Skip to content

Commit 4ea9e92

Browse files
Fix accumulation on DX11 (#1987)
* Fix accumulation on DX11 * Remove left-over line of code * minor bugfix Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent bd8038f commit 4ea9e92

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
120120
- Fixed the Ray-Tracing related Debug Display not working in render graph mode.
121121
- Fix nan in pbr sky
122122
- Fixed Light skin not properly applied on the LookDev when switching from Dark Skin (case 1278802)
123+
- Fixed accumulation on DX11
123124

124125
### Changed
125126
- Preparation pass for RTSSShadows to be supported by render graph.

com.unity.render-pipelines.high-definition/Documentation~/Accumulation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class FrameManager : MonoBehaviour
6969
{
7070
RenderPipelineManager.beginFrameRendering -= PrepareSubFrameCallBack;
7171
HDRenderPipeline renderPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
72-
renderPipeline.EndRecording();
72+
renderPipeline?.EndRecording();
7373
m_Recording = false;
7474
}
7575

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
#pragma kernel KMain
66

7+
#pragma multi_compile _ INPUT_FROM_RADIANCE_TEXTURE
8+
79
// Inputs
10+
#ifdef INPUT_FROM_RADIANCE_TEXTURE
811
TEXTURE2D_X(_RadianceTexture);
12+
#endif
13+
914
float4 _AccumulationWeights;
1015
int _AccumulationNeedsExposure;
1116
uint _AccumulationFrameIndex;
@@ -55,8 +60,12 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
5560
_CameraColorTextureRW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)].xyz * exposureMultiplier, 1.0);
5661
}
5762
else
58-
{
63+
{
64+
#ifdef INPUT_FROM_RADIANCE_TEXTURE
5965
float4 color = _RadianceTexture[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
66+
#else
67+
float4 color = _CameraColorTextureRW[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
68+
#endif
6069

6170
if (sampleCount++)
6271
color.xyz = (_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)].xyz * _AccumulationWeights.y + _AccumulationWeights.x * color.xyz) * _AccumulationWeights.z;

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ struct RenderAccumulationParameters
291291
public HDCamera hdCamera;
292292
}
293293

294-
RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCamera, bool needExposure)
294+
RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCamera, bool needExposure, bool inputFromRadianceTexture)
295295
{
296296
var parameters = new RenderAccumulationParameters();
297297

@@ -301,6 +301,11 @@ RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCame
301301
parameters.needExposure = needExposure;
302302
parameters.hdCamera = hdCamera;
303303

304+
parameters.accumulationCS.shaderKeywords = null;
305+
if (inputFromRadianceTexture)
306+
{
307+
parameters.accumulationCS.EnableKeyword("INPUT_FROM_RADIANCE_TEXTURE");
308+
}
304309
return parameters;
305310
}
306311

@@ -310,7 +315,8 @@ void RenderAccumulation(HDCamera hdCamera, RTHandle inputTexture, RTHandle outpu
310315
RTHandle history = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.PathTracing)
311316
?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.PathTracing, PathTracingHistoryBufferAllocatorFunction, 1);
312317

313-
var parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure);
318+
bool inputFromRadianceTexture = !inputTexture.Equals(outputTexture);
319+
var parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure, inputFromRadianceTexture);
314320
RenderAccumulation(parameters, inputTexture, outputTexture, history, cmd);
315321
}
316322

@@ -332,7 +338,10 @@ static void RenderAccumulation(in RenderAccumulationParameters parameters, RTHan
332338
cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNumSamples, (int)parameters.subFrameManager.subFrameCount);
333339
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._AccumulatedFrameTexture, historyTexture);
334340
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._CameraColorTextureRW, outputTexture);
335-
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture);
341+
if (!inputTexture.Equals(outputTexture))
342+
{
343+
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture);
344+
}
336345
cmd.SetComputeVectorParam(accumulationShader, HDShaderIDs._AccumulationWeights, frameWeights);
337346
cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNeedsExposure, parameters.needExposure ? 1 : 0);
338347
cmd.DispatchCompute(accumulationShader, parameters.accumulationKernel, (parameters.hdCamera.actualWidth + 7) / 8, (parameters.hdCamera.actualHeight + 7) / 8, parameters.hdCamera.viewCount);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,8 @@ void RenderAccumulation(RenderGraph renderGraph, HDCamera hdCamera, TextureHandl
13831383
TextureHandle history = renderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.PathTracing)
13841384
?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.PathTracing, PathTracingHistoryBufferAllocatorFunction, 1));
13851385

1386-
passData.parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure);
1386+
bool inputFromRadianceTexture = !inputTexture.Equals(outputTexture);
1387+
passData.parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure, inputFromRadianceTexture);
13871388
passData.input = builder.ReadTexture(inputTexture);
13881389
passData.output = builder.WriteTexture(outputTexture);
13891390
passData.history = builder.WriteTexture(history);

0 commit comments

Comments
 (0)