Sign in to follow this  
jeffkingdev

Cascade Shadow Map Pixel Shader

Recommended Posts

jeffkingdev    787
Hello,

So, I have CSM working. Looks great. In order for it to work properly, I need to figure out the cascade index in the pixel shader and then do the multiply with it's 1 of 4 matrices (one for each map) again in the pixel shader. I'd rather do this in the vertex shader, but then I get shadows with lines across it (shadow, no shadow, shadow, no shadow, etc.).

Is this possible to do in the vertex shader? If so, any ideas how?

Maybe I can't do this because of the nature of the shadow, it really does need to be a pixel operation. It just sucks I have to pass all 4 matrices into my pixel shader for the operation.

Thanks
Jeff.

Share this post


Link to post
Share on other sites
AliasBinman    855
You cannot generally do it in the VS because a triangle can cross over cascade boundaries. If you can guarantee that it doesn't (using frustum checks on the CPU) then you can do it on the VS.

Typically for orthographic projected cascades you only need to do a single vector by matrix transform. Each cascade can then be done via a bias and scale operation which is a single MAD operation per cascade check.

Share this post


Link to post
Share on other sites
MJP    19754
To elaborate more on what Alias said...all of your cascades are going to use the same light direction, which means that the bounding boxes formed by the projection for each cascade will all be aligned to the same axes. With that in mind you can transform from the coordinate space of one cascade to the coordinate space of another cascade by figuring out how much to translate, and how much to scale. Ultimately it should be just a just a bit of math in shader, and it shouldn't even be a blip in terms of performance on GPU that's not more than 5 years old.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this