@@ -9,34 +9,32 @@ class HDDiffuseDenoiser
9
9
// Resources used for the de-noiser
10
10
ComputeShader m_DiffuseDenoiser ;
11
11
12
- HDRenderPipeline m_RenderPipeline ;
12
+ // Runtime Initialization data
13
+ bool m_DenoiserInitialized ;
14
+ Texture2D m_OwnenScrambledTexture ;
15
+ ComputeBuffer m_PointDistribution ;
13
16
14
17
// Kernels that may be required
15
18
int m_BilateralFilterSingleKernel ;
16
19
int m_BilateralFilterColorKernel ;
17
20
int m_GatherSingleKernel ;
18
21
int m_GatherColorKernel ;
19
- ComputeBuffer m_PointDistribution ;
20
22
21
23
public void Init ( HDRenderPipelineRuntimeResources rpResources , HDRenderPipeline renderPipeline )
22
24
{
23
25
// Keep track of the resources
24
26
m_DiffuseDenoiser = rpResources . shaders . diffuseDenoiserCS ;
25
27
26
- m_RenderPipeline = renderPipeline ;
27
-
28
28
// Grab all the kernels we'll eventually need
29
29
m_BilateralFilterSingleKernel = m_DiffuseDenoiser . FindKernel ( "BilateralFilterSingle" ) ;
30
30
m_BilateralFilterColorKernel = m_DiffuseDenoiser . FindKernel ( "BilateralFilterColor" ) ;
31
31
m_GatherSingleKernel = m_DiffuseDenoiser . FindKernel ( "GatherSingle" ) ;
32
32
m_GatherColorKernel = m_DiffuseDenoiser . FindKernel ( "GatherColor" ) ;
33
33
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 ;
36
37
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 ) ;
40
38
}
41
39
42
40
public void Release ( )
@@ -52,6 +50,7 @@ class DiffuseDenoiserPassData
52
50
public int viewCount ;
53
51
54
52
// Denoising parameters
53
+ public bool needInit ;
55
54
public float pixelSpreadTangent ;
56
55
public float kernelSize ;
57
56
public bool halfResolutionFilter ;
@@ -67,6 +66,7 @@ class DiffuseDenoiserPassData
67
66
public ComputeBufferHandle pointDistribution ;
68
67
public ComputeShader diffuseDenoiserCS ;
69
68
69
+ public Texture2D owenScrambledTexture ;
70
70
public TextureHandle depthStencilBuffer ;
71
71
public TextureHandle normalBuffer ;
72
72
public TextureHandle noisyBuffer ;
@@ -91,7 +91,11 @@ public TextureHandle Denoise(RenderGraph renderGraph, HDCamera hdCamera, Diffuse
91
91
// Cannot run in async
92
92
builder . EnableAsyncCompute ( false ) ;
93
93
94
- // Fetch all the resources
94
+ // Initialization data
95
+ passData . needInit = ! m_DenoiserInitialized ;
96
+ m_DenoiserInitialized = true ;
97
+ passData . owenScrambledTexture = m_OwnenScrambledTexture ;
98
+
95
99
// Camera parameters
96
100
if ( denoiserParams . fullResolutionInput )
97
101
{
@@ -110,7 +114,7 @@ public TextureHandle Denoise(RenderGraph renderGraph, HDCamera hdCamera, Diffuse
110
114
passData . kernelSize = denoiserParams . kernelSize ;
111
115
passData . halfResolutionFilter = denoiserParams . halfResolutionFilter ;
112
116
passData . jitterFilter = denoiserParams . jitterFilter ;
113
- passData . frameIndex = m_RenderPipeline . RayTracingFrameIndex ( hdCamera ) ;
117
+ passData . frameIndex = HDRenderPipeline . RayTracingFrameIndex ( hdCamera ) ;
114
118
passData . fullResolutionInput = denoiserParams . fullResolutionInput ;
115
119
116
120
// Kernels
@@ -130,6 +134,15 @@ public TextureHandle Denoise(RenderGraph renderGraph, HDCamera hdCamera, Diffuse
130
134
builder . SetRenderFunc (
131
135
( DiffuseDenoiserPassData data , RenderGraphContext ctx ) =>
132
136
{
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
+
133
146
// Evaluate the dispatch parameters
134
147
int areaTileSize = 8 ;
135
148
int numTilesX = ( data . texWidth + ( areaTileSize - 1 ) ) / areaTileSize ;
0 commit comments