Soft Shadows Shader Code Question

Hopefully I’m posting this in the correct place. The forum selection system is a bit daunting for the unfamiliar. Where would you post general questions about shader programming?

Anyway, I’m trying to implement soft shadows in my custom DX12 game engine while using (along with several others) as a guide.

One of my biggest issues is that the code assumes the shadow depth is in eye space, while mine is in clip/depth space. So while trying to determine which elements need to be rescaled, I ran into some confusion about one of the statements on the paper. In the testing section, it mentions:

First, replace the “return PCF_Filter;” line of the PCSS shader with:
return PCF_Filter( shadowMapTex, coords, 0 );
This should generate hard shadows.
Also, you can try:
return PCF_Filter( shadowMapTex, coords, 1 );
This should generate uniformly soft shadows.
If both of these tests work, you can move to Step 3.

The second test is what confuses me: return PCF_Filter( shadowMapTex, coords, 1 ) “to generate uniformly soft shadows”. Now take a look at the function itself:

float PCF_Filter( float2 uv, float zReceiver, float filterRadiusUV )
    float sum = 0.0f;
    for ( int i = 0; i < PCF_NUM_SAMPLES; ++i )
        float2 offset = poissonDisk[i] * filterRadiusUV;
        sum += tDepthMap.SampleCmpLevelZero(PCF_Sampler, uv + offset, zReceiver);
    return sum / PCF_NUM_SAMPLES;

Since the poissonDisk[] lookups have uv coordinates that range up into the 0.9+ ranges, this means that sending a value of 1.0 to this function will end up sampling the entire shadowmap depth map, doesn’t it?

If anyone could help me understand what I’m missing here, I would really appreciate it. I’m assuming my other calculations are off because of the fact that sending 1.0 to this function results in the entire system breaking down, since, in my case, the function is returning a random sampling of the entire scene for every fragment.


Hi there @xmoatz,

I got hold of one of the authors of the paper and while they were happy to hear that it still finds an audience, they highly recommend you to move on from this 15 years old shadow map filtering method.

Since then NVIDIA has introduced GPUs capable of real-time ray tracing and the quality of shadows that can be achieved with ray tracing is much better with similar performance. There is also a video explaining nicely why you should use RT for shadows. And even that is already 5 years old.