Showing the changes to libraries/render-utils/src/SurfaceGeometryPass.cpp (1 of 7 files). Show all
Unified · Split
| @@ -282,6 +282,10 @@ void SurfaceGeometryFramebuffer::updateLinearDepth(const gpu::TexturePointer& li · 281 unmodified lines | |||
| 282 | void SurfaceGeometryFramebuffer::clear() { | 282 | void SurfaceGeometryFramebuffer::clear() { |
| 283 | _curvatureFramebuffer.reset(); | 283 | _curvatureFramebuffer.reset(); |
| 284 | _curvatureTexture.reset(); | 284 | _curvatureTexture.reset(); |
| 285 | _lowCurvatureFramebuffer.reset(); | ||
| 286 | _lowCurvatureTexture.reset(); | ||
| 287 | _blurringFramebuffer.reset(); | ||
| 288 | _blurringTexture.reset(); | ||
| 285 | } | 289 | } |
| 286 | 290 | ||
| 287 | gpu::TexturePointer SurfaceGeometryFramebuffer::getLinearDepthTexture() { | 291 | gpu::TexturePointer SurfaceGeometryFramebuffer::getLinearDepthTexture() { |
| @@ -293,9 +297,17 @@ void SurfaceGeometryFramebuffer::allocate() { · 5 unmodified lines | |||
| 293 | auto width = _frameSize.x; | 297 | auto width = _frameSize.x; |
| 294 | auto height = _frameSize.y; | 298 | auto height = _frameSize.y; |
| 295 | 299 | ||
| 296 | _curvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width >> getResolutionLevel(), height >> getResolutionLevel(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT))); | 300 | _curvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT))); |
| 297 | _curvatureFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); | 301 | _curvatureFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); |
| 298 | _curvatureFramebuffer->setRenderBuffer(0, _curvatureTexture); | 302 | _curvatureFramebuffer->setRenderBuffer(0, _curvatureTexture); |
| 303 | |||
| 304 | _lowCurvatureTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT))); | ||
| 305 | _lowCurvatureFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); | ||
| 306 | _lowCurvatureFramebuffer->setRenderBuffer(0, _lowCurvatureTexture); | ||
| 307 | |||
| 308 | _blurringTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT))); | ||
| 309 | _blurringFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); | ||
| 310 | _blurringFramebuffer->setRenderBuffer(0, _blurringTexture); | ||
| 299 | } | 311 | } |
| 300 | 312 | ||
| 301 | gpu::FramebufferPointer SurfaceGeometryFramebuffer::getCurvatureFramebuffer() { | 313 | gpu::FramebufferPointer SurfaceGeometryFramebuffer::getCurvatureFramebuffer() { |
| @@ -312,6 +324,34 @@ gpu::TexturePointer SurfaceGeometryFramebuffer::getCurvatureTexture() { · 10 unmodified lines | |||
| 312 | return _curvatureTexture; | 324 | return _curvatureTexture; |
| 313 | } | 325 | } |
| 314 | 326 | ||
| 327 | gpu::FramebufferPointer SurfaceGeometryFramebuffer::getLowCurvatureFramebuffer() { | ||
| 328 | if (!_lowCurvatureFramebuffer) { | ||
| 329 | allocate(); | ||
| 330 | } | ||
| 331 | return _lowCurvatureFramebuffer; | ||
| 332 | } | ||
| 333 | |||
| 334 | gpu::TexturePointer SurfaceGeometryFramebuffer::getLowCurvatureTexture() { | ||
| 335 | if (!_lowCurvatureTexture) { | ||
| 336 | allocate(); | ||
| 337 | } | ||
| 338 | return _lowCurvatureTexture; | ||
| 339 | } | ||
| 340 | |||
| 341 | gpu::FramebufferPointer SurfaceGeometryFramebuffer::getBlurringFramebuffer() { | ||
| 342 | if (!_blurringFramebuffer) { | ||
| 343 | allocate(); | ||
| 344 | } | ||
| 345 | return _blurringFramebuffer; | ||
| 346 | } | ||
| 347 | |||
| 348 | gpu::TexturePointer SurfaceGeometryFramebuffer::getBlurringTexture() { | ||
| 349 | if (!_blurringTexture) { | ||
| 350 | allocate(); | ||
| 351 | } | ||
| 352 | return _blurringTexture; | ||
| 353 | } | ||
| 354 | |||
| 315 | void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) { | 355 | void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) { |
| 316 | if (resolutionLevel != getResolutionLevel()) { | 356 | if (resolutionLevel != getResolutionLevel()) { |
| 317 | clear(); | 357 | clear(); |
| @@ -320,8 +360,7 @@ void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) { · 2 unmodified lines | |||
| 320 | } | 360 | } |
| 321 | 361 | ||
| 322 | SurfaceGeometryPass::SurfaceGeometryPass() : | 362 | SurfaceGeometryPass::SurfaceGeometryPass() : |
| 323 | _firstBlurPass(false), | 363 | _diffusePass(false) |
| 324 | _secondBlurPass(true, _firstBlurPass.getParameters()) | ||
| 325 | { | 364 | { |
| 326 | Parameters parameters; | 365 | Parameters parameters; |
| 327 | _parametersBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Parameters), (const gpu::Byte*) ¶meters)); | 366 | _parametersBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Parameters), (const gpu::Byte*) ¶meters)); |
| @@ -345,6 +384,10 @@ void SurfaceGeometryPass::configure(const Config& config) { · 17 unmodified lines | |||
| 345 | _surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>(); | 384 | _surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>(); |
| 346 | } | 385 | } |
| 347 | _surfaceGeometryFramebuffer->setResolutionLevel(config.resolutionLevel); | 386 | _surfaceGeometryFramebuffer->setResolutionLevel(config.resolutionLevel); |
| 387 | |||
| 388 | _diffusePass.getParameters()->setFilterRadiusScale(config.diffuseFilterScale); | ||
| 389 | _diffusePass.getParameters()->setDepthThreshold(config.diffuseDepthThreshold); | ||
| 390 | |||
| 348 | } | 391 | } |
| 349 | 392 | ||
| 350 | 393 | ||
| @@ -358,33 +401,52 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c · 7 unmodified lines | |||
| 358 | const auto deferredFramebuffer = inputs.get1(); | 401 | const auto deferredFramebuffer = inputs.get1(); |
| 359 | const auto linearDepthFramebuffer = inputs.get2(); | 402 | const auto linearDepthFramebuffer = inputs.get2(); |
| 360 | 403 | ||
| 361 | auto linearDepthTexture = linearDepthFramebuffer->getHalfLinearDepthTexture(); | 404 | |
| 405 | auto linearDepthTexture = linearDepthFramebuffer->getLinearDepthTexture(); | ||
| 406 | auto normalTexture = deferredFramebuffer->getDeferredNormalTexture(); | ||
| 407 | auto sourceViewport = args->_viewport; | ||
| 408 | auto curvatureViewport = sourceViewport; | ||
| 409 | |||
| 410 | if (_surfaceGeometryFramebuffer->getResolutionLevel() > 0) { | ||
| 411 | linearDepthTexture = linearDepthFramebuffer->getHalfLinearDepthTexture(); | ||
| 412 | normalTexture = linearDepthFramebuffer->getHalfNormalTexture(); | ||
| 413 | curvatureViewport = curvatureViewport >> _surfaceGeometryFramebuffer->getResolutionLevel(); | ||
| 414 | } | ||
| 362 | 415 | ||
| 363 | if (!_surfaceGeometryFramebuffer) { | 416 | if (!_surfaceGeometryFramebuffer) { |
| 364 | _surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>(); | 417 | _surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>(); |
| 365 | } | 418 | } |
| 366 | _surfaceGeometryFramebuffer->updateLinearDepth(linearDepthTexture); | 419 | _surfaceGeometryFramebuffer->updateLinearDepth(linearDepthTexture); |
| 367 | 420 | ||
| 368 | // auto normalTexture = deferredFramebuffer->getDeferredNormalTexture(); | ||
| 369 | auto normalTexture = linearDepthFramebuffer->getHalfNormalTexture(); | ||
| 370 | |||
| 371 | auto curvatureFramebuffer = _surfaceGeometryFramebuffer->getCurvatureFramebuffer(); | 421 | auto curvatureFramebuffer = _surfaceGeometryFramebuffer->getCurvatureFramebuffer(); |
| 422 | auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture(); | ||
| 372 | #ifdef USE_STENCIL_TEST | 423 | #ifdef USE_STENCIL_TEST |
| 373 | if (curvatureFBO->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) { | 424 | if (curvatureFramebuffer->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) { |
| 374 | curvatureFBO->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat()); | 425 | curvatureFramebuffer->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat()); |
| 375 | } | 426 | } |
| 376 | #endif | 427 | #endif |
| 377 | auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture(); | 428 | |
| 429 | auto lowCurvatureFramebuffer = _surfaceGeometryFramebuffer->getLowCurvatureFramebuffer(); | ||
| 430 | auto lowCurvatureTexture = _surfaceGeometryFramebuffer->getLowCurvatureTexture(); | ||
| 431 | |||
| 432 | auto blurringFramebuffer = _surfaceGeometryFramebuffer->getBlurringFramebuffer(); | ||
| 433 | auto blurringTexture = _surfaceGeometryFramebuffer->getBlurringTexture(); | ||
| 378 | 434 | ||
| 379 | outputs.edit0() = _surfaceGeometryFramebuffer; | 435 | outputs.edit0() = _surfaceGeometryFramebuffer; |
| 380 | outputs.edit1() = curvatureFramebuffer; | 436 | outputs.edit1() = curvatureFramebuffer; |
| 437 | outputs.edit2() = curvatureFramebuffer; | ||
| 438 | outputs.edit3() = lowCurvatureFramebuffer; | ||
| 381 | 439 | ||
| 382 | auto curvaturePipeline = getCurvaturePipeline(); | 440 | auto curvaturePipeline = getCurvaturePipeline(); |
| 441 | auto diffuseVPipeline = _diffusePass.getBlurVPipeline(); | ||
| 442 | auto diffuseHPipeline = _diffusePass.getBlurHPipeline(); | ||
| 383 | 443 | ||
| 384 | auto depthViewport = args->_viewport; | 444 | glm::ivec2 textureSize(curvatureTexture->getDimensions()); |
| 385 | auto curvatureViewport = depthViewport >> 1; | 445 | _diffusePass.getParameters()->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, curvatureViewport)); |
| 386 | // >> _surfaceGeometryFramebuffer->getResolutionLevel(); | 446 | _diffusePass.getParameters()->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]); |
| 447 | _diffusePass.getParameters()->setLinearDepthPosFar(args->getViewFrustum().getFarClip()); | ||
| 387 | 448 | ||
| 449 | |||
| 388 | gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { | 450 | gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { |
| 389 | _gpuTimer.begin(batch); | 451 | _gpuTimer.begin(batch); |
| 390 | batch.enableStereo(false); | 452 | batch.enableStereo(false); |
| @@ -393,43 +455,58 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c · 2 unmodified lines | |||
| 393 | batch.setViewTransform(Transform()); | 455 | batch.setViewTransform(Transform()); |
| 394 | 456 | ||
| 395 | batch.setViewportTransform(curvatureViewport); | 457 | batch.setViewportTransform(curvatureViewport); |
| 396 | batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(_surfaceGeometryFramebuffer->getCurvatureFrameSize(), curvatureViewport)); | 458 | batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(_surfaceGeometryFramebuffer->getSourceFrameSize(), curvatureViewport)); |
| 397 | 459 | ||
| 460 | // Curvature pass | ||
| 398 | batch.setUniformBuffer(SurfaceGeometryPass_FrameTransformSlot, frameTransform->getFrameTransformBuffer()); | 461 | batch.setUniformBuffer(SurfaceGeometryPass_FrameTransformSlot, frameTransform->getFrameTransformBuffer()); |
| 399 | batch.setUniformBuffer(SurfaceGeometryPass_ParamsSlot, _parametersBuffer); | 462 | batch.setUniformBuffer(SurfaceGeometryPass_ParamsSlot, _parametersBuffer); |
| 400 | |||
| 401 | // Curvature pass | ||
| 402 | batch.setFramebuffer(curvatureFramebuffer); | 463 | batch.setFramebuffer(curvatureFramebuffer); |
| 403 | 464 | // We can avoid the clear by drawing the same clear vallue from the makeCurvature shader. same performances or no worse | |
| 404 | // We can avoid the clear by drawing the same clear vallue from the makeCurvature shader. same performances or no worse | ||
| 405 | |||
| 406 | #ifdef USE_STENCIL_TEST | 465 | #ifdef USE_STENCIL_TEST |
| 407 | // Except if stenciling out | 466 | // Except if stenciling out |
| 408 | batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0)); | 467 | batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0)); |
| 409 | #endif | 468 | #endif |
| 410 | |||
| 411 | batch.setPipeline(curvaturePipeline); | 469 | batch.setPipeline(curvaturePipeline); |
| 412 | batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, linearDepthTexture); | 470 | batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, linearDepthTexture); |
| 413 | batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, normalTexture); | 471 | batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, normalTexture); |
| 414 | batch.draw(gpu::TRIANGLE_STRIP, 4); | 472 | batch.draw(gpu::TRIANGLE_STRIP, 4); |
| 415 | 473 | ||
| 416 | batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, nullptr); | 474 | // Diffusion pass |
| 417 | batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, nullptr); | 475 | const int BlurTask_ParamsSlot = 0; |
| 476 | const int BlurTask_SourceSlot = 0; | ||
| 477 | const int BlurTask_DepthSlot = 1; | ||
| 478 | batch.setUniformBuffer(BlurTask_ParamsSlot, _diffusePass.getParameters()->_parametersBuffer); | ||
| 418 | 479 | ||
| 419 | _gpuTimer.end(batch); | 480 | batch.setResourceTexture(BlurTask_DepthSlot, linearDepthTexture); |
| 420 | }); | 481 | |
| 482 | batch.setFramebuffer(blurringFramebuffer); | ||
| 483 | batch.setPipeline(diffuseVPipeline); | ||
| 484 | batch.setResourceTexture(BlurTask_SourceSlot, curvatureTexture); | ||
| 485 | batch.draw(gpu::TRIANGLE_STRIP, 4); | ||
| 421 | 486 | ||
| 422 | const auto diffuseCurvaturePassInputs = render::BlurGaussianDepthAware::Inputs(curvatureFramebuffer, linearDepthTexture); | 487 | batch.setFramebuffer(curvatureFramebuffer); |
| 423 | gpu::FramebufferPointer midBlurredFramebuffer; | 488 | batch.setPipeline(diffuseHPipeline); |
| 424 | _firstBlurPass.run(sceneContext, renderContext, diffuseCurvaturePassInputs, midBlurredFramebuffer); | 489 | batch.setResourceTexture(BlurTask_SourceSlot, blurringTexture); |
| 490 | batch.draw(gpu::TRIANGLE_STRIP, 4); | ||
| 425 | 491 | ||
| 426 | gpu::FramebufferPointer lowBlurredFramebuffer; | 492 | batch.setFramebuffer(blurringFramebuffer); |
| 427 | _secondBlurPass.run(sceneContext, renderContext, diffuseCurvaturePassInputs, lowBlurredFramebuffer); | 493 | batch.setPipeline(diffuseVPipeline); |
| 428 | 494 | batch.setResourceTexture(BlurTask_SourceSlot, curvatureTexture); | |
| 429 | 495 | batch.draw(gpu::TRIANGLE_STRIP, 4); | |
| 430 | outputs.edit2() = midBlurredFramebuffer; | ||
| 431 | outputs.edit3() = lowBlurredFramebuffer; | ||
| 432 | 496 | ||
| 497 | batch.setFramebuffer(lowCurvatureFramebuffer); | ||
| 498 | batch.setPipeline(diffuseHPipeline); | ||
| 499 | batch.setResourceTexture(BlurTask_SourceSlot, blurringTexture); | ||
| 500 | batch.draw(gpu::TRIANGLE_STRIP, 4); | ||
| 501 | |||
| 502 | batch.setResourceTexture(BlurTask_SourceSlot, nullptr); | ||
| 503 | batch.setResourceTexture(BlurTask_DepthSlot, nullptr); | ||
| 504 | batch.setUniformBuffer(BlurTask_ParamsSlot, nullptr); | ||
| 505 | |||
| 506 | _gpuTimer.end(batch); | ||
| 507 | }); | ||
| 508 | |||
| 509 | |||
| 433 | auto config = std::static_pointer_cast<Config>(renderContext->jobConfig); | 510 | auto config = std::static_pointer_cast<Config>(renderContext->jobConfig); |
| 434 | config->gpuTime = _gpuTimer.getAverage(); | 511 | config->gpuTime = _gpuTimer.getAverage(); |
| 435 | } | 512 | } |