Skip to content

Commit b18ef86

Browse files
pmavridisEvergreen
authored andcommitted
Fix viewport flickering when multi-frame rendering API is used with certain parameters
Our user was getting flickering when using accumulation motion blur with certain parameters: https://jira.unity3d.com/browse/UUM-59115 The root cause of this was that we were not properly handling the case that the first sample in the Monte Carlo accumulation has zero weight. I've re-arranged the formula to output zero in this case. Path tracing without motion blur always uses a weight of one for all frames, so it should not be affected. @pieterjan-bartels if you think there is an issue let me know. I've also fixed an error in the example script in the documentation: it was capturing a screenshot in two places, only one is needed.
1 parent d5901a2 commit b18ef86

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

Packages/com.unity.render-pipelines.high-definition/Documentation~/rendering-combine-animation-sequences-in-script.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,5 @@ public class FrameManager : MonoBehaviour
8484
// Make sure the shutter will begin closing sometime after it is fully open (and not before)
8585
shutterBeginsClosing = Mathf.Max(shutterFullyOpen, shutterBeginsClosing);
8686
}
87-
88-
void Update()
89-
{
90-
// Save a screenshot to disk when recording
91-
if (m_Recording && m_Iteration % samples == 0)
92-
{
93-
ScreenCapture.CaptureScreenshot($"frame_{m_RecordedFrames++}.png");
94-
}
95-
}
9687
}
9788
```

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/Shaders/Accumulation.compute

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
7373
#ifdef INPUT_FROM_FRAME_TEXTURE
7474
float4 color = _FrameTexture[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
7575
#else
76-
float4 color = _CameraColorTextureRW[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
76+
float4 color = _CameraColorTextureRW[COORD_TEXTURE2D_X(dispatchThreadId.xy)] * _AccumulationWeights.x;
7777
#endif
7878

79-
if (sampleCount++)
80-
color = (_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)] * _AccumulationWeights.y + _AccumulationWeights.x * color) * _AccumulationWeights.z;
79+
if (sampleCount > 0)
80+
color = (_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)] * _AccumulationWeights.y + color);
81+
82+
color *= _AccumulationWeights.z;
8183

8284
_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)] = color;
8385

@@ -86,7 +88,7 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
8688
color *= exposureMultiplier;
8789

8890
// Add a little convergence cue to our result
89-
AddConvergenceCue(currentPixelCoord, sampleCount, color.xyz);
91+
AddConvergenceCue(currentPixelCoord, sampleCount + 1, color.xyz);
9092

9193
_CameraColorTextureRW[COORD_TEXTURE2D_X(currentPixelCoord)] = color;
9294
#endif

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ float ShutterProfile(float time)
322322
else if (time > m_ShutterBeginsClosing)
323323
{
324324
float closingSlope = 1.0f / (1.0f - m_ShutterBeginsClosing);
325-
return 1.0f - closingSlope * (time - m_ShutterBeginsClosing);
325+
// We are using max to prevent the weight from going negative due to numerical imprecision
326+
return Mathf.Max(0.0f, 1.0f - closingSlope * (time - m_ShutterBeginsClosing));
326327
}
327328
else
328329
{

0 commit comments

Comments
 (0)