diff --git a/Source/Engine/Renderer/ReflectionsPass.cpp b/Source/Engine/Renderer/ReflectionsPass.cpp index 898f487c6..508d361ae 100644 --- a/Source/Engine/Renderer/ReflectionsPass.cpp +++ b/Source/Engine/Renderer/ReflectionsPass.cpp @@ -215,6 +215,11 @@ bool ReflectionsPass::setupResources() { psDesc.BlendMode = BlendingMode::Add; psDesc.BlendMode.RenderTargetWriteMask = BlendingMode::ColorWrite::RGB; + if (_depthBounds) + { + psDesc.DepthEnable = psDesc.DepthBoundsEnable = true; + psDesc.DepthWriteEnable = false; + } psDesc.PS = shader->GetPS("PS_CombinePass"); if (_psCombinePass->Init(psDesc)) return true; @@ -374,7 +379,7 @@ void ReflectionsPass::Render(RenderContext& renderContext, GPUTextureView* light context->BindSR(0, renderContext.Buffers->GBuffer0); context->BindSR(1, renderContext.Buffers->GBuffer1); context->BindSR(2, renderContext.Buffers->GBuffer2); - context->BindSR(3, renderContext.Buffers->DepthBuffer); + context->BindSR(3, depthBufferSRV); context->SetViewportAndScissors(renderContext.Task->GetViewport()); } @@ -406,7 +411,13 @@ void ReflectionsPass::Render(RenderContext& renderContext, GPUTextureView* light else { // Combine reflections and light buffer (additive mode) - context->SetRenderTarget(lightBuffer); + if (_depthBounds) + { + context->SetRenderTarget(depthBufferRTV, lightBuffer); + context->SetDepthBounds(0, RenderTools::DepthBoundMaxBackground); + } + else + context->SetRenderTarget(lightBuffer); context->BindCB(0, cb); if (probesCount == 0 || !renderProbes) context->UpdateCB(cb, &data); @@ -415,6 +426,8 @@ void ReflectionsPass::Render(RenderContext& renderContext, GPUTextureView* light context->BindSR(7, ssrBuffer); context->SetState(_psCombinePass); context->DrawFullscreenTriangle(); + if (_depthBounds) + context->SetDepthBounds(0, 1); } RenderTargetPool::Release(ssrBuffer); diff --git a/Source/Engine/Renderer/ScreenSpaceReflectionsPass.cpp b/Source/Engine/Renderer/ScreenSpaceReflectionsPass.cpp index bc3ea3783..52b1412fe 100644 --- a/Source/Engine/Renderer/ScreenSpaceReflectionsPass.cpp +++ b/Source/Engine/Renderer/ScreenSpaceReflectionsPass.cpp @@ -62,9 +62,7 @@ bool ScreenSpaceReflectionsPass::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/SSR")); _preIntegratedGF = Content::LoadAsyncInternal(PRE_INTEGRATED_GF_ASSET_NAME); if (_shader == nullptr || _preIntegratedGF == nullptr) - { return true; - } #if COMPILE_WITH_DEV_ENV _shader.Get()->OnReloading.Bind(this); #endif @@ -248,13 +246,7 @@ GPUTexture* ScreenSpaceReflectionsPass::Render(RenderContext& renderContext, GPU } // Check if resize depth - GPUTexture* originalDepthBuffer = buffers->DepthBuffer; - GPUTexture* smallerDepthBuffer = originalDepthBuffer; - if (settings.DepthResolution != ResolutionMode::Full) - { - // Smaller depth buffer improves ray tracing performance - smallerDepthBuffer = buffers->RequestHalfResDepth(context); - } + GPUTexture* depthBufferTrace = settings.DepthResolution == ResolutionMode::Half ? buffers->RequestHalfResDepth(context) : buffers->DepthBuffer; // Prepare constants context->UpdateCB(cb, &data); @@ -264,7 +256,7 @@ GPUTexture* ScreenSpaceReflectionsPass::Render(RenderContext& renderContext, GPU context->BindSR(0, buffers->GBuffer0); context->BindSR(1, buffers->GBuffer1); context->BindSR(2, buffers->GBuffer2); - context->BindSR(3, smallerDepthBuffer); + context->BindSR(3, depthBufferTrace); // Combine pass context->BindSR(TEXTURE0, lightBuffer);