|
|
|
|
|
|
// Perform integration over the screen-aligned plane in the view space. |
|
|
|
// TODO: it would be more accurate to use the tangent plane in the world space. |
|
|
|
|
|
|
|
int invalidSampleCount = 0; |
|
|
|
int validSampleCount = 0; |
|
|
|
|
|
|
|
[unroll] |
|
|
|
for (uint i = 1; i < SSS_N_SAMPLES_NEAR_FIELD; i++) |
|
|
|
|
|
|
if (rawDepth == 0) |
|
|
|
{ |
|
|
|
// Our sample comes from a region without any geometry. |
|
|
|
invalidSampleCount++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
// Our blur is energy-preserving, so 'sampleWeight' should be set to 0. |
|
|
|
// We do not terminate the loop since we want to gather the contribution |
|
|
|
// of the remaining samples (e.g. in case of hair covering skin). |
|
|
|
invalidSampleCount++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
totalIrradiance += sampleWeight * sampleIrradiance; |
|
|
|
totalWeight += sampleWeight; |
|
|
|
|
|
|
|
validSampleCount++; |
|
|
|
if (invalidSampleCount > SSS_N_SAMPLES_NEAR_FIELD / 2) |
|
|
|
if (validSampleCount < SSS_N_SAMPLES_NEAR_FIELD / 2) |
|
|
|
{ |
|
|
|
// Do not blur. |
|
|
|
samplePosition = posInput.unPositionSS; |
|
|
|