Skip to content

Commit fa9bdac

Browse files
anisunitysebastienlagarde
authored andcommitted
Fixed the point distribution for the diffuse denoiser sometimes not being properly intialized. #6194
1 parent cb537b7 commit fa9bdac

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2020
- Fixed Z axis orientation when sampling 3D textures in local volumetric fog.
2121
- Fixed geometry scale issue with the Eye Shader.
2222
- Fixed motion vector buffer not accessible from custom passes in the BeforeTransparent, BeforePreRefraction and AfterDepthAndNormal injection points.
23+
- Fixed the point distribution for the diffuse denoiser sometimes not being properly intialized.
2324

2425
### Changed
2526
- Maximum light count per fine prunned tile (opaque deferred) is now 63 instead of 23.

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDDiffuseDenoiser.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,32 @@ class HDDiffuseDenoiser
99
// Resources used for the de-noiser
1010
ComputeShader m_DiffuseDenoiser;
1111

12-
HDRenderPipeline m_RenderPipeline;
12+
// Runtime Initialization data
13+
bool m_DenoiserInitialized;
14+
Texture2D m_OwnenScrambledTexture;
15+
ComputeBuffer m_PointDistribution;
1316

1417
// Kernels that may be required
1518
int m_BilateralFilterSingleKernel;
1619
int m_BilateralFilterColorKernel;
1720
int m_GatherSingleKernel;
1821
int m_GatherColorKernel;
19-
ComputeBuffer m_PointDistribution;
2022

2123
public void Init(HDRenderPipelineRuntimeResources rpResources, HDRenderPipeline renderPipeline)
2224
{
2325
// Keep track of the resources
2426
m_DiffuseDenoiser = rpResources.shaders.diffuseDenoiserCS;
2527

26-
m_RenderPipeline = renderPipeline;
27-
2828
// Grab all the kernels we'll eventually need
2929
m_BilateralFilterSingleKernel = m_DiffuseDenoiser.FindKernel("BilateralFilterSingle");
3030
m_BilateralFilterColorKernel = m_DiffuseDenoiser.FindKernel("BilateralFilterColor");
3131
m_GatherSingleKernel = m_DiffuseDenoiser.FindKernel("GatherSingle");
3232
m_GatherColorKernel = m_DiffuseDenoiser.FindKernel("GatherColor");
3333

34-
// Generate the point distribution
35-
int m_GeneratePointDistributionKernel = m_DiffuseDenoiser.FindKernel("GeneratePointDistribution");
34+
// Data required for the online initialization
35+
m_DenoiserInitialized = false;
36+
m_OwnenScrambledTexture = rpResources.textures.owenScrambledRGBATex;
3637
m_PointDistribution = new ComputeBuffer(16 * 2 * 4, sizeof(float));
37-
m_DiffuseDenoiser.SetTexture(m_GeneratePointDistributionKernel, HDShaderIDs._OwenScrambledRGTexture, rpResources.textures.owenScrambledRGBATex);
38-
m_DiffuseDenoiser.SetBuffer(m_GeneratePointDistributionKernel, "_PointDistributionRW", m_PointDistribution);
39-
m_DiffuseDenoiser.Dispatch(m_GeneratePointDistributionKernel, 1, 1, 1);
4038
}
4139

4240
public void Release()
@@ -52,6 +50,7 @@ class DiffuseDenoiserPassData
5250
public int viewCount;
5351

5452
// Denoising parameters
53+
public bool needInit;
5554
public float pixelSpreadTangent;
5655
public float kernelSize;
5756
public bool halfResolutionFilter;
@@ -67,6 +66,7 @@ class DiffuseDenoiserPassData
6766
public ComputeBufferHandle pointDistribution;
6867
public ComputeShader diffuseDenoiserCS;
6968

69+
public Texture2D owenScrambledTexture;
7070
public TextureHandle depthStencilBuffer;
7171
public TextureHandle normalBuffer;
7272
public TextureHandle noisyBuffer;
@@ -91,7 +91,11 @@ public TextureHandle Denoise(RenderGraph renderGraph, HDCamera hdCamera, Diffuse
9191
// Cannot run in async
9292
builder.EnableAsyncCompute(false);
9393

94-
// Fetch all the resources
94+
// Initialization data
95+
passData.needInit = !m_DenoiserInitialized;
96+
m_DenoiserInitialized = true;
97+
passData.owenScrambledTexture = m_OwnenScrambledTexture;
98+
9599
// Camera parameters
96100
if (denoiserParams.fullResolutionInput)
97101
{
@@ -110,7 +114,7 @@ public TextureHandle Denoise(RenderGraph renderGraph, HDCamera hdCamera, Diffuse
110114
passData.kernelSize = denoiserParams.kernelSize;
111115
passData.halfResolutionFilter = denoiserParams.halfResolutionFilter;
112116
passData.jitterFilter = denoiserParams.jitterFilter;
113-
passData.frameIndex = m_RenderPipeline.RayTracingFrameIndex(hdCamera);
117+
passData.frameIndex = HDRenderPipeline.RayTracingFrameIndex(hdCamera);
114118
passData.fullResolutionInput = denoiserParams.fullResolutionInput;
115119

116120
// Kernels
@@ -130,6 +134,15 @@ public TextureHandle Denoise(RenderGraph renderGraph, HDCamera hdCamera, Diffuse
130134
builder.SetRenderFunc(
131135
(DiffuseDenoiserPassData data, RenderGraphContext ctx) =>
132136
{
137+
// Generate the point distribution if needed (this is only ran once)
138+
if (passData.needInit)
139+
{
140+
int m_GeneratePointDistributionKernel = data.diffuseDenoiserCS.FindKernel("GeneratePointDistribution");
141+
ctx.cmd.SetComputeTextureParam(data.diffuseDenoiserCS, m_GeneratePointDistributionKernel, HDShaderIDs._OwenScrambledRGTexture, data.owenScrambledTexture);
142+
ctx.cmd.SetComputeBufferParam(data.diffuseDenoiserCS, m_GeneratePointDistributionKernel, "_PointDistributionRW", data.pointDistribution);
143+
ctx.cmd.DispatchCompute(data.diffuseDenoiserCS, m_GeneratePointDistributionKernel, 1, 1, 1);
144+
}
145+
133146
// Evaluate the dispatch parameters
134147
int areaTileSize = 8;
135148
int numTilesX = (data.texWidth + (areaTileSize - 1)) / areaTileSize;

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ static internal bool ValidRayTracingHistory(HDCamera hdCamera)
590590
&& hdCamera.historyRTHandleProperties.previousViewportSize.y == hdCamera.actualHeight;
591591
}
592592

593-
internal int RayTracingFrameIndex(HDCamera hdCamera)
593+
internal static int RayTracingFrameIndex(HDCamera hdCamera)
594594
{
595595
#if UNITY_HDRP_DXR_TESTS_DEFINE
596596
if (Application.isPlaying)

0 commit comments

Comments
 (0)