From 88645c8d7a8fdc394fac6560fdd8230d6568865f Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Thu, 16 Apr 2020 14:22:58 +0200 Subject: [PATCH] Fixed issues with path traced SSS and accumulation. --- .../Runtime/Material/Lit/LitPathTracing.hlsl | 2 +- .../Runtime/RenderPipeline/Accumulation/SubFrameManager.cs | 4 +++- .../Runtime/RenderPipeline/PathTracing/PathTracing.cs | 1 - .../Raytracing/Shaders/RayTracingSubSurface.raytrace | 3 +-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl index 77d0b1cdd74..32358051f8f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl @@ -103,7 +103,7 @@ bool CreateMaterialData(PathIntersection pathIntersection, BuiltinData builtinDa mtlData.subsurfaceWeightFactor = subsurfaceWeight; SSS::Result subsurfaceResult; - float3 meanFreePath = -0.001 / (_ShapeParamsAndMaxScatterDists[mtlData.bsdfData.diffusionProfileIndex].rgb * _WorldScalesAndFilterRadiiAndThicknessRemaps[mtlData.bsdfData.diffusionProfileIndex].x); + float3 meanFreePath = 0.001 / (_ShapeParamsAndMaxScatterDists[mtlData.bsdfData.diffusionProfileIndex].rgb * _WorldScalesAndFilterRadiiAndThicknessRemaps[mtlData.bsdfData.diffusionProfileIndex].x); if (!SSS::RandomWalk(shadingPosition, mtlData.bsdfData.normalWS, mtlData.bsdfData.diffuseColor, meanFreePath, pathIntersection.pixelCoord, subsurfaceResult)) return false; 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 745e2c52650..12f1acbb47f 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 @@ -174,7 +174,9 @@ internal Vector4 GetFrameWeights() float weight = isRecording ? ShutterProfile(time) : 1.0f; - m_AccumulatedWeight += weight; + if (m_CurrentIteration < m_AccumulationSamples) + m_AccumulatedWeight += weight; + if (m_AccumulatedWeight > 0) { return new Vector4(weight, totalWeight, 1.0f / m_AccumulatedWeight, 0.0f); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs index d30b4c852a7..6bc0e87bfb0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs @@ -244,7 +244,6 @@ void RenderPathTracing(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputText cmd.SetGlobalTexture(HDShaderIDs._ScramblingTexture, m_Asset.renderPipelineResources.textures.scramblingTex); // Inject the ray generation data - cmd.SetGlobalFloat(HDShaderIDs._RaytracingNumSamples, m_SubFrameManager.subFrameCount); cmd.SetGlobalFloat(HDShaderIDs._RaytracingMinRecursion, m_PathTracingSettings.minimumDepth.value); cmd.SetGlobalFloat(HDShaderIDs._RaytracingMaxRecursion, m_PathTracingSettings.maximumDepth.value); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingSubSurface.raytrace b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingSubSurface.raytrace index ee418bafeb1..ac00a2ca669 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingSubSurface.raytrace +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingSubSurface.raytrace @@ -76,8 +76,7 @@ void RayGenSubSurface() DECODE_FROM_SSSBUFFER(posInput.positionSS, sssData); float3 shapeParam = _ShapeParamsAndMaxScatterDists[sssData.diffusionProfileIndex].rgb * _WorldScalesAndFilterRadiiAndThicknessRemaps[sssData.diffusionProfileIndex].x; - // Deduce our scattering distance - // For some reason the value in shapeParam is negative, convert it to milimeters while we are there. + // Deduce our scattering distance (converted to mm) float3 scatteringDistance = 1.0 / shapeParam * 0.001; // Define which sample in the sequence we are up to.