Ejemplo n.º 1
0
            public void WriteResources(RenderGraphBuilder builder)
            {
                source        = builder.WriteTexture(source);
                output        = builder.WriteTexture(output);
                depth         = builder.WriteTexture(depth);
                motionVectors = builder.WriteTexture(motionVectors);

                if (biasColorMask.IsValid())
                {
                    biasColorMask = builder.WriteTexture(biasColorMask);
                }
            }
Ejemplo n.º 2
0
        void RenderAccumulation(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle inputTexture, TextureHandle outputTexture, HDCameraFrameHistoryType historyType, Vector4 frameWeights, bool needExposure)
        {
            using (var builder = renderGraph.AddRenderPass <RenderAccumulationPassData>("Render Accumulation", out var passData))
            {
                bool useInputTexture = !inputTexture.Equals(outputTexture);
                passData.accumulationCS     = m_Asset.renderPipelineResources.shaders.accumulationCS;
                passData.accumulationKernel = passData.accumulationCS.FindKernel("KMain");
                passData.subFrameManager    = m_SubFrameManager;
                passData.needExposure       = needExposure;
                passData.hdCamera           = hdCamera;
                passData.inputKeyword       = new LocalKeyword(passData.accumulationCS, "INPUT_FROM_FRAME_TEXTURE");
                passData.outputKeyword      = new LocalKeyword(passData.accumulationCS, "WRITE_TO_OUTPUT_TEXTURE");
                passData.frameWeights       = frameWeights;

                TextureHandle history = renderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)historyType)
                                                                  ?? hdCamera.AllocHistoryFrameRT((int)historyType, PathTracingHistoryBufferAllocatorFunction, 1));

                passData.input            = builder.ReadTexture(inputTexture);
                passData.history          = builder.ReadWriteTexture(history);
                passData.useOutputTexture = outputTexture.IsValid();
                passData.useInputTexture  = useInputTexture;

                if (outputTexture.IsValid())
                {
                    passData.output = builder.ReadWriteTexture(outputTexture);
                }

                builder.SetRenderFunc(
                    (RenderAccumulationPassData data, RenderGraphContext ctx) =>
                {
                    ComputeShader accumulationShader = data.accumulationCS;

                    // Check the validity of the state before moving on with the computation
                    if (!accumulationShader)
                    {
                        return;
                    }

                    accumulationShader.shaderKeywords = null;
                    if (data.useInputTexture)
                    {
                        ctx.cmd.EnableKeyword(accumulationShader, passData.inputKeyword);
                    }
                    else
                    {
                        ctx.cmd.DisableKeyword(accumulationShader, passData.inputKeyword);
                    }

                    if (data.useOutputTexture)
                    {
                        ctx.cmd.EnableKeyword(accumulationShader, passData.outputKeyword);
                    }
                    else
                    {
                        ctx.cmd.DisableKeyword(accumulationShader, passData.outputKeyword);
                    }

                    // Get the per-camera data
                    int camID          = data.hdCamera.camera.GetInstanceID();
                    CameraData camData = data.subFrameManager.GetCameraData(camID);

                    // Accumulate the path tracing results
                    ctx.cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationFrameIndex, (int)camData.currentIteration);
                    ctx.cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNumSamples, (int)data.subFrameManager.subFrameCount);
                    ctx.cmd.SetComputeTextureParam(accumulationShader, data.accumulationKernel, HDShaderIDs._AccumulatedFrameTexture, data.history);

                    if (data.useOutputTexture)
                    {
                        ctx.cmd.SetComputeTextureParam(accumulationShader, data.accumulationKernel, HDShaderIDs._CameraColorTextureRW, data.output);
                    }

                    if (data.useInputTexture)
                    {
                        ctx.cmd.SetComputeTextureParam(accumulationShader, data.accumulationKernel, HDShaderIDs._FrameTexture, data.input);
                    }

                    ctx.cmd.SetComputeVectorParam(accumulationShader, HDShaderIDs._AccumulationWeights, data.frameWeights);
                    ctx.cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNeedsExposure, data.needExposure ? 1 : 0);
                    ctx.cmd.DispatchCompute(accumulationShader, data.accumulationKernel, (data.hdCamera.actualWidth + 7) / 8, (data.hdCamera.actualHeight + 7) / 8, data.hdCamera.viewCount);

                    // Increment the iteration counter, if we haven't converged yet
                    if (data.useOutputTexture && camData.currentIteration < data.subFrameManager.subFrameCount)
                    {
                        camData.currentIteration++;
                        data.subFrameManager.SetCameraData(camID, camData);
                    }
                });
            }
        }