Skip to content

Commit 64a6c13

Browse files
Fix SSR accumulation white flash (#4648)
* Fix white flash * changelog Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent 5945333 commit 64a6c13

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
202202
- Fixed HDRP's ShaderGraphVersion migration management which was broken.
203203
- Fixed missing API documentation for LTC area light code.
204204
- Fixed AxF debug output in certain configurations (case 1333780).
205+
- Fixed white flash when camera is reset and SSR Accumulation mode is on.
205206

206207
### Changed
207208
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public struct ViewConstants
9494
public bool volumetricHistoryIsValid = false;
9595

9696
internal int volumetricValidFrames = 0;
97+
internal int colorPyramidHistoryValidFrames = 0;
9798

9899
/// <summary>Width actually used for rendering after dynamic resolution and XR is applied.</summary>
99100
public int actualWidth { get; private set; }
@@ -147,6 +148,7 @@ public void Reset()
147148
volumetricHistoryIsValid = false;
148149
volumetricValidFrames = 0;
149150
colorPyramidHistoryIsValid = false;
151+
colorPyramidHistoryValidFrames = 0;
150152
dofHistoryIsValid = false;
151153

152154
// Reset the volumetric cloud offset animation data

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ class RenderSSRPassData
403403
public bool usePBRAlgo;
404404
public bool accumNeedClear;
405405
public bool previousAccumNeedClear;
406+
public bool validColorPyramid;
406407

407408
public int width, height, viewCount;
408409

@@ -511,6 +512,7 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
511512
passData.accumNeedClear = usePBRAlgo;
512513
passData.previousAccumNeedClear = usePBRAlgo && (hdCamera.currentSSRAlgorithm == ScreenSpaceReflectionAlgorithm.Approximation || hdCamera.isFirstFrame || hdCamera.resetPostProcessingHistory);
513514
hdCamera.currentSSRAlgorithm = volumeSettings.usedAlgorithm.value; // Store for next frame comparison
515+
passData.validColorPyramid = hdCamera.colorPyramidHistoryValidFrames > 1;
514516

515517
passData.depthBuffer = builder.ReadTexture(prepassOutput.depthBuffer);
516518
passData.depthPyramid = builder.ReadTexture(prepassOutput.depthPyramidTexture);
@@ -603,22 +605,30 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
603605

604606
if (data.usePBRAlgo)
605607
{
606-
using (new ProfilingScope(ctx.cmd, ProfilingSampler.Get(HDProfileId.SsrAccumulate)))
608+
if (!data.validColorPyramid)
607609
{
608-
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._DepthTexture, data.depthBuffer);
609-
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._CameraDepthTexture, data.depthPyramid);
610-
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._NormalBufferTexture, data.normalBuffer);
611-
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._ColorPyramidTexture, data.colorPyramid);
612-
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._SsrHitPointTexture, data.hitPointsTexture);
613-
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._SSRAccumTexture, data.ssrAccum);
614-
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._SsrLightingTextureRW, data.lightingTexture);
615-
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._SsrAccumPrev, data.ssrAccumPrev);
616-
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._SsrClearCoatMaskTexture, data.clearCoatMask);
617-
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._CameraMotionVectorsTexture, data.motionVectorsBuffer);
618-
619-
ConstantBuffer.Push(ctx.cmd, data.cb, cs, HDShaderIDs._ShaderVariablesScreenSpaceReflection);
620-
621-
ctx.cmd.DispatchCompute(cs, data.accumulateKernel, HDUtils.DivRoundUp(data.width, 8), HDUtils.DivRoundUp(data.height, 8), data.viewCount);
610+
CoreUtils.SetRenderTarget(ctx.cmd, data.ssrAccum, ClearFlag.Color, Color.clear);
611+
CoreUtils.SetRenderTarget(ctx.cmd, data.ssrAccumPrev, ClearFlag.Color, Color.clear);
612+
}
613+
else
614+
{
615+
using (new ProfilingScope(ctx.cmd, ProfilingSampler.Get(HDProfileId.SsrAccumulate)))
616+
{
617+
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._DepthTexture, data.depthBuffer);
618+
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._CameraDepthTexture, data.depthPyramid);
619+
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._NormalBufferTexture, data.normalBuffer);
620+
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._ColorPyramidTexture, data.colorPyramid);
621+
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._SsrHitPointTexture, data.hitPointsTexture);
622+
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._SSRAccumTexture, data.ssrAccum);
623+
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._SsrLightingTextureRW, data.lightingTexture);
624+
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._SsrAccumPrev, data.ssrAccumPrev);
625+
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._SsrClearCoatMaskTexture, data.clearCoatMask);
626+
ctx.cmd.SetComputeTextureParam(cs, data.accumulateKernel, HDShaderIDs._CameraMotionVectorsTexture, data.motionVectorsBuffer);
627+
628+
ConstantBuffer.Push(ctx.cmd, data.cb, cs, HDShaderIDs._ShaderVariablesScreenSpaceReflection);
629+
630+
ctx.cmd.DispatchCompute(cs, data.accumulateKernel, HDUtils.DivRoundUp(data.width, 8), HDUtils.DivRoundUp(data.height, 8), data.viewCount);
631+
}
622632
}
623633
}
624634
});
@@ -639,8 +649,13 @@ TextureHandle RenderSSR(RenderGraph renderGraph,
639649
if (!hdCamera.colorPyramidHistoryIsValid)
640650
{
641651
hdCamera.colorPyramidHistoryIsValid = true; // For the next frame...
652+
hdCamera.colorPyramidHistoryValidFrames = 0;
642653
result = renderGraph.defaultResources.blackTextureXR;
643654
}
655+
else
656+
{
657+
hdCamera.colorPyramidHistoryValidFrames++;
658+
}
644659
}
645660

646661
PushFullScreenDebugTexture(renderGraph, result, transparent ? FullScreenDebugMode.TransparentScreenSpaceReflections : FullScreenDebugMode.ScreenSpaceReflections);

0 commit comments

Comments
 (0)