From 2b4dc97a97a2b202596033f2a85ad3f27a7751eb Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 13 Jan 2026 13:12:33 +0100 Subject: [PATCH] Fix yellowish artifacts due to quantization error in TAA and composite image output #3318 #3254 --- Content/Shaders/PostProcessing.flax | 4 ++-- Content/Shaders/TAA.flax | 4 ++-- Source/Engine/Renderer/AntiAliasing/TAA.cpp | 5 ++++- Source/Engine/Renderer/PostProcessingPass.cpp | 6 +++++- Source/Shaders/PostProcessing.shader | 8 ++++++++ Source/Shaders/TAA.shader | 8 ++++++++ 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Content/Shaders/PostProcessing.flax b/Content/Shaders/PostProcessing.flax index f58498b34..bec24f8c0 100644 --- a/Content/Shaders/PostProcessing.flax +++ b/Content/Shaders/PostProcessing.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a430a05bdfa8476cc742748d5406e9c8c80a7e1ed00f392947b8c88cdf7cd176 -size 23062 +oid sha256:17fc5977b0e82aea17310dad1a93745fd923ebc920b74ee29a55afb909275e56 +size 23340 diff --git a/Content/Shaders/TAA.flax b/Content/Shaders/TAA.flax index fb5bb686c..01e4e04bb 100644 --- a/Content/Shaders/TAA.flax +++ b/Content/Shaders/TAA.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9ba59e7b56c9cda8b9d19369b998e873f08c634fc87021dc8bbd836f44a5bdc5 -size 4275 +oid sha256:b0120ff9db1973674dd8b99af7e75ce66069bfa9d7f32916e897aee062a99dd2 +size 4548 diff --git a/Source/Engine/Renderer/AntiAliasing/TAA.cpp b/Source/Engine/Renderer/AntiAliasing/TAA.cpp index b772eb45e..3100fa0c8 100644 --- a/Source/Engine/Renderer/AntiAliasing/TAA.cpp +++ b/Source/Engine/Renderer/AntiAliasing/TAA.cpp @@ -6,10 +6,10 @@ #include "Engine/Graphics/GPUContext.h" #include "Engine/Graphics/RenderTargetPool.h" #include "Engine/Graphics/RenderBuffers.h" -#include "Engine/Graphics/RenderTask.h" #include "Engine/Renderer/RenderList.h" #include "Engine/Renderer/GBufferPass.h" #include "Engine/Engine/Engine.h" +#include "Engine/Graphics/RenderTools.h" GPU_CB_STRUCT(Data { Float2 ScreenSizeInv; @@ -18,6 +18,8 @@ GPU_CB_STRUCT(Data { float StationaryBlending; float MotionBlending; float Dummy0; + Float3 QuantizationError; + float Dummy1; ShaderGBufferData GBuffer; }); @@ -122,6 +124,7 @@ void TAA::Render(const RenderContext& renderContext, GPUTexture* input, GPUTextu data.Sharpness = settings.TAA_Sharpness; data.StationaryBlending = settings.TAA_StationaryBlending * blendStrength; data.MotionBlending = settings.TAA_MotionBlending * blendStrength; + data.QuantizationError = RenderTools::GetColorQuantizationError(tempDesc.Format); GBufferPass::SetInputs(renderContext.View, data.GBuffer); const auto cb = _shader->GetShader()->GetCB(0); context->UpdateCB(cb, &data); diff --git a/Source/Engine/Renderer/PostProcessingPass.cpp b/Source/Engine/Renderer/PostProcessingPass.cpp index 529c66f2d..bde2e520f 100644 --- a/Source/Engine/Renderer/PostProcessingPass.cpp +++ b/Source/Engine/Renderer/PostProcessingPass.cpp @@ -6,7 +6,7 @@ #include "Engine/Content/Content.h" #include "Engine/Graphics/Graphics.h" #include "Engine/Graphics/GPUContext.h" -#include "Engine/Graphics/RenderTask.h" +#include "Engine/Graphics/RenderTools.h" #include "Engine/Graphics/RenderTargetPool.h" #include "Engine/Engine/Time.h" @@ -58,6 +58,9 @@ GPU_CB_STRUCT(Data{ Color ScreenFadeColor; + Float3 QuantizationError; + float Dummy2; + Matrix LensFlareStarMat; }); @@ -359,6 +362,7 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input, data.LensFlareIntensity = 0; data.LensDirtIntensity = 0; } + data.QuantizationError = RenderTools::GetColorQuantizationError(output->Format()); data.PostExposure = Math::Exp2(settings.EyeAdaptation.PostExposure); data.InputSize = Float2(static_cast(w1), static_cast(h1)); data.InvInputSize = Float2(1.0f / static_cast(w1), 1.0f / static_cast(h1)); diff --git a/Source/Shaders/PostProcessing.shader b/Source/Shaders/PostProcessing.shader index b8beedc18..e3e1509a7 100644 --- a/Source/Shaders/PostProcessing.shader +++ b/Source/Shaders/PostProcessing.shader @@ -22,6 +22,7 @@ #include "./Flax/Common.hlsl" #include "./Flax/Random.hlsl" +#include "./Flax/Noise.hlsl" #include "./Flax/GammaCorrectionCommon.hlsl" #define GB_RADIUS 6 @@ -80,6 +81,9 @@ float LensDirtIntensity; float4 ScreenFadeColor; +float3 QuantizationError; +float Dummy2; + float4x4 LensFlareStarMat; META_CB_END @@ -738,6 +742,10 @@ float4 PS_Composite(Quad_VS2PS input) : SV_Target // Saturate color since it will be rendered to the screen color.rgb = saturate(color.rgb); + // Apply quantization error to reduce yellowish artifacts due to R11G11B10 format + float noise = rand2dTo1d(input.TexCoord); + color.rgb = QuantizeColor(color.rgb, noise, QuantizationError); + // Return final pixel color (preserve input alpha) return color; } diff --git a/Source/Shaders/TAA.shader b/Source/Shaders/TAA.shader index 0263e94f2..ca100b92c 100644 --- a/Source/Shaders/TAA.shader +++ b/Source/Shaders/TAA.shader @@ -5,6 +5,7 @@ #include "./Flax/Common.hlsl" #include "./Flax/GBuffer.hlsl" +#include "./Flax/Noise.hlsl" META_CB_BEGIN(0, Data) float2 ScreenSizeInv; @@ -13,6 +14,8 @@ float Sharpness; float StationaryBlending; float MotionBlending; float Dummy0; +float3 QuantizationError; +float Dummy1; GBufferData GBuffer; META_CB_END @@ -104,5 +107,10 @@ float4 PS(Quad_VS2PS input) : SV_Target0 color = lerp(color, neighborhoodSharp, saturate(miss)); color = clamp(color, 0, HDR_CLAMP_MAX); + + // Apply quantization error to reduce yellowish artifacts due to R11G11B10 format + float noise = rand2dTo1d(input.TexCoord); + color.rgb = QuantizeColor(color.rgb, noise, QuantizationError); + return color; }