From eab96f208639c3c594a6a565970ac48bae2064eb Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 2 Jun 2024 11:01:23 +0200 Subject: [PATCH] Fix TAA jittering when rendering UI in world after TAA resolve --- Source/Engine/UI/UICanvas.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Engine/UI/UICanvas.cs b/Source/Engine/UI/UICanvas.cs index 0ddac70e1..0d8d79eb3 100644 --- a/Source/Engine/UI/UICanvas.cs +++ b/Source/Engine/UI/UICanvas.cs @@ -72,6 +72,7 @@ namespace FlaxEngine bounds.Transformation.Translation -= renderContext.View.Origin; if (renderContext.View.Frustum.Contains(bounds.GetBoundingBox()) == ContainmentType.Disjoint) return; + var worldSpace = Canvas.RenderMode == CanvasRenderMode.WorldSpace || Canvas.RenderMode == CanvasRenderMode.WorldSpaceFaceCamera; Profiler.BeginEvent("UI Canvas"); Profiler.BeginEventGPU("UI Canvas"); @@ -79,14 +80,17 @@ namespace FlaxEngine // Calculate rendering matrix (world*view*projection) Canvas.GetWorldMatrix(renderContext.View.Origin, out Matrix worldMatrix); Matrix.Multiply(ref worldMatrix, ref renderContext.View.View, out Matrix viewMatrix); - Matrix.Multiply(ref viewMatrix, ref renderContext.View.Projection, out Matrix viewProjectionMatrix); + Matrix projectionMatrix = renderContext.View.Projection; + if (worldSpace && (Canvas.RenderLocation == PostProcessEffectLocation.Default || Canvas.RenderLocation == PostProcessEffectLocation.AfterAntiAliasingPass)) + projectionMatrix = renderContext.View.NonJitteredProjection; // Fix TAA jittering when rendering UI in world after TAA resolve + Matrix.Multiply(ref viewMatrix, ref projectionMatrix, out Matrix viewProjectionMatrix); // Pick a depth buffer GPUTexture depthBuffer = Canvas.IgnoreDepth ? null : renderContext.Buffers.DepthBuffer; // Render GUI in 3D var features = Render2D.Features; - if (Canvas.RenderMode == CanvasRenderMode.WorldSpace || Canvas.RenderMode == CanvasRenderMode.WorldSpaceFaceCamera) + if (worldSpace) Render2D.Features &= ~Render2D.RenderingFeatures.VertexSnapping; Render2D.CallDrawing(Canvas.GUI, context, input, depthBuffer, ref viewProjectionMatrix); Render2D.Features = features;