@@ -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