Hi,
I'm trying to switch from my basic shadow mapping to CSM so I can have decent quality shadows covering my terrain.
I think I understand the concept after lots of reading but I'm struggling with the specifics.
How am I meant to be writing the values to the depth buffer? Currently for my simple shadow mapping I'm just writing out z/w (z position comes from position multiplied by WorldViewProj).
Now from the example code I'm reading the cascades are partitioned from 0-1 depth using slides like 0-0.2 then 0.2-0.5 then 0.5-1 or similar. Now when I check my depth buffer in final rendering and do something like:
if (depth > 0.5f)
OutputColor.g += 0.5;
else
OutputColor.r += 0.5;
I'd expect everything to be tinted red near the camera and tinted green about halfway from the camera to the far clip plane.
Unfortunately its just all green. It seems I have to do depth > 0.92 or so before it makes any difference.
Any ideas what I'm doing wrong?
Update: I found my nearclip was too close (0.1f) after reading a good article about depth buffers. Moving it a little further away to 5 made me at least be able to use 0.9-1 in fairly sensible chunks.
If I just use my depth buffer is it is not I can divide it to 0-0.9 for the cascade near the player, 0.9-0.95 is the mid-distance/medium quality cascade and 0.95-1 is the low quality cascade for everything further away than that.
Is there some reason I can't do CSM like that? Do I have to use linear depths?
Here's a screen shot of my "cascades"