public void RenderRTAO(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputTexture, ShaderVariablesRaytracing globalCB, ScriptableRenderContext renderContext, int frameCount)
        {
            if (!m_RenderPipeline.GetRayTracingState())
            {
                SetDefaultAmbientOcclusionTexture(cmd);
                return;
            }
            AmbientOcclusionTraceParameters aoTraceParameters = PrepareAmbientOcclusionTraceParameters(hdCamera, globalCB);
            AmbientOcclusionTraceResources  aoTraceResources  = PrepareAmbientOcclusionTraceResources(hdCamera, m_AOIntermediateBuffer0);

            // 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
            using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingAmbientOcclusion)))
            {
                TraceAO(cmd, aoTraceParameters, aoTraceResources);
            }

            AmbientOcclusionDenoiseParameters aoDenoiseParameters = PrepareAmbientOcclusionDenoiseParameters(hdCamera, globalCB);
            AmbientOcclusionDenoiseResources  aoDenoiserResources = PrepareAmbientOcclusionDenoiseResources(hdCamera, m_AOIntermediateBuffer0, m_AOIntermediateBuffer1, outputTexture);

            using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingFilterAmbientOcclusion)))
            {
                DenoiseAO(cmd, hdCamera, aoDenoiseParameters, aoDenoiserResources);
            }

            AmbientOcclusionComposeParameters aoComposeParameters = PrepareAmbientOcclusionComposeParameters(hdCamera, globalCB);

            using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingComposeAmbientOcclusion)))
            {
                ComposeAO(cmd, hdCamera, aoComposeParameters, outputTexture);
            }
        }
        public void DenoiseAO(CommandBuffer cmd, HDCamera hdCamera, AmbientOcclusionDenoiseParameters aoDenoiseParameters, AmbientOcclusionDenoiseResources aoDenoiseResources)
        {
            if (aoDenoiseParameters.denoise)
            {
                // Apply the temporal denoiser
                HDTemporalFilter temporalFilter = m_RenderPipeline.GetTemporalFilter();
                temporalFilter.DenoiseBuffer(cmd, hdCamera, aoDenoiseResources.inputTexture, aoDenoiseResources.ambientOcclusionHistory, aoDenoiseResources.intermediateBuffer, historyValidity: aoDenoiseParameters.historyValidity);

                // Apply the diffuse denoiser
                HDDiffuseDenoiser diffuseDenoiser = m_RenderPipeline.GetDiffuseDenoiser();
                diffuseDenoiser.DenoiseBuffer(cmd, hdCamera, aoDenoiseResources.intermediateBuffer, aoDenoiseResources.outputTexture, aoDenoiseParameters.denoiserRadius);
            }
            else
            {
                HDUtils.BlitCameraTexture(cmd, aoDenoiseResources.inputTexture, aoDenoiseResources.outputTexture);
            }
        }
        AmbientOcclusionDenoiseParameters PrepareAmbientOcclusionDenoiseParameters(HDCamera hdCamera, ShaderVariablesRaytracing raytracingCB)
        {
            AmbientOcclusionDenoiseParameters rtAOParameters = new AmbientOcclusionDenoiseParameters();
            var aoSettings = hdCamera.volumeStack.GetComponent <AmbientOcclusion>();

            rtAOParameters.denoise         = aoSettings.denoise;
            rtAOParameters.denoiserRadius  = aoSettings.denoiserRadius;
            rtAOParameters.historyValidity = 1.0f;
#if UNITY_HDRP_DXR_TESTS_DEFINE
            if (Application.isPlaying)
            {
                rtAOParameters.historyValidity = 0.0f;
            }
            else
#endif
            // We need to check if something invalidated the history buffers
            rtAOParameters.historyValidity = m_RenderPipeline.ValidRayTracingHistory(hdCamera) ? 1.0f : 0.0f;
            rtAOParameters.actualWidth     = hdCamera.actualWidth;
            rtAOParameters.actualHeight    = hdCamera.actualHeight;
            rtAOParameters.viewCount       = hdCamera.viewCount;
            return(rtAOParameters);
        }
Example #4
0
        public void DenoiseAO(CommandBuffer cmd, HDCamera hdCamera, AmbientOcclusionDenoiseParameters aoDenoiseParameters, AmbientOcclusionDenoiseResources aoDenoiseResources)
        {
            if (aoDenoiseParameters.denoise)
            {
                // Prepare and execute the temporal filter
                HDTemporalFilter         temporalFilter = m_RenderPipeline.GetTemporalFilter();
                TemporalFilterParameters tfParameters   = temporalFilter.PrepareTemporalFilterParameters(hdCamera, true, aoDenoiseParameters.historyValidity);
                RTHandle validationBuffer           = m_RenderPipeline.GetRayTracingBuffer(InternalRayTracingBuffers.R0);
                TemporalFilterResources tfResources = temporalFilter.PrepareTemporalFilterResources(hdCamera, validationBuffer, aoDenoiseResources.inputTexture, aoDenoiseResources.ambientOcclusionHistory, aoDenoiseResources.intermediateBuffer);
                HDTemporalFilter.DenoiseBuffer(cmd, tfParameters, tfResources);

                // Apply the diffuse denoiser
                HDDiffuseDenoiser         diffuseDenoiser = m_RenderPipeline.GetDiffuseDenoiser();
                DiffuseDenoiserParameters ddParams        = diffuseDenoiser.PrepareDiffuseDenoiserParameters(hdCamera, true, aoDenoiseParameters.denoiserRadius, false);
                RTHandle intermediateBuffer          = m_RenderPipeline.GetRayTracingBuffer(InternalRayTracingBuffers.RGBA0);
                DiffuseDenoiserResources ddResources = diffuseDenoiser.PrepareDiffuseDenoiserResources(aoDenoiseResources.intermediateBuffer, intermediateBuffer, aoDenoiseResources.outputTexture);
                HDDiffuseDenoiser.DenoiseBuffer(cmd, ddParams, ddResources);
            }
            else
            {
                HDUtils.BlitCameraTexture(cmd, aoDenoiseResources.inputTexture, aoDenoiseResources.outputTexture);
            }
        }