Skip to content

Commit 4e326f7

Browse files
[HDRP] Fix flickering / edge aliasing issue when DoF and TAAU or DLSS are enabled (#6371)
* Fix flickering / edge aliasing issue when DoF and TAAU or DLSS are enabled * Cache and reuse scaled texture coord * Update CHANGELOG.md Co-authored-by: JulienIgnace-Unity <julien@unity3d.com>
1 parent de8ab64 commit 4e326f7

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3333
- Fixed missing information in the tooltip of affects smooth surfaces of the ray traced reflections denoiser (case 1376918).
3434
- Fixed broken debug views when dynamic resolution was enabled (case 1365368).
3535
- Fixed shader graph errors when disabling the bias on texture samplers.
36+
- Fixed flickering / edge aliasing issue when DoF and TAAU or DLSS are enabled (case 1381858).
3637

3738
### Changed
3839
- Optimizations for the physically based depth of field.

com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/DepthOfFieldCoCReproject.compute

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
5454
float coc3 = cocBR.x;
5555
float coc4 = cocBR.z;
5656
#else
57-
float coc1 = LOAD_TEXTURE2D_X(_InputCoCTexture, posInputs.positionSS - uint2(1u, 0u)).x; // Left
58-
float coc2 = LOAD_TEXTURE2D_X(_InputCoCTexture, posInputs.positionSS - uint2(0u, 1u)).x; // Top
59-
float coc3 = LOAD_TEXTURE2D_X(_InputCoCTexture, posInputs.positionSS + uint2(0u, 1u)).x; // Bottom
60-
float coc4 = LOAD_TEXTURE2D_X(_InputCoCTexture, posInputs.positionSS + uint2(1u, 0u)).x; // Right
57+
float2 coord = ClampAndScaleUVPostProcessTextureForPoint(posInputs.positionSS);
58+
float coc1 = LOAD_TEXTURE2D_X(_InputCoCTexture, coord - uint2(1u, 0u)).x; // Left
59+
float coc2 = LOAD_TEXTURE2D_X(_InputCoCTexture, coord - uint2(0u, 1u)).x; // Top
60+
float coc3 = LOAD_TEXTURE2D_X(_InputCoCTexture, coord + uint2(0u, 1u)).x; // Bottom
61+
float coc4 = LOAD_TEXTURE2D_X(_InputCoCTexture, coord + uint2(1u, 0u)).x; // Right
6162
#endif
6263

6364
// Dejittered center sample

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,9 +2884,13 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu
28842884
{
28852885
bool postDoFTAAEnabled = false;
28862886
bool isSceneView = hdCamera.camera.cameraType == CameraType.SceneView;
2887-
bool taaEnabled = m_AntialiasingFS && hdCamera.antialiasing == HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing;
2887+
bool stabilizeCoC = m_AntialiasingFS && hdCamera.antialiasing == HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing;
28882888
bool isOrtho = hdCamera.camera.orthographic;
28892889

2890+
// If DLSS is enabled, we need to stabilize the CoC buffer (because the upsampled depth is jittered)
2891+
if (m_DLSSPassEnabled)
2892+
stabilizeCoC = true;
2893+
28902894
// If Path tracing is enabled, then DoF is computed in the path tracer by sampling the lens aperure (when using the physical camera mode)
28912895
bool isDoFPathTraced = (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) &&
28922896
hdCamera.volumeStack.GetComponent<PathTracing>().enable.value &&
@@ -2899,7 +2903,7 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu
28992903
{
29002904
// If we switch DoF modes and the old one was not using TAA, make sure we invalidate the history
29012905
// Note: for Rendergraph the m_IsDoFHisotoryValid perhaps should be moved to the "pass data" struct
2902-
if (taaEnabled && hdCamera.dofHistoryIsValid != m_DepthOfField.physicallyBased)
2906+
if (stabilizeCoC && hdCamera.dofHistoryIsValid != m_DepthOfField.physicallyBased)
29032907
{
29042908
hdCamera.resetPostProcessingHistory = true;
29052909
}
@@ -2928,7 +2932,7 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu
29282932
TextureHandle dest = GetPostprocessOutputHandle(renderGraph, "DoF Destination");
29292933
passData.destination = builder.WriteTexture(dest);
29302934
passData.motionVecTexture = builder.ReadTexture(motionVectors);
2931-
passData.taaEnabled = taaEnabled;
2935+
passData.taaEnabled = stabilizeCoC;
29322936

29332937
if (!m_DepthOfField.physicallyBased)
29342938
{
@@ -3079,7 +3083,7 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu
30793083
}
30803084

30813085
// When physically based DoF is enabled, TAA runs two times, first to stabilize the color buffer before DoF and then after DoF to accumulate more aperture samples
3082-
if (taaEnabled && m_DepthOfField.physicallyBased)
3086+
if (stabilizeCoC && m_DepthOfField.physicallyBased)
30833087
{
30843088
source = DoTemporalAntialiasing(renderGraph, hdCamera, depthBuffer, motionVectors, depthBufferMipChain, source, stencilTexture, postDoF: true, "Post-DoF TAA Destination");
30853089
hdCamera.dofHistoryIsValid = true;

0 commit comments

Comments
 (0)