Beispiel #1
0
        public void Dispatch(CommandBuffer cmd, HDCamera camera, SharedRTManager sharedRTManager)
        {
            // Grab current settings
            var settings = VolumeManager.instance.stack.GetComponent <AmbientOcclusion>();

            if (!IsActive(camera, settings))
            {
                return;
            }

            using (new ProfilingSample(cmd, "Render SSAO", CustomSamplerId.RenderSSAO.GetSampler()))
            {
                // Base size
                m_Widths[0]  = camera.actualWidth;
                m_Heights[0] = camera.actualHeight;

                // L1 -> L6 sizes
                // We need to recalculate these on every frame, we can't rely on RTHandle width/height
                // values as they may have been rescaled and not the actual size we want
                for (int i = 1; i < (int)MipLevel.Count; i++)
                {
                    int div = 1 << i;
                    m_Widths[i]  = (m_Widths[0] + (div - 1)) / div;
                    m_Heights[i] = (m_Heights[0] + (div - 1)) / div;
                }

                // Grab current viewport scale factor - needed to handle RTHandle auto resizing
                var viewport = camera.viewportScale;

                // Textures used for rendering
                RTHandle depthMap, destination;
                bool     msaa = camera.frameSettings.IsEnabled(FrameSettingsField.MSAA);

                if (msaa)
                {
                    depthMap    = sharedRTManager.GetDepthValuesTexture();
                    destination = m_MultiAmbientOcclusionTex;
                }
                else
                {
                    depthMap    = sharedRTManager.GetDepthTexture();
                    destination = m_AmbientOcclusionTex;
                }

                // Render logic
                PushDownsampleCommands(cmd, camera, depthMap, msaa);

                float tanHalfFovH = CalculateTanHalfFovHeight(camera);
                PushRenderCommands(cmd, camera, viewport, m_TiledDepth1Tex, m_Occlusion1Tex, settings, GetSizeArray(MipLevel.L3), tanHalfFovH, msaa);
                PushRenderCommands(cmd, camera, viewport, m_TiledDepth2Tex, m_Occlusion2Tex, settings, GetSizeArray(MipLevel.L4), tanHalfFovH, msaa);
                PushRenderCommands(cmd, camera, viewport, m_TiledDepth3Tex, m_Occlusion3Tex, settings, GetSizeArray(MipLevel.L5), tanHalfFovH, msaa);
                PushRenderCommands(cmd, camera, viewport, m_TiledDepth4Tex, m_Occlusion4Tex, settings, GetSizeArray(MipLevel.L6), tanHalfFovH, msaa);

                PushUpsampleCommands(cmd, camera, viewport, m_LowDepth4Tex, m_Occlusion4Tex, m_LowDepth3Tex, m_Occlusion3Tex, m_Combined3Tex, settings, GetSize(MipLevel.L4), GetSize(MipLevel.L3), msaa);
                PushUpsampleCommands(cmd, camera, viewport, m_LowDepth3Tex, m_Combined3Tex, m_LowDepth2Tex, m_Occlusion2Tex, m_Combined2Tex, settings, GetSize(MipLevel.L3), GetSize(MipLevel.L2), msaa);
                PushUpsampleCommands(cmd, camera, viewport, m_LowDepth2Tex, m_Combined2Tex, m_LowDepth1Tex, m_Occlusion1Tex, m_Combined1Tex, settings, GetSize(MipLevel.L2), GetSize(MipLevel.L1), msaa);
                PushUpsampleCommands(cmd, camera, viewport, m_LowDepth1Tex, m_Combined1Tex, m_LinearDepthTex, null, destination, settings, GetSize(MipLevel.L1), GetSize(MipLevel.Original), msaa);
            }
        }
Beispiel #2
0
        public void PostDispatchWork(CommandBuffer cmd, HDCamera camera, SharedRTManager sharedRTManager)
        {
            // Grab current settings
            var settings = VolumeManager.instance.stack.GetComponent <AmbientOcclusion>();

            if (!IsActive(camera, settings))
            {
                // No AO applied - neutral is black, see the comment in the shaders
                cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, TextureXR.GetBlackTexture());
                cmd.SetGlobalVector(HDShaderIDs._AmbientOcclusionParam, Vector4.zero);
                return;
            }

            // MSAA Resolve
            if (camera.frameSettings.IsEnabled(FrameSettingsField.MSAA))
            {
                using (new ProfilingSample(cmd, "Resolve AO Buffer", CustomSamplerId.ResolveSSAO.GetSampler()))
                {
                    HDUtils.SetRenderTarget(cmd, camera, m_AmbientOcclusionTex);
                    m_ResolvePropertyBlock.SetTexture(HDShaderIDs._DepthValuesTexture, sharedRTManager.GetDepthValuesTexture());
                    m_ResolvePropertyBlock.SetTexture(HDShaderIDs._MultiAmbientOcclusionTexture, m_MultiAmbientOcclusionTex);
                    cmd.DrawProcedural(Matrix4x4.identity, m_ResolveMaterial, 0, MeshTopology.Triangles, 3, 1, m_ResolvePropertyBlock);
                }
            }

            cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, m_AmbientOcclusionTex);
            cmd.SetGlobalVector(HDShaderIDs._AmbientOcclusionParam, new Vector4(0f, 0f, 0f, settings.directLightingStrength.value));

            // TODO: All the pushdebug stuff should be centralized somewhere
            (RenderPipelineManager.currentPipeline as HDRenderPipeline).PushFullScreenDebugTexture(camera, cmd, m_AmbientOcclusionTex, FullScreenDebugMode.SSAO);
        }