Skip to content

Commit cc7c135

Browse files
authored
Hdrp/pt pass no bsdf data (#710)
* Removed direct use of BSDFData in path tracing pass. * Updated changelog. * Fixed float3 typo...
1 parent 74cc8b1 commit cc7c135

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
774774
- Refactored shadow caching system.
775775
- Removed experimental namespace for ray tracing code.
776776
- Increase limit for max numbers of lights in UX
777+
- Removed direct use of BSDFData in the path tracing pass, delegated to the material instead.
777778

778779
## [7.1.1] - 2019-09-05
779780

com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,34 @@ void EvaluateMaterial(MaterialData mtlData, float3 sampleDir, out MaterialResult
336336
#endif
337337
}
338338
}
339+
340+
float AdjustPathRoughness(MaterialData mtlData, MaterialResult mtlResult, bool isSampleBelow, float pathRoughness)
341+
{
342+
// Adjust the max roughness, based on the estimated diff/spec ratio
343+
float adjustedPathRoughness = (mtlResult.specPdf * max(mtlData.bsdfData.roughnessT, mtlData.bsdfData.roughnessB) + mtlResult.diffPdf) / (mtlResult.diffPdf + mtlResult.specPdf);
344+
345+
#ifdef _SURFACE_TYPE_TRANSPARENT
346+
// When transmitting with an IOR close to 1.0, roughness is barely noticeable -> take that into account for path roughness adjustment
347+
if (IsBelow(mtlData) != isSampleBelow)
348+
adjustedPathRoughness = lerp(pathRoughness, adjustedPathRoughness, smoothstep(1.0, 1.3, mtlData.bsdfData.ior));
349+
#endif
350+
351+
return adjustedPathRoughness;
352+
}
353+
354+
float3 ApplyAbsorption(MaterialData mtlData, float dist, bool isSampleBelow, float3 value)
355+
{
356+
#if defined(_SURFACE_TYPE_TRANSPARENT) && HAS_REFRACTION
357+
// Apply absorption on rays below the interface, using Beer-Lambert's law
358+
if (isSampleBelow)
359+
{
360+
#ifdef _REFRACTION_THIN
361+
value *= exp(-mtlData.bsdfData.absorptionCoefficient * REFRACTION_THIN_DISTANCE);
362+
#else
363+
value *= exp(-mtlData.bsdfData.absorptionCoefficient * dist);
364+
#endif
365+
}
366+
#endif
367+
368+
return value;
369+
}

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,12 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu
176176
nextPathIntersection.remainingDepth = pathIntersection.remainingDepth - 1;
177177
nextPathIntersection.t = rayDescriptor.TMax;
178178

179-
// Adjust the max roughness, based on the estimated diff/spec ratio
180-
nextPathIntersection.maxRoughness = (mtlResult.specPdf * max(mtlData.bsdfData.roughnessT, mtlData.bsdfData.roughnessB) + mtlResult.diffPdf) / pdf;
179+
// Adjust the path max roughness (used for roughness clamping, to reduce fireflies)
180+
nextPathIntersection.maxRoughness = AdjustPathRoughness(mtlData, mtlResult, isSampleBelow, pathIntersection.maxRoughness);
181181

182182
// In order to achieve filtering for the textures, we need to compute the spread angle of the pixel
183183
nextPathIntersection.cone.spreadAngle = pathIntersection.cone.spreadAngle + roughnessToSpreadAngle(nextPathIntersection.maxRoughness);
184184

185-
#ifdef _SURFACE_TYPE_TRANSPARENT
186-
// When transmitting with an IOR close to 1.0, roughness is barely noticeable -> take that into account for roughness clamping
187-
if (IsBelow(mtlData) != isSampleBelow)
188-
nextPathIntersection.maxRoughness = lerp(pathIntersection.maxRoughness, nextPathIntersection.maxRoughness, smoothstep(1.0, 1.3, mtlData.bsdfData.ior));
189-
#endif
190-
191185
// Shoot ray for indirect lighting
192186
TraceRay(_RaytracingAccelerationStructure, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, RAYTRACINGRENDERERFLAG_PATH_TRACING, 0, 1, 2, rayDescriptor, nextPathIntersection);
193187

@@ -203,19 +197,9 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu
203197
nextPathIntersection.value += lightValue * misWeight;
204198
}
205199

206-
#if defined(_SURFACE_TYPE_TRANSPARENT) && HAS_REFRACTION
207-
// Apply absorption on rays below the interface, using Beer-Lambert's law
208-
if (isSampleBelow)
209-
{
210-
#ifdef _REFRACTION_THIN
211-
nextPathIntersection.value *= exp(-mtlData.bsdfData.absorptionCoefficient * REFRACTION_THIN_DISTANCE);
212-
#else
213-
// FIXME: maxDist might need some more tweaking
214-
float maxDist = surfaceData.atDistance * 10.0;
215-
nextPathIntersection.value *= exp(-mtlData.bsdfData.absorptionCoefficient * min(nextPathIntersection.t, maxDist));
216-
#endif
217-
}
218-
#endif
200+
// Apply material absorption
201+
float dist = min(nextPathIntersection.t, surfaceData.atDistance * 10.0);
202+
nextPathIntersection.value = ApplyAbsorption(mtlData, dist, isSampleBelow, nextPathIntersection.value);
219203

220204
pathIntersection.value += value * rrFactor * nextPathIntersection.value;
221205
}

0 commit comments

Comments
 (0)