Cascaded shadow maps

Started by
1 comment, last by george7378 11 years ago
I've got basic shadow mapping working in my game right now and I'd like to sort out a few issues - the biggest being that I am trying to project the shadow of a small object onto a large terrain, which should also self-shadow. So, I need to create a cascaded shadow map (I think!)

So what's the process? Do I need to loop through each cascade and chain the view/projection matrices accordingly, all while rendering to the same map?
Advertisement

Perhaps you might not have to deal with CSM at all, and just play/tweak the SM`s projection matrix.

I am too having a large terrain where you can have a visibility of few kms, but most of the time, the camera is about 20 meters above the player (but player can zoom in/out at any time).

I came up with a very simple workaround where I can get a reasonable detail in a shadow map for both near and far objects. My SM is either 2048x2048 or 4096x4096.

At run-time, you set the near/far plane of SM based on the camera - if it is a mostly top-down camera, move the far plane as close as possible - this gives you maximum detail in view space, since with that camera you don't see very far anyway.

When the camera view changes into the distance, adjust the far plane accordingly. Now, you will loose some detail in foreground, but will gain the shadows in the distance, so it's a reasonable trade-off.

To avoid the ugly "pop" in a shadow, I just fluently lerp between Max_Far_SM_Plane and Min_Far_SM_Plane every frame. This way, you will get the fluent transition even during the camera flythroughs over waypoints, without having to set anything, fully automatically.

Considering it took me about 15 minutes to come up with this, I consider it a pretty neat and cheap trick without having to bother myself with implementation of yet another different Shadow technique smile.png

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

Hey - there are some interesting ideas there! I actually tried to make a dynamic projection matrix myself, but I don't think my problem is the same as yours. What I'm trying to do is get my object to cast a shadow on the distant terrain, while also self-shadowing and casting shadows on itself. At the moment, I can only get one or the other - i.e. I can have shadows on the terrain, but this doesn't give enough depth resolution for self shadowing, or I can bring the far plane right up to the object and it will self-shadow, but it won't cast onto the terrain if I do that:

[attachment=14962:lem3dterrainshadow.jpg]

...or...

[attachment=14963:lem3dselfshadow.jpg]

This topic is closed to new replies.

Advertisement