diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index a7860990fc4..7216985f991 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -120,6 +120,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed the Ray-Tracing related Debug Display not working in render graph mode. - Fix nan in pbr sky - Fixed Light skin not properly applied on the LookDev when switching from Dark Skin (case 1278802) +- Fixed accumulation on DX11 ### Changed - Preparation pass for RTSSShadows to be supported by render graph. diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Accumulation.md b/com.unity.render-pipelines.high-definition/Documentation~/Accumulation.md index b0c50801f05..953427d9968 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Accumulation.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Accumulation.md @@ -69,7 +69,7 @@ public class FrameManager : MonoBehaviour { RenderPipelineManager.beginFrameRendering -= PrepareSubFrameCallBack; HDRenderPipeline renderPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline; - renderPipeline.EndRecording(); + renderPipeline?.EndRecording(); m_Recording = false; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/Shaders/Accumulation.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/Shaders/Accumulation.compute index 9f5ca00ba16..2b9c8159d3f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/Shaders/Accumulation.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/Shaders/Accumulation.compute @@ -4,8 +4,13 @@ #pragma kernel KMain +#pragma multi_compile _ INPUT_FROM_RADIANCE_TEXTURE + // Inputs +#ifdef INPUT_FROM_RADIANCE_TEXTURE TEXTURE2D_X(_RadianceTexture); +#endif + float4 _AccumulationWeights; int _AccumulationNeedsExposure; uint _AccumulationFrameIndex; @@ -55,8 +60,12 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID) _CameraColorTextureRW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)].xyz * exposureMultiplier, 1.0); } else - { + { +#ifdef INPUT_FROM_RADIANCE_TEXTURE float4 color = _RadianceTexture[COORD_TEXTURE2D_X(dispatchThreadId.xy)]; +#else + float4 color = _CameraColorTextureRW[COORD_TEXTURE2D_X(dispatchThreadId.xy)]; +#endif if (sampleCount++) color.xyz = (_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)].xyz * _AccumulationWeights.y + _AccumulationWeights.x * color.xyz) * _AccumulationWeights.z; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs index 77a31cadace..640f179af0b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs @@ -291,7 +291,7 @@ struct RenderAccumulationParameters public HDCamera hdCamera; } - RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCamera, bool needExposure) + RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCamera, bool needExposure, bool inputFromRadianceTexture) { var parameters = new RenderAccumulationParameters(); @@ -301,6 +301,11 @@ RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCame parameters.needExposure = needExposure; parameters.hdCamera = hdCamera; + parameters.accumulationCS.shaderKeywords = null; + if (inputFromRadianceTexture) + { + parameters.accumulationCS.EnableKeyword("INPUT_FROM_RADIANCE_TEXTURE"); + } return parameters; } @@ -310,7 +315,8 @@ void RenderAccumulation(HDCamera hdCamera, RTHandle inputTexture, RTHandle outpu RTHandle history = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.PathTracing) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.PathTracing, PathTracingHistoryBufferAllocatorFunction, 1); - var parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure); + bool inputFromRadianceTexture = !inputTexture.Equals(outputTexture); + var parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure, inputFromRadianceTexture); RenderAccumulation(parameters, inputTexture, outputTexture, history, cmd); } @@ -332,7 +338,10 @@ static void RenderAccumulation(in RenderAccumulationParameters parameters, RTHan cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNumSamples, (int)parameters.subFrameManager.subFrameCount); cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._AccumulatedFrameTexture, historyTexture); cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._CameraColorTextureRW, outputTexture); - cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture); + if (!inputTexture.Equals(outputTexture)) + { + cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture); + } cmd.SetComputeVectorParam(accumulationShader, HDShaderIDs._AccumulationWeights, frameWeights); cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNeedsExposure, parameters.needExposure ? 1 : 0); cmd.DispatchCompute(accumulationShader, parameters.accumulationKernel, (parameters.hdCamera.actualWidth + 7) / 8, (parameters.hdCamera.actualHeight + 7) / 8, parameters.hdCamera.viewCount); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs index 2274edbbcb4..f5ede395e99 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs @@ -1383,7 +1383,8 @@ void RenderAccumulation(RenderGraph renderGraph, HDCamera hdCamera, TextureHandl TextureHandle history = renderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.PathTracing) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.PathTracing, PathTracingHistoryBufferAllocatorFunction, 1)); - passData.parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure); + bool inputFromRadianceTexture = !inputTexture.Equals(outputTexture); + passData.parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure, inputFromRadianceTexture); passData.input = builder.ReadTexture(inputTexture); passData.output = builder.WriteTexture(outputTexture); passData.history = builder.WriteTexture(history);