From ac344e26bb0d86b6d315f2a53e0f23e6e80e32e5 Mon Sep 17 00:00:00 2001 From: Karol Suprynowicz Date: Wed, 12 Mar 2025 00:51:56 +0100 Subject: [PATCH 1/2] Initial fix for blurry/noisy transparencies on TAA --- .../render-utils/src/DeferredBufferWrite.slh | 16 ++++++++-------- .../render-utils/src/RenderDeferredTask.cpp | 5 ++++- libraries/render-utils/src/RenderDeferredTask.h | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index ff965d9eb9..cfb4730598 100644 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -73,10 +73,10 @@ void packDeferredFragmentTranslucent(vec4 prevPositionCS, vec3 normal, float alp discard; } _albedoMetallic = vec4(albedo.rgb, alpha); - _normalRoughness = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); - _scatteringEmissiveOcclusion = vec4(vec3(0.0), 1.0); - _velocity = vec4(packVelocity(prevPositionCS), 0.0, 0.0); - _lighting = vec4(0.0); + //_normalRoughness = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); + //_scatteringEmissiveOcclusion = vec4(vec3(0.0), 1.0); + //_velocity = vec4(packVelocity(prevPositionCS), 0.0, 0.0); + //_lighting = vec4(0.0); } void packDeferredFragmentTranslucentUnlit(vec4 prevPositionCS, vec3 normal, float alpha, vec3 color) { @@ -84,10 +84,10 @@ void packDeferredFragmentTranslucentUnlit(vec4 prevPositionCS, vec3 normal, floa discard; } _albedoMetallic = vec4(color, alpha); - _normalRoughness = vec4(packNormal(normal), 1.0); - _scatteringEmissiveOcclusion = vec4(vec3(0.0), 1.0); - _velocity = vec4(packVelocity(prevPositionCS), 0.0, 0.0); - _lighting = vec4(color, 1.0); + //_normalRoughness = vec4(packNormal(normal), 1.0); + //_scatteringEmissiveOcclusion = vec4(vec3(0.0), 1.0); + //_velocity = vec4(packVelocity(prevPositionCS), 0.0, 0.0); + //_lighting = vec4(color, 1.0); } <@endif@> diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 296fc22c40..cdcf2265ae 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -216,7 +216,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren task.addJob("DrawHazeDeferred", drawHazeInputs, depth > 0); // Render transparent objects forward in LightingBuffer - const auto transparentsInputs = RenderTransparentDeferred::Inputs(transparents, hazeFrame, lightFrame, lightingModel, lightClusters, shadowFrame, deferredFrameTransform).asVarying(); + const auto transparentsInputs = RenderTransparentDeferred::Inputs(transparents, hazeFrame, lightFrame, lightingModel, lightClusters, shadowFrame, deferredFrameTransform, deferredFramebuffer).asVarying(); task.addJob("DrawTransparentDeferred", transparentsInputs, shapePlumberDeferred, mainViewTransformSlot); // Highlight @@ -465,12 +465,15 @@ void RenderTransparentDeferred::run(const RenderContextPointer& renderContext, c const auto& lightClusters = inputs.get4(); // Not needed yet: const auto& shadowFrame = inputs.get5(); const auto& deferredFrameTransform = inputs.get6(); + auto &deferredFramebuffer = inputs.get7(); auto deferredLightingEffect = DependencyManager::get(); RenderArgs* args = renderContext->args; gpu::doInBatch("RenderTransparentDeferred::run", args->_context, [&](gpu::Batch& batch) { args->_batch = &batch; + + batch.setFramebuffer(deferredFramebuffer->getLightingFramebuffer()); // Setup camera, projection and viewport for all items batch.setViewportTransform(args->_viewport); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 5ecca97306..163a0480ce 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -44,7 +44,7 @@ protected: class RenderTransparentDeferred { public: - using Inputs = render::VaryingSet7; + using Inputs = render::VaryingSet8; using Config = RenderTransparentDeferredConfig; using JobModel = render::Job::ModelI; From 7c59a6360a44a71e40df439f62d4d868e1880d14 Mon Sep 17 00:00:00 2001 From: Karol Suprynowicz Date: Fri, 14 Mar 2025 18:55:28 +0100 Subject: [PATCH 2/2] Added a comment about transparencies --- libraries/render-utils/src/DeferredBufferWrite.slh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index cfb4730598..ca781603b4 100644 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -72,22 +72,18 @@ void packDeferredFragmentTranslucent(vec4 prevPositionCS, vec3 normal, float alp if (alpha <= 0.0) { discard; } + // There's only one attachment here, and _albedoMetallic is actually _lighting, + // since transparencies are drawn using forward rendering, not deferred. _albedoMetallic = vec4(albedo.rgb, alpha); - //_normalRoughness = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); - //_scatteringEmissiveOcclusion = vec4(vec3(0.0), 1.0); - //_velocity = vec4(packVelocity(prevPositionCS), 0.0, 0.0); - //_lighting = vec4(0.0); } void packDeferredFragmentTranslucentUnlit(vec4 prevPositionCS, vec3 normal, float alpha, vec3 color) { if (alpha <= 0.0) { discard; } + // There's only one attachment here, and _albedoMetallic is actually _lighting, + // since transparencies are drawn using forward rendering, not deferred. _albedoMetallic = vec4(color, alpha); - //_normalRoughness = vec4(packNormal(normal), 1.0); - //_scatteringEmissiveOcclusion = vec4(vec3(0.0), 1.0); - //_velocity = vec4(packVelocity(prevPositionCS), 0.0, 0.0); - //_lighting = vec4(color, 1.0); } <@endif@>