public void Render(ScreenSpaceAmbientOcclusionSettings.Settings settings, HDRenderPipeline hdRP, HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd, bool isForward)
        {
            const RenderTextureFormat    kTempFormat = RenderTextureFormat.ARGB32;
            const RenderTextureReadWrite kRWMode     = RenderTextureReadWrite.Linear;
            const FilterMode             kFilter     = FilterMode.Bilinear;

            // Note: Currently there is no SSAO in forward as we don't have normal buffer
            // If SSAO is disable, simply put a white 1x1 texture
            if (settings.enable == false || isForward)
            {
                cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, UnityEngine.Rendering.PostProcessing.RuntimeUtilities.blackTexture); // Neutral is black, see the comment in the shaders
                cmd.SetGlobalFloat(HDShaderIDs._AmbientOcclusionDirectLightStrenght, 0.0f);
                return;
            }

            var width    = hdCamera.camera.pixelWidth;
            var height   = hdCamera.camera.pixelHeight;
            var downsize = settings.downsampling ? 2 : 1;

            // Provide the settings via uniforms.
            m_Material.SetFloat(Uniforms._Intensity, settings.intensity);
            m_Material.SetFloat(Uniforms._Radius, settings.radius);
            m_Material.SetFloat(Uniforms._Downsample, 1.0f / downsize);
            m_Material.SetFloat(Uniforms._SampleCount, settings.sampleCount);

            using (new Utilities.ProfilingSample("Screenspace ambient occlusion", cmd))
            {
                // AO estimation.
                cmd.GetTemporaryRT(Uniforms._TempTex1, width / downsize, height / downsize, 0, kFilter, kTempFormat, kRWMode);
                Utilities.DrawFullScreen(cmd, m_Material, Uniforms._TempTex1, null, 0);
                hdRP.PushFullScreenDebugTexture(cmd, Uniforms._TempTex1, hdCamera.camera, renderContext, FullScreenDebugMode.SSAOBeforeFiltering);

                // Denoising (horizontal pass).
                cmd.GetTemporaryRT(Uniforms._TempTex2, width, height, 0, kFilter, kTempFormat, kRWMode);
                cmd.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex1);
                Utilities.DrawFullScreen(cmd, m_Material, Uniforms._TempTex2, null, 1);
                cmd.ReleaseTemporaryRT(Uniforms._TempTex1);

                // Denoising (vertical pass).
                cmd.GetTemporaryRT(Uniforms._TempTex1, width, height, 0, kFilter, kTempFormat, kRWMode);
                cmd.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex2);
                Utilities.DrawFullScreen(cmd, m_Material, Uniforms._TempTex1, null, 2);
                cmd.ReleaseTemporaryRT(Uniforms._TempTex2);

                // Final filtering
                cmd.GetTemporaryRT(Uniforms._AOBuffer, width, height, 0, kFilter, GetAOBufferFormat(), kRWMode);
                cmd.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex1);
                Utilities.DrawFullScreen(cmd, m_Material, Uniforms._AOBuffer, null, 3);
                cmd.ReleaseTemporaryRT(Uniforms._TempTex1);

                // Setup texture for lighting pass (automatic of unity)
                cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, Uniforms._AOBuffer);
                cmd.SetGlobalFloat(HDShaderIDs._AmbientOcclusionDirectLightStrenght, settings.affectDirectLigthingStrenght);
                hdRP.PushFullScreenDebugTexture(cmd, Uniforms._AOBuffer, hdCamera.camera, renderContext, FullScreenDebugMode.SSAO);
            }
        }
        public void Render(ScreenSpaceAmbientOcclusionSettings.Settings settings, HDRenderPipelineAsset hdRP, Camera hdCamera, ScriptableRenderContext renderContext, bool isForward)
        {
            const RenderTextureFormat    kTempFormat = RenderTextureFormat.ARGB32;
            const RenderTextureReadWrite kRWMode     = RenderTextureReadWrite.Linear;
            const FilterMode             kFilter     = FilterMode.Bilinear;

            if (m_Command == null)
            {
                m_Command = new CommandBuffer {
                    name = "Ambient Occlusion"
                };
            }
            else
            {
                m_Command.Clear();
            }

            // Note: Currently there is no SSAO in forward as we don't have normal buffer
            // If SSAO is disable, simply put a white 1x1 texture
            if (settings.enable == false || isForward)
            {
                m_Command.SetGlobalTexture(Uniforms._AOBuffer, PostProcessing.RuntimeUtilities.blackTexture); // Neutral is black, see the comment in the shaders
                renderContext.ExecuteCommandBuffer(m_Command);
                return;
            }

            //var width = hdCamera.camera.pixelWidth;
            //var height = hdCamera.camera.pixelHeight;
            var downsize = settings.downsampling ? 2 : 1;

            // Provide the settings via uniforms.
            m_Material.SetFloat(Uniforms._Intensity, settings.intensity);
            m_Material.SetFloat(Uniforms._Radius, settings.radius);
            m_Material.SetFloat(Uniforms._Downsample, 1.0f / downsize);
            m_Material.SetFloat(Uniforms._SampleCount, settings.sampleCount);

            /*
             * // AO estimation.
             * m_Command.GetTemporaryRT(Uniforms._TempTex1, width / downsize, height / downsize, 0, kFilter, kTempFormat, kRWMode);
             * //Utilities.DrawFullScreen(m_Command, m_Material, hdCamera, Uniforms._TempTex1, null, 0);
             * hdRP.PushFullScreenDebugTexture(m_Command, Uniforms._TempTex1, hdCamera.camera, renderContext, FullScreenDebugMode.SSAOBeforeFiltering);
             *
             * // Denoising (horizontal pass).
             * m_Command.GetTemporaryRT(Uniforms._TempTex2, width, height, 0, kFilter, kTempFormat, kRWMode);
             * m_Command.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex1);
             * //Utilities.DrawFullScreen(m_Command, m_Material, hdCamera, Uniforms._TempTex2, null, 1);
             * m_Command.ReleaseTemporaryRT(Uniforms._TempTex1);
             *
             * // Denoising (vertical pass).
             * m_Command.GetTemporaryRT(Uniforms._TempTex1, width, height, 0, kFilter, kTempFormat, kRWMode);
             * m_Command.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex2);
             * // Utilities.DrawFullScreen(m_Command, m_Material, hdCamera, Uniforms._TempTex1, null, 2);
             * m_Command.ReleaseTemporaryRT(Uniforms._TempTex2);
             *
             * // Final filtering
             * m_Command.GetTemporaryRT(Uniforms._AOBuffer, width, height, 0, kFilter, GetAOBufferFormat(), kRWMode);
             * m_Command.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex1);
             * //Utilities.DrawFullScreen(m_Command, m_Material, hdCamera, Uniforms._AOBuffer, null, 3);
             * m_Command.ReleaseTemporaryRT(Uniforms._TempTex1);
             *
             * // Setup texture for lighting pass (automagic of unity)
             * m_Command.SetGlobalTexture("_AmbientOcclusionTexture", Uniforms._AOBuffer);
             * hdRP.PushFullScreenDebugTexture(m_Command, Uniforms._AOBuffer, hdCamera.camera, renderContext, FullScreenDebugMode.SSAO);
             */
            // Register the command buffer and release it.
            renderContext.ExecuteCommandBuffer(m_Command);
        }