Hello, I'm trying to impl PCSS into my OpenGL project, following these 2 PDFs, https://developer.download.nvidia.com/shaderlibrary/docs/shadow_PCSS.pdf
https://developer.download.nvidia.com/whitepapers/2008/PCSS_Integration.pdf.
Howerver, my result is quite ugly and I have some question about implement pcss with CSM.
my code is as follow :
// blocker search
float avgBlockerDepth = 0;
float numBlockers = 0;
//currentDepth = projCoord.z
float receiver = currentDepth - normalBias - _depthBias;
float nearPlane = _nearPlane;
//_lightWidthUv was calculated on cpu => lightSize / frustumWidth.
float lightWidthUv = _lightWidthUv;
FindBlocker( avgBlockerDepth, numBlockers, projCoords.xy, lightWidthUv, receiver, nearPlane, layer);
if( numBlockers < 1 )
return 0.0f;
float penumbraRatio = lightWidthUv * (receiver - avgBlockerDepth) / avgBlockerDepth;
float filterRadius = penumbraRatio * nearPlane / receiver;
float shadow = 0.0;
shadow = PCF_Filter(projCoords.xy, receiver, filterRadius, layer);
return shadow;
and this is the FindBlocker function
void FindBlocker(out float avgBlockerDepth, out float numBlockers, vec2 uv, float lightWidthUV, float zReceiver, float nearPlane, int layer)
{
float searchWidth = lightWidthUV * (zReceiver - nearPlane) / zReceiver;
float blockerSum = 0;
numBlockers = 0;
vec2 texelSize = 1.0 / vec2(textureSize(_shadowMap, 0));
for( int i = 0; i < BLOCKER_SEARCH_NUM_SAMPLES; ++i )
{
vec2 offset = POISSON16[i] * searchWidth;
float shadowMapDepth = texture(_shadowMap, vec3(uv + offset * texelSize, layer)).r;
if ( shadowMapDepth < zReceiver ) {
blockerSum += shadowMapDepth;
numBlockers++;
}
}
avgBlockerDepth = blockerSum / numBlockers;
}
.