Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand All @@ -313,8 +314,7 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu
else
ComputeSurfaceScattering(pathIntersection, attributeData, inputSample);

// Apply the volume/surface pdf
pathIntersection.value /= pdf;
computeDirect &= !sampleVolume;

#else // HAS_LIGHTLOOP

Expand All @@ -323,9 +323,11 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu
#endif // HAS_LIGHTLOOP

// Apply volumetric attenuation
bool computeDirect = 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
Expand Down