Arthur Monteiro
Arthur Monteiro

Reputation: 319

How to make soft shadows with cascaded shadow mapping?

I'm trying to implement soft shadows using cascaded shadow mapping.

For this test, I use PCF :

for(int i = 0; i < 16; i++)
{
    int index = int(16.0*random(worldPos.xyz, i))%16;
    shadow += 1.0 - textureProj(projCoords + vec4(poissonDisk[index] / divisor, 0.0, 0.0), cascadeIndex);
}
shadow /= 16.0;

The problem is that I'm using cascaded shadow mapping, that seems that the size of an object in the shadow map is not the same between different directions of the camera.

Here an example (the quad on the bottom right draw the shadow map of the first cascade) :

correctWidth
(source: noelshack.com)

smallWidth
(source: noelshack.com)

As you can see in the second image, the pike width in the shadow map is smaller than on the first image.

Because PCF read the front texels of the shadow map regardless of the orientation of the camera, the pike appear smaller then more transparent.

In a lot of soft-shadow algorithm I read on the internet I see that they consist of reading some front texels of the shadow map.

My question is : are these algorithm incompatible with cascaded shadow mapping or is there a way to fix this ?

Upvotes: 0

Views: 453

Answers (1)

Kyy13
Kyy13

Reputation: 315

It seems that you are using a best-fit approach for your orthographic projection. If the orthographic projection from the sun is best-fit to sections of your cameras viewing frustum, then the orientation of the camera will change the cross-sectional area of the sun's frustum.

The solution is to fit the sun's orthographic frustums to spheres that encloses each section of your cameras frustum... this ensures that the area enclosed by your orthographic projection is the same regardless of the orientation of your camera.

Upvotes: 1

Related Questions