示例#1
0
        // Function that evaluates the history validation Buffer
        static public void ExecuteHistoryValidity(CommandBuffer cmd, HistoryValidityParameters parameters, HistoryValidityResources resources)
        {
            // If we do not have a depth and normal history buffers, we can skip right away
            if (resources.historyDepthTexture == null || resources.historyNormalTexture == null)
            {
                CoreUtils.SetRenderTarget(cmd, resources.validationBuffer, clearFlag: ClearFlag.Color, Color.black);
                return;
            }

            // Evaluate the dispatch parameters
            int areaTileSize = 8;
            int numTilesX    = (parameters.texWidth + (areaTileSize - 1)) / areaTileSize;
            int numTilesY    = (parameters.texHeight + (areaTileSize - 1)) / areaTileSize;

            // First of all we need to validate the history to know where we can or cannot use the history signal
            // Bind the input buffers
            cmd.SetComputeTextureParam(parameters.temporalFilterCS, parameters.validateHistoryKernel, HDShaderIDs._DepthTexture, resources.depthStencilBuffer);
            cmd.SetComputeTextureParam(parameters.temporalFilterCS, parameters.validateHistoryKernel, HDShaderIDs._HistoryDepthTexture, resources.historyDepthTexture);
            cmd.SetComputeTextureParam(parameters.temporalFilterCS, parameters.validateHistoryKernel, HDShaderIDs._NormalBufferTexture, resources.normalBuffer);
            cmd.SetComputeTextureParam(parameters.temporalFilterCS, parameters.validateHistoryKernel, HDShaderIDs._HistoryNormalTexture, resources.historyNormalTexture);
            cmd.SetComputeTextureParam(parameters.temporalFilterCS, parameters.validateHistoryKernel, HDShaderIDs._CameraMotionVectorsTexture, resources.motionVectorBuffer);
            cmd.SetComputeTextureParam(parameters.temporalFilterCS, parameters.validateHistoryKernel, HDShaderIDs._StencilTexture, resources.depthStencilBuffer, 0, RenderTextureSubElement.Stencil);

            // Bind the constants
            cmd.SetComputeFloatParam(parameters.temporalFilterCS, HDShaderIDs._HistoryValidity, parameters.historyValidity);
            cmd.SetComputeFloatParam(parameters.temporalFilterCS, HDShaderIDs._PixelSpreadAngleTangent, parameters.pixelSpreadTangent);
            cmd.SetComputeIntParam(parameters.temporalFilterCS, HDShaderIDs._ObjectMotionStencilBit, (int)StencilUsage.ObjectMotionVector);

            // Bind the output buffer
            cmd.SetComputeTextureParam(parameters.temporalFilterCS, parameters.validateHistoryKernel, HDShaderIDs._ValidationBufferRW, resources.validationBuffer);

            // Evaluate the validity
            cmd.DispatchCompute(parameters.temporalFilterCS, parameters.validateHistoryKernel, numTilesX, numTilesY, parameters.viewCount);
        }
        internal TextureHandle EvaluateHistoryValidationBuffer(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectorsBuffer)
        {
            // Grab the temporal filter
            HDTemporalFilter temporalFilter = GetTemporalFilter();

            // If the temporal filter is valid use it, otherwise return a white texture
            if (temporalFilter != null)
            {
                float historyValidity = EvaluateHistoryValidity(hdCamera);
                HistoryValidityParameters parameters = temporalFilter.PrepareHistoryValidityParameters(hdCamera, historyValidity);
                return(temporalFilter.HistoryValidity(renderGraph, hdCamera, parameters, depthBuffer, normalBuffer, motionVectorsBuffer));
            }
            else
            {
                return(renderGraph.defaultResources.whiteTexture);
            }
        }
示例#3
0
        public HistoryValidityParameters PrepareHistoryValidityParameters(HDCamera hdCamera, float historyValidity)
        {
            HistoryValidityParameters parameters = new HistoryValidityParameters();

            // Camera parameters
            parameters.texWidth  = hdCamera.actualWidth;
            parameters.texHeight = hdCamera.actualHeight;
            parameters.viewCount = hdCamera.viewCount;

            // Denoising parameters
            parameters.pixelSpreadTangent = HDRenderPipeline.GetPixelSpreadTangent(hdCamera.camera.fieldOfView, hdCamera.actualWidth, hdCamera.actualHeight);
            parameters.historyValidity    = historyValidity;

            // Kernels
            parameters.validateHistoryKernel = m_ValidateHistoryKernel;

            // Other parameters
            parameters.temporalFilterCS = m_TemporalFilterCS;

            return(parameters);
        }
        public TextureHandle HistoryValidity(RenderGraph renderGraph, HDCamera hdCamera, HistoryValidityParameters parameters,
                                             TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectorBuffer)
        {
            using (var builder = renderGraph.AddRenderPass <HistoryValidityPassData>("History Validity Evaluation", out var passData, ProfilingSampler.Get(HDProfileId.HistoryValidity)))
            {
                // Cannot run in async
                builder.EnableAsyncCompute(false);

                // Fetch all the resources
                passData.parameters = parameters;
                // Input Buffers
                passData.depthStencilBuffer = builder.ReadTexture(depthBuffer);
                passData.normalBuffer       = builder.ReadTexture(normalBuffer);
                passData.motionVectorBuffer = builder.ReadTexture(motionVectorBuffer);

                // History buffers
                passData.historyDepthTexture  = builder.ReadTexture(renderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth)));
                passData.historyNormalTexture = builder.ReadTexture(renderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Normal)));

                // Output buffers
                passData.validationBuffer = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true)
                {
                    colorFormat = GraphicsFormat.R8_UNorm, enableRandomWrite = true, name = "ValidationTexture"
                }));

                builder.SetRenderFunc(
                    (HistoryValidityPassData data, RenderGraphContext ctx) =>
                {
                    HistoryValidityResources resources = new HistoryValidityResources();
                    resources.depthStencilBuffer       = data.depthStencilBuffer;
                    resources.normalBuffer             = data.normalBuffer;
                    resources.motionVectorBuffer       = data.motionVectorBuffer;
                    resources.historyDepthTexture      = data.historyDepthTexture;
                    resources.historyNormalTexture     = data.historyNormalTexture;
                    resources.validationBuffer         = data.validationBuffer;
                    ExecuteHistoryValidity(ctx.cmd, data.parameters, resources);
                });
                return(passData.validationBuffer);
            }
        }