Skip to content

Commit

Permalink
[HDRP][Path Tracing] Minor fix for SSS when combined with fog (#6215)
Browse files Browse the repository at this point in the history
* Minor fix for SSS + fog.

* Comments.
  • Loading branch information
eturquin authored Nov 5, 2021
1 parent 0d37210 commit 385218f
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ void ComputeSurfaceScattering(inout PathIntersection pathIntersection : SV_RayPa

pathIntersection.value = computeDirect ? bsdfData.color * GetInverseCurrentExposureMultiplier() + builtinData.emissiveColor : 0.0;

// Apply shadow matte if requested
#ifdef _ENABLE_SHADOW_MATTE
// Apply shadow matte if requested
#ifdef _ENABLE_SHADOW_MATTE
float3 shadowColor = lerp(pathIntersection.value, surfaceData.shadowTint.rgb * GetInverseCurrentExposureMultiplier(), surfaceData.shadowTint.a);
float visibility = ComputeVisibility(fragInput.positionRWS, surfaceData.normalWS, inputSample.xyz);
pathIntersection.value = lerp(shadowColor, pathIntersection.value, visibility);
#endif
#endif

// Simulate opacity blending by simply continuing along the current ray
#ifdef _SURFACE_TYPE_TRANSPARENT
// Simulate opacity blending by simply continuing along the current ray
#ifdef _SURFACE_TYPE_TRANSPARENT
if (builtinData.opacity < 1.0)
{
RayDesc rayDescriptor;
Expand All @@ -273,7 +273,7 @@ void ComputeSurfaceScattering(inout PathIntersection pathIntersection : SV_RayPa

pathIntersection.value = lerp(nextPathIntersection.value, pathIntersection.value, builtinData.opacity);
}
#endif
#endif

#endif // SHADER_UNLIT
}
Expand Down Expand Up @@ -306,6 +306,7 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu
float3 lightPosition;
bool sampleLocalLights, sampleVolume = false;

// Skip this code if getting out of a SSS random walk (currentDepth < 0)
if (currentDepth >= 0)
{
// Generate a 4D unit-square sample for this depth, from our QMC sequence
Expand All @@ -329,25 +330,29 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu

#endif // HAS_LIGHTLOOP

// Apply volumetric attenuation
ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), pathIntersection.t, pathIntersection.value, computeDirect);
// Skip this code if getting out of a SSS random walk (currentDepth < 0)
if (currentDepth >= 0)
{
// Apply volumetric attenuation
ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), pathIntersection.t, pathIntersection.value, computeDirect);

// Apply the volume/surface pdf
pathIntersection.value /= pdf;
// Apply the volume/surface pdf
pathIntersection.value /= pdf;

if (currentDepth)
{
// Bias the result (making it too dark), but reduces fireflies a lot
float intensity = Luminance(pathIntersection.value) * GetCurrentExposureMultiplier();
if (intensity > _RaytracingIntensityClamp)
pathIntersection.value *= _RaytracingIntensityClamp / intensity;
if (currentDepth)
{
// Bias the result (making it too dark), but reduces fireflies a lot
float intensity = Luminance(pathIntersection.value) * GetCurrentExposureMultiplier();
if (intensity > _RaytracingIntensityClamp)
pathIntersection.value *= _RaytracingIntensityClamp / intensity;
}
}
}

[shader("anyhit")]
void AnyHit(inout PathIntersection pathIntersection : SV_RayPayload, AttributeData attributeData : SV_IntersectionAttributes)
{
// The first thing that we should do is grab the intersection vertice
// The first thing that we should do is grab the intersection vertex
IntersectionVertex currentVertex;
GetCurrentIntersectionVertex(attributeData, currentVertex);

Expand Down

0 comments on commit 385218f

Please sign in to comment.