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);
            }
        }
示例#2
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);
        }