Fix temporal anti-aliasing to provide better quality output

This commit is contained in:
Wojciech Figat
2022-12-15 12:40:21 +01:00
parent 63e7fb85ec
commit b9244df8f7
4 changed files with 10 additions and 11 deletions

BIN
Content/Shaders/TAA.flax (Stored with Git LFS)

Binary file not shown.

View File

@@ -1906,7 +1906,7 @@ API_STRUCT() struct FLAXENGINE_API AntiAliasingSettings : ISerializable
/// The blending coefficient for moving fragments. Controls the percentage of history sample blended into the final color for fragments with significant active motion. /// The blending coefficient for moving fragments. Controls the percentage of history sample blended into the final color for fragments with significant active motion.
/// </summary> /// </summary>
API_FIELD(Attributes="Limit(0, 0.99f, 0.001f), EditorOrder(4), PostProcessSetting((int)AntiAliasingSettingsOverride.TAA_MotionBlending), EditorDisplay(null, \"TAA Motion Blending\")") API_FIELD(Attributes="Limit(0, 0.99f, 0.001f), EditorOrder(4), PostProcessSetting((int)AntiAliasingSettingsOverride.TAA_MotionBlending), EditorDisplay(null, \"TAA Motion Blending\")")
float TAA_MotionBlending = 0.4f; float TAA_MotionBlending = 0.7f;
public: public:
/// <summary> /// <summary>

View File

@@ -26,9 +26,9 @@ void RenderView::Prepare(RenderContext& renderContext)
TaaFrameIndex = 0; TaaFrameIndex = 0;
// Calculate jitter // Calculate jitter
const float jitterSpread = renderContext.List->Settings.AntiAliasing.TAA_JitterSpread; const float jitterSpread = renderContext.List->Settings.AntiAliasing.TAA_JitterSpread / 0.75f;
const float jitterX = RendererUtils::TemporalHalton(TaaFrameIndex + 1, 2) * jitterSpread; const float jitterX = (RendererUtils::TemporalHalton(TaaFrameIndex + 1, 2) - 0.5f) * jitterSpread;
const float jitterY = RendererUtils::TemporalHalton(TaaFrameIndex + 1, 3) * jitterSpread; const float jitterY = (RendererUtils::TemporalHalton(TaaFrameIndex + 1, 3) - 0.5f) * jitterSpread;
taaJitter = Float2(jitterX * 2.0f / width, jitterY * 2.0f / height); taaJitter = Float2(jitterX * 2.0f / width, jitterY * 2.0f / height);
// Modify projection matrix // Modify projection matrix

View File

@@ -61,13 +61,13 @@ float4 PS(Quad_VS2PS input) : SV_Target0
} }
float2 velocity = SAMPLE_RT_LINEAR(MotionVectors, bestUV).xy; float2 velocity = SAMPLE_RT_LINEAR(MotionVectors, bestUV).xy;
float velocityLength = length(velocity); float velocityLength = length(velocity);
float2 prevUV = input.TexCoord + velocity; float2 prevUV = input.TexCoord - velocity;
// Apply sharpening // Apply sharpening
float4 neighborhoodAvg = neighborhoodSum / 9.0; float4 neighborhoodAvg = neighborhoodSum / 9.0;
current += (current - neighborhoodAvg) * Sharpness; current += (current - neighborhoodAvg) * Sharpness;
// Sample history by clamp it to the nearby colros range to reduce artifacts // Sample history by clamp it to the nearby colors range to reduce artifacts
float4 history = SAMPLE_RT_LINEAR(InputHistory, prevUV); float4 history = SAMPLE_RT_LINEAR(InputHistory, prevUV);
float lumaOffset = abs(Luminance(neighborhoodAvg) - Luminance(current)); float lumaOffset = abs(Luminance(neighborhoodAvg) - Luminance(current));
float aabbMargin = lerp(4.0, 0.25, saturate(velocityLength * 100.0)) * lumaOffset; float aabbMargin = lerp(4.0, 0.25, saturate(velocityLength * 100.0)) * lumaOffset;
@@ -75,9 +75,8 @@ float4 PS(Quad_VS2PS input) : SV_Target0
//history = clamp(history, neighborhoodMin, neighborhoodMax); //history = clamp(history, neighborhoodMin, neighborhoodMax);
// Calculate history blending factor // Calculate history blending factor
float motion = saturate(velocityLength * 600.0f); float motion = saturate(velocityLength * 1000.0f);
float blendfactor = lerp(StationaryBlending, MotionBlending, motion); float blendfactor = any(abs(prevUV * 2 - 1) >= 1.0f) ? 0.0f : lerp(StationaryBlending, MotionBlending, motion);
blendfactor = any(abs(prevUV * 2 - 1) >= 1.0f) ? 0.0f : blendfactor;
// Perform linear accumulation of the previous samples with a current one // Perform linear accumulation of the previous samples with a current one
float4 color = lerp(current, history, blendfactor); float4 color = lerp(current, history, blendfactor);