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 | 282 | void SurfaceGeometryFramebuffer::clear() { |
| 283 | 283 | _curvatureFramebuffer.reset(); |
| 284 | 284 | _curvatureTexture.reset(); |
| 285 | + _lowCurvatureFramebuffer.reset(); | |
| 286 | + _lowCurvatureTexture.reset(); | |
| 287 | + _blurringFramebuffer.reset(); | |
| 288 | + _blurringTexture.reset(); | |
| 285 | 289 | } |
| 286 | 290 | |
| 287 | 291 | gpu::TexturePointer SurfaceGeometryFramebuffer::getLinearDepthTexture() { |
| @@ -293,9 +297,17 @@ void SurfaceGeometryFramebuffer::allocate() { · 5 unmodified lines | ||
| 293 | 297 | auto width = _frameSize.x; |
| 294 | 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 | 301 | _curvatureFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); |
| 298 | 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 | 313 | gpu::FramebufferPointer SurfaceGeometryFramebuffer::getCurvatureFramebuffer() { |
| @@ -312,6 +324,34 @@ gpu::TexturePointer SurfaceGeometryFramebuffer::getCurvatureTexture() { · 10 unmodified lines | ||
| 312 | 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 | 355 | void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) { |
| 316 | 356 | if (resolutionLevel != getResolutionLevel()) { |
| 317 | 357 | clear(); |
| @@ -320,8 +360,7 @@ void SurfaceGeometryFramebuffer::setResolutionLevel(int resolutionLevel) { · 2 unmodified lines | ||
| 320 | 360 | } |
| 321 | 361 | |
| 322 | 362 | SurfaceGeometryPass::SurfaceGeometryPass() : |
| 323 | − _firstBlurPass(false), | |
| 324 | − _secondBlurPass(true, _firstBlurPass.getParameters()) | |
| 363 | + _diffusePass(false) | |
| 325 | 364 | { |
| 326 | 365 | Parameters parameters; |
| 327 | 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 | 384 | _surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>(); |
| 346 | 385 | } |
| 347 | 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 | 401 | const auto deferredFramebuffer = inputs.get1(); |
| 359 | 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 | 416 | if (!_surfaceGeometryFramebuffer) { |
| 364 | 417 | _surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>(); |
| 365 | 418 | } |
| 366 | 419 | _surfaceGeometryFramebuffer->updateLinearDepth(linearDepthTexture); |
| 367 | 420 | |
| 368 | − // auto normalTexture = deferredFramebuffer->getDeferredNormalTexture(); | |
| 369 | − auto normalTexture = linearDepthFramebuffer->getHalfNormalTexture(); | |
| 370 | − | |
| 371 | 421 | auto curvatureFramebuffer = _surfaceGeometryFramebuffer->getCurvatureFramebuffer(); |
| 422 | + auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture(); | |
| 372 | 423 | #ifdef USE_STENCIL_TEST |
| 373 | − if (curvatureFBO->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) { | |
| 374 | − curvatureFBO->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat()); | |
| 424 | + if (curvatureFramebuffer->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) { | |
| 425 | + curvatureFramebuffer->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat()); | |
| 375 | 426 | } |
| 376 | 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 | 435 | outputs.edit0() = _surfaceGeometryFramebuffer; |
| 380 | 436 | outputs.edit1() = curvatureFramebuffer; |
| 437 | + outputs.edit2() = curvatureFramebuffer; | |
| 438 | + outputs.edit3() = lowCurvatureFramebuffer; | |
| 381 | 439 | |
| 382 | 440 | auto curvaturePipeline = getCurvaturePipeline(); |
| 441 | + auto diffuseVPipeline = _diffusePass.getBlurVPipeline(); | |
| 442 | + auto diffuseHPipeline = _diffusePass.getBlurHPipeline(); | |
| 383 | 443 | |
| 384 | − auto depthViewport = args->_viewport; | |
| 385 | − auto curvatureViewport = depthViewport >> 1; | |
| 386 | − // >> _surfaceGeometryFramebuffer->getResolutionLevel(); | |
| 444 | + glm::ivec2 textureSize(curvatureTexture->getDimensions()); | |
| 445 | + _diffusePass.getParameters()->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, curvatureViewport)); | |
| 446 | + _diffusePass.getParameters()->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]); | |
| 447 | + _diffusePass.getParameters()->setLinearDepthPosFar(args->getViewFrustum().getFarClip()); | |
| 387 | 448 | |
| 449 | + | |
| 388 | 450 | gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { |
| 389 | 451 | _gpuTimer.begin(batch); |
| 390 | 452 | batch.enableStereo(false); |
| @@ -393,43 +455,58 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c · 2 unmodified lines | ||
| 393 | 455 | batch.setViewTransform(Transform()); |
| 394 | 456 | |
| 395 | 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 | 461 | batch.setUniformBuffer(SurfaceGeometryPass_FrameTransformSlot, frameTransform->getFrameTransformBuffer()); |
| 399 | 462 | batch.setUniformBuffer(SurfaceGeometryPass_ParamsSlot, _parametersBuffer); |
| 400 | − | |
| 401 | − // Curvature pass | |
| 402 | 463 | batch.setFramebuffer(curvatureFramebuffer); |
| 403 | − | |
| 404 | − // We can avoid the clear by drawing the same clear vallue from the makeCurvature shader. same performances or no worse | |
| 405 | − | |
| 464 | + // We can avoid the clear by drawing the same clear vallue from the makeCurvature shader. same performances or no worse | |
| 406 | 465 | #ifdef USE_STENCIL_TEST |
| 407 | 466 | // Except if stenciling out |
| 408 | 467 | batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0)); |
| 409 | 468 | #endif |
| 410 | − | |
| 411 | 469 | batch.setPipeline(curvaturePipeline); |
| 412 | 470 | batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, linearDepthTexture); |
| 413 | 471 | batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, normalTexture); |
| 414 | 472 | batch.draw(gpu::TRIANGLE_STRIP, 4); |
| 415 | 473 | |
| 416 | − batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, nullptr); | |
| 417 | − batch.setResourceTexture(SurfaceGeometryPass_NormalMapSlot, nullptr); | |
| 474 | + // Diffusion pass | |
| 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); | |
| 420 | − }); | |
| 480 | + batch.setResourceTexture(BlurTask_DepthSlot, linearDepthTexture); | |
| 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); | |
| 423 | − gpu::FramebufferPointer midBlurredFramebuffer; | |
| 424 | − _firstBlurPass.run(sceneContext, renderContext, diffuseCurvaturePassInputs, midBlurredFramebuffer); | |
| 487 | + batch.setFramebuffer(curvatureFramebuffer); | |
| 488 | + batch.setPipeline(diffuseHPipeline); | |
| 489 | + batch.setResourceTexture(BlurTask_SourceSlot, blurringTexture); | |
| 490 | + batch.draw(gpu::TRIANGLE_STRIP, 4); | |
| 425 | 491 | |
| 426 | − gpu::FramebufferPointer lowBlurredFramebuffer; | |
| 427 | − _secondBlurPass.run(sceneContext, renderContext, diffuseCurvaturePassInputs, lowBlurredFramebuffer); | |
| 428 | − | |
| 429 | − | |
| 430 | − outputs.edit2() = midBlurredFramebuffer; | |
| 431 | − outputs.edit3() = lowBlurredFramebuffer; | |
| 492 | + batch.setFramebuffer(blurringFramebuffer); | |
| 493 | + batch.setPipeline(diffuseVPipeline); | |
| 494 | + batch.setResourceTexture(BlurTask_SourceSlot, curvatureTexture); | |
| 495 | + batch.draw(gpu::TRIANGLE_STRIP, 4); | |
| 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 | 510 | auto config = std::static_pointer_cast<Config>(renderContext->jobConfig); |
| 434 | 511 | config->gpuTime = _gpuTimer.getAverage(); |
| 435 | 512 | } |