From 25954d8fe720b8313b2faeacef781ec9ce6789fa Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Fri, 24 Sep 2021 15:59:04 +0200 Subject: [PATCH 1/2] Do not use volume color on non-surface scattering. --- .../RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl index 8504ae40bfb..2c38cf99d3c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl @@ -313,9 +313,6 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu else ComputeSurfaceScattering(pathIntersection, attributeData, inputSample); - // Apply the volume/surface pdf - pathIntersection.value /= pdf; - #else // HAS_LIGHTLOOP ComputeSurfaceScattering(pathIntersection, attributeData, inputSample); @@ -323,9 +320,12 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu #endif // HAS_LIGHTLOOP // Apply volumetric attenuation - bool computeDirect = currentDepth >= _RaytracingMinRecursion - 1; + bool computeDirect = !sampleVolume && (currentDepth >= _RaytracingMinRecursion - 1); ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), pathIntersection.t, pathIntersection.value, computeDirect); + // Apply the volume/surface pdf + pathIntersection.value /= pdf; + if (currentDepth) { // Bias the result (making it too dark), but reduces fireflies a lot From 52f245e521197d61a362935f44db914a31f68dba Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Fri, 24 Sep 2021 16:26:08 +0200 Subject: [PATCH 2/2] ... --- .../RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl index 2c38cf99d3c..1f34b464bb1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl @@ -289,13 +289,14 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu // Grab depth information int currentDepth = _RaytracingMaxRecursion - pathIntersection.remainingDepth; + bool computeDirect = currentDepth >= _RaytracingMinRecursion - 1; float4 inputSample = 0.0; + float pdf = 1.0; #ifdef HAS_LIGHTLOOP float3 lightPosition; - float pdf = 1.0; bool sampleLocalLights, sampleVolume = false; if (currentDepth >= 0) @@ -304,7 +305,7 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu inputSample = GetSample4D(pathIntersection.pixelCoord, _RaytracingSampleIndex, 4 * currentDepth); // For the time being, we test for volumetric scattering only on camera rays - if (!currentDepth) + if (!currentDepth && computeDirect) sampleVolume = SampleVolumeScatteringPosition(pathIntersection.pixelCoord, inputSample.w, pathIntersection.t, pdf, sampleLocalLights, lightPosition); } @@ -313,6 +314,8 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu else ComputeSurfaceScattering(pathIntersection, attributeData, inputSample); + computeDirect &= !sampleVolume; + #else // HAS_LIGHTLOOP ComputeSurfaceScattering(pathIntersection, attributeData, inputSample); @@ -320,7 +323,6 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu #endif // HAS_LIGHTLOOP // Apply volumetric attenuation - bool computeDirect = !sampleVolume && (currentDepth >= _RaytracingMinRecursion - 1); ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), pathIntersection.t, pathIntersection.value, computeDirect); // Apply the volume/surface pdf