Sign in to follow this  
whyamibrad

How do I get a shadow map to follow viewer's camera?

Recommended Posts

whyamibrad    122
I am implementing shadow mapping for a school project and I am having trouble positioning my shadow map so that I get the most "coverage" inside the camera's view frustum. I am using a single directional light for my outdoor scene and was wondering if anyone has any ideas on where to position the camera (the camera from the light's POV, not the scene's camera) when rendering to the shadow map. The goal is that when the player moves about the scene, the shadow map will follow the viewer's camera, ensuring that nothing inside the viewer's frustum gets clipped out of the shadow map render. I have read that you can use multiple shadow maps placed side to side to cover large areas, but I would prefer to use one strategically placed shadow map to make sure I catch all the occluders. The image below illistrates my problem: I can aim the shadow map towards the center of my view frustum, but when camera is oriented like this, the top of the pink object is clipped from the shadow map render and therefore does not cast a complete shadow (the rectangle with round edges represents what the user sees). Any ideas? Photobucket - Video and Image Hosting

Share this post


Link to post
Share on other sites
wolf    852
There are several ways to do this. Here is a simplified view on it:
1. check the dimensions of your view frustum in a certain distance ... let's say in 1m and in 10m
2. Get the four values that enclose the view frustum there
3. Build a quad around those values and construct a light view frustum from the point of view of the light source by using the extrema of those points ...

So I think the key to succeed here is to find a way on how to get the four starting values and then come up with a way to construct a frustum. You should find some documentation on how to construct the light view frustum on the web ...
Another catch is, that you have to go back and forth probably between light view space and world space :-).

To catch everything you want, you might have some overlap on the right and left side ... so just construct the light frustum a little bit bigger.

Hope this helps,
- Wolfgang

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