@@ -63,7 +63,6 @@ static public void SetDefaultAmbientOcclusionTexture(CommandBuffer cmd)
6363 public struct AmbientOcclusionTraceParameters
6464 {
6565 // Generic attributes
66- public bool validRayTracing ;
6766 public float rayLength ;
6867 public int sampleCount ;
6968
@@ -98,7 +97,6 @@ AmbientOcclusionTraceParameters PrepareAmbientOcclusionTraceParameters(HDCamera
9897 {
9998 AmbientOcclusionTraceParameters rtAOParameters = new AmbientOcclusionTraceParameters ( ) ;
10099 var aoSettings = hdCamera . volumeStack . GetComponent < AmbientOcclusion > ( ) ;
101- rtAOParameters . validRayTracing = m_RenderPipeline . GetRayTracingState ( ) ;
102100 rtAOParameters . rayLength = aoSettings . rayLength ;
103101 rtAOParameters . sampleCount = aoSettings . sampleCount ;
104102 rtAOParameters . actualWidth = hdCamera . actualWidth ;
@@ -126,7 +124,6 @@ AmbientOcclusionTraceResources PrepareAmbientOcclusionTraceResources(HDCamera hd
126124 public struct AmbientOcclusionDenoiseParameters
127125 {
128126 // Generic attributes
129- public bool validRayTracing ;
130127 public bool denoise ;
131128 public float denoiserRadius ;
132129 public float historyValidity ;
@@ -152,7 +149,6 @@ AmbientOcclusionDenoiseParameters PrepareAmbientOcclusionDenoiseParameters(HDCam
152149 {
153150 AmbientOcclusionDenoiseParameters rtAOParameters = new AmbientOcclusionDenoiseParameters ( ) ;
154151 var aoSettings = hdCamera . volumeStack . GetComponent < AmbientOcclusion > ( ) ;
155- rtAOParameters . validRayTracing = m_RenderPipeline . GetRayTracingState ( ) ;
156152 rtAOParameters . denoise = aoSettings . denoise ;
157153 rtAOParameters . denoiserRadius = aoSettings . denoiserRadius ;
158154 rtAOParameters . historyValidity = 1.0f ;
@@ -184,7 +180,6 @@ AmbientOcclusionDenoiseResources PrepareAmbientOcclusionDenoiseResources(HDCamer
184180 public struct AmbientOcclusionComposeParameters
185181 {
186182 // Generic attributes
187- public bool validRayTracing ;
188183 public float intensity ;
189184
190185 // Camera data
@@ -199,17 +194,10 @@ public struct AmbientOcclusionComposeParameters
199194 public ComputeShader aoShaderCS ;
200195 }
201196
202- public struct AmbientOcclusionComposeResources
203- {
204- // Output Buffer
205- public RTHandle outputTexture ;
206- }
207-
208197 AmbientOcclusionComposeParameters PrepareAmbientOcclusionComposeParameters ( HDCamera hdCamera , ShaderVariablesRaytracing raytracingCB )
209198 {
210199 AmbientOcclusionComposeParameters aoComposeParameters = new AmbientOcclusionComposeParameters ( ) ;
211200 var aoSettings = hdCamera . volumeStack . GetComponent < AmbientOcclusion > ( ) ;
212- aoComposeParameters . validRayTracing = m_RenderPipeline . GetRayTracingState ( ) ;
213201 aoComposeParameters . intensity = aoSettings . intensity . value ;
214202 aoComposeParameters . actualWidth = hdCamera . actualWidth ;
215203 aoComposeParameters . actualHeight = hdCamera . actualHeight ;
@@ -219,114 +207,97 @@ AmbientOcclusionComposeParameters PrepareAmbientOcclusionComposeParameters(HDCam
219207 return aoComposeParameters ;
220208 }
221209
222- AmbientOcclusionComposeResources PrepareAmbientOcclusionComposeResources ( HDCamera hdCamera , RTHandle inOutTexture )
223- {
224- AmbientOcclusionComposeResources aoComposeResources = new AmbientOcclusionComposeResources ( ) ;
225- aoComposeResources . outputTexture = inOutTexture ;
226- return aoComposeResources ;
227- }
228-
229210 public void RenderRTAO ( HDCamera hdCamera , CommandBuffer cmd , RTHandle outputTexture , ShaderVariablesRaytracing globalCB , ScriptableRenderContext renderContext , int frameCount )
230211 {
212+ if ( ! m_RenderPipeline . GetRayTracingState ( ) )
213+ {
214+ SetDefaultAmbientOcclusionTexture ( cmd ) ;
215+ return ;
216+ }
231217 AmbientOcclusionTraceParameters aoTraceParameters = PrepareAmbientOcclusionTraceParameters ( hdCamera , globalCB ) ;
232218 AmbientOcclusionTraceResources aoTraceResources = PrepareAmbientOcclusionTraceResources ( hdCamera , m_AOIntermediateBuffer0 ) ;
233- TraceAO ( cmd , aoTraceParameters , aoTraceResources ) ;
219+ // If any of the previous requirements is missing, the effect is not requested or no acceleration structure, set the default one and leave right away
220+ using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . RaytracingAmbientOcclusion ) ) )
221+ {
222+ TraceAO ( cmd , aoTraceParameters , aoTraceResources ) ;
223+ }
234224
235225 AmbientOcclusionDenoiseParameters aoDenoiseParameters = PrepareAmbientOcclusionDenoiseParameters ( hdCamera , globalCB ) ;
236226 AmbientOcclusionDenoiseResources aoDenoiserResources = PrepareAmbientOcclusionDenoiseResources ( hdCamera , m_AOIntermediateBuffer0 , m_AOIntermediateBuffer1 , outputTexture ) ;
237- DenoiseAO ( cmd , hdCamera , aoDenoiseParameters , aoDenoiserResources ) ;
227+ using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . RaytracingFilterAmbientOcclusion ) ) )
228+ {
229+ DenoiseAO ( cmd , hdCamera , aoDenoiseParameters , aoDenoiserResources ) ;
230+ }
238231
239232 AmbientOcclusionComposeParameters aoComposeParameters = PrepareAmbientOcclusionComposeParameters ( hdCamera , globalCB ) ;
240- AmbientOcclusionComposeResources aoComposeResources = PrepareAmbientOcclusionComposeResources ( hdCamera , outputTexture ) ;
241- ComposeAO ( cmd , hdCamera , aoComposeParameters , aoComposeResources ) ;
233+ using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . RaytracingComposeAmbientOcclusion ) ) )
234+ {
235+ ComposeAO ( cmd , hdCamera , aoComposeParameters , outputTexture ) ;
236+ }
242237 }
243238
244239 static public void TraceAO ( CommandBuffer cmd , AmbientOcclusionTraceParameters aoTraceParameters , AmbientOcclusionTraceResources aoTraceResources )
245240 {
246- // If any of the previous requirements is missing, the effect is not requested or no acceleration structure, set the default one and leave right away
247- if ( ! aoTraceParameters . validRayTracing )
248- {
249- SetDefaultAmbientOcclusionTexture ( cmd ) ;
250- return ;
251- }
241+ // Define the shader pass to use for the reflection pass
242+ cmd . SetRayTracingShaderPass ( aoTraceParameters . aoShaderRT , "VisibilityDXR" ) ;
252243
253- using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . RaytracingAmbientOcclusion ) ) )
254- {
255- // Define the shader pass to use for the reflection pass
256- cmd . SetRayTracingShaderPass ( aoTraceParameters . aoShaderRT , "VisibilityDXR" ) ;
244+ // Set the acceleration structure for the pass
245+ cmd . SetRayTracingAccelerationStructure ( aoTraceParameters . aoShaderRT , HDShaderIDs . _RaytracingAccelerationStructureName , aoTraceResources . rayTracingAccelerationStructure ) ;
257246
258- // Set the acceleration structure for the pass
259- cmd . SetRayTracingAccelerationStructure ( aoTraceParameters . aoShaderRT , HDShaderIDs . _RaytracingAccelerationStructureName , aoTraceResources . rayTracingAccelerationStructure ) ;
247+ // Inject the ray generation data (be careful of the global constant buffer limitation)
248+ aoTraceParameters . raytracingCB . _RaytracingRayMaxLength = aoTraceParameters . rayLength ;
249+ aoTraceParameters . raytracingCB . _RaytracingNumSamples = aoTraceParameters . sampleCount ;
250+ ConstantBuffer . PushGlobal ( cmd , aoTraceParameters . raytracingCB , HDShaderIDs . _ShaderVariablesRaytracing ) ;
260251
261- // Inject the ray generation data (be careful of the global constant buffer limitation)
262- aoTraceParameters . raytracingCB . _RaytracingRayMaxLength = aoTraceParameters . rayLength ;
263- aoTraceParameters . raytracingCB . _RaytracingNumSamples = aoTraceParameters . sampleCount ;
264- ConstantBuffer . PushGlobal ( cmd , aoTraceParameters . raytracingCB , HDShaderIDs . _ShaderVariablesRaytracing ) ;
252+ // Set the data for the ray generation
253+ cmd . SetRayTracingTextureParam ( aoTraceParameters . aoShaderRT , HDShaderIDs . _DepthTexture , aoTraceResources . depthStencilBuffer ) ;
254+ cmd . SetRayTracingTextureParam ( aoTraceParameters . aoShaderRT , HDShaderIDs . _NormalBufferTexture , aoTraceResources . normalBuffer ) ;
265255
266- // Set the data for the ray generation
267- cmd . SetRayTracingTextureParam ( aoTraceParameters . aoShaderRT , HDShaderIDs . _DepthTexture , aoTraceResources . depthStencilBuffer ) ;
268- cmd . SetRayTracingTextureParam ( aoTraceParameters . aoShaderRT , HDShaderIDs . _NormalBufferTexture , aoTraceResources . normalBuffer ) ;
256+ // Inject the ray-tracing sampling data
257+ BlueNoise . BindDitheredTextureSet ( cmd , aoTraceResources . ditheredTextureSet ) ;
269258
270- // Inject the ray-tracing sampling data
271- BlueNoise . BindDitheredTextureSet ( cmd , aoTraceResources . ditheredTextureSet ) ;
259+ // Set the output textures
260+ cmd . SetRayTracingTextureParam ( aoTraceParameters . aoShaderRT , HDShaderIDs . _RayCountTexture , aoTraceResources . rayCountTexture ) ;
261+ cmd . SetRayTracingTextureParam ( aoTraceParameters . aoShaderRT , HDShaderIDs . _AmbientOcclusionTextureRW , aoTraceResources . outputTexture ) ;
272262
273- // Set the output textures
274- cmd . SetRayTracingTextureParam ( aoTraceParameters . aoShaderRT , HDShaderIDs . _RayCountTexture , aoTraceResources . rayCountTexture ) ;
275- cmd . SetRayTracingTextureParam ( aoTraceParameters . aoShaderRT , HDShaderIDs . _AmbientOcclusionTextureRW , aoTraceResources . outputTexture ) ;
276-
277- // Run the computation
278- cmd . DispatchRays ( aoTraceParameters . aoShaderRT , m_RayGenShaderName , ( uint ) aoTraceParameters . actualWidth , ( uint ) aoTraceParameters . actualHeight , ( uint ) aoTraceParameters . viewCount ) ;
279- }
263+ // Run the computation
264+ cmd . DispatchRays ( aoTraceParameters . aoShaderRT , m_RayGenShaderName , ( uint ) aoTraceParameters . actualWidth , ( uint ) aoTraceParameters . actualHeight , ( uint ) aoTraceParameters . viewCount ) ;
280265 }
281266
282267 public void DenoiseAO ( CommandBuffer cmd , HDCamera hdCamera , AmbientOcclusionDenoiseParameters aoDenoiseParameters , AmbientOcclusionDenoiseResources aoDenoiseResources )
283268 {
284- // If the ray tracing state is invalid, we should be doing anything
285- if ( ! aoDenoiseParameters . validRayTracing )
286- return ;
269+ if ( aoDenoiseParameters . denoise )
270+ {
271+ // Apply the temporal denoiser
272+ HDTemporalFilter temporalFilter = m_RenderPipeline . GetTemporalFilter ( ) ;
273+ temporalFilter . DenoiseBuffer ( cmd , hdCamera , aoDenoiseResources . inputTexture , aoDenoiseResources . ambientOcclusionHistory , aoDenoiseResources . intermediateBuffer , historyValidity : aoDenoiseParameters . historyValidity ) ;
287274
288- using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . RaytracingFilterAmbientOcclusion ) ) )
275+ // Apply the diffuse denoiser
276+ HDDiffuseDenoiser diffuseDenoiser = m_RenderPipeline . GetDiffuseDenoiser ( ) ;
277+ diffuseDenoiser . DenoiseBuffer ( cmd , hdCamera , aoDenoiseResources . intermediateBuffer , aoDenoiseResources . outputTexture , aoDenoiseParameters . denoiserRadius ) ;
278+ }
279+ else
289280 {
290- if ( aoDenoiseParameters . denoise )
291- {
292- // Apply the temporal denoiser
293- HDTemporalFilter temporalFilter = m_RenderPipeline . GetTemporalFilter ( ) ;
294- temporalFilter . DenoiseBuffer ( cmd , hdCamera , aoDenoiseResources . inputTexture , aoDenoiseResources . ambientOcclusionHistory , aoDenoiseResources . intermediateBuffer , historyValidity : aoDenoiseParameters . historyValidity ) ;
295-
296- // Apply the diffuse denoiser
297- HDDiffuseDenoiser diffuseDenoiser = m_RenderPipeline . GetDiffuseDenoiser ( ) ;
298- diffuseDenoiser . DenoiseBuffer ( cmd , hdCamera , aoDenoiseResources . intermediateBuffer , aoDenoiseResources . outputTexture , aoDenoiseParameters . denoiserRadius ) ;
299- }
300- else
301- {
302- HDUtils . BlitCameraTexture ( cmd , aoDenoiseResources . inputTexture , aoDenoiseResources . outputTexture ) ;
303- }
281+ HDUtils . BlitCameraTexture ( cmd , aoDenoiseResources . inputTexture , aoDenoiseResources . outputTexture ) ;
304282 }
305283 }
306284
307- static public void ComposeAO ( CommandBuffer cmd , HDCamera hdCamera , AmbientOcclusionComposeParameters aoComposeParameters , AmbientOcclusionComposeResources aoComposeResources )
285+ static public void ComposeAO ( CommandBuffer cmd , HDCamera hdCamera , AmbientOcclusionComposeParameters aoComposeParameters , RTHandle outputTexture )
308286 {
309- // If the ray tracing state is invalid, we should be doing anything
310- if ( ! aoComposeParameters . validRayTracing )
311- return ;
312-
313- using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . RaytracingComposeAmbientOcclusion ) ) )
314- {
315- cmd . SetComputeFloatParam ( aoComposeParameters . aoShaderCS , HDShaderIDs . _RaytracingAOIntensity , aoComposeParameters . intensity ) ;
316- cmd . SetComputeTextureParam ( aoComposeParameters . aoShaderCS , aoComposeParameters . intensityKernel , HDShaderIDs . _AmbientOcclusionTextureRW , aoComposeResources . outputTexture ) ;
317- int texWidth = aoComposeParameters . actualWidth ;
318- int texHeight = aoComposeParameters . actualHeight ;
319- int areaTileSize = 8 ;
320- int numTilesXHR = ( texWidth + ( areaTileSize - 1 ) ) / areaTileSize ;
321- int numTilesYHR = ( texHeight + ( areaTileSize - 1 ) ) / areaTileSize ;
322- cmd . DispatchCompute ( aoComposeParameters . aoShaderCS , aoComposeParameters . intensityKernel , numTilesXHR , numTilesYHR , aoComposeParameters . viewCount ) ;
323- }
287+ cmd . SetComputeFloatParam ( aoComposeParameters . aoShaderCS , HDShaderIDs . _RaytracingAOIntensity , aoComposeParameters . intensity ) ;
288+ cmd . SetComputeTextureParam ( aoComposeParameters . aoShaderCS , aoComposeParameters . intensityKernel , HDShaderIDs . _AmbientOcclusionTextureRW , outputTexture ) ;
289+ int texWidth = aoComposeParameters . actualWidth ;
290+ int texHeight = aoComposeParameters . actualHeight ;
291+ int areaTileSize = 8 ;
292+ int numTilesXHR = ( texWidth + ( areaTileSize - 1 ) ) / areaTileSize ;
293+ int numTilesYHR = ( texHeight + ( areaTileSize - 1 ) ) / areaTileSize ;
294+ cmd . DispatchCompute ( aoComposeParameters . aoShaderCS , aoComposeParameters . intensityKernel , numTilesXHR , numTilesYHR , aoComposeParameters . viewCount ) ;
324295
325296 // Bind the textures and the params
326- cmd . SetGlobalTexture ( HDShaderIDs . _AmbientOcclusionTexture , aoComposeResources . outputTexture ) ;
297+ cmd . SetGlobalTexture ( HDShaderIDs . _AmbientOcclusionTexture , outputTexture ) ;
327298
328299 // TODO: All the push-debug stuff should be centralized somewhere
329- ( RenderPipelineManager . currentPipeline as HDRenderPipeline ) . PushFullScreenDebugTexture ( hdCamera , cmd , aoComposeResources . outputTexture , FullScreenDebugMode . ScreenSpaceAmbientOcclusion ) ;
300+ ( RenderPipelineManager . currentPipeline as HDRenderPipeline ) . PushFullScreenDebugTexture ( hdCamera , cmd , outputTexture , FullScreenDebugMode . ScreenSpaceAmbientOcclusion ) ;
330301 }
331302 }
332303}
0 commit comments