Sign in to follow this  
MARS_999

Shadowmapping with Large terrains

Recommended Posts

I have now moved onto rendering larger terrain sets like 1025x1025 and larger if need be. My old method only rendered 129x129 and my shadowmap would fit into it 100%. Now with the larger terrains I am running out of map it looks like... From what I can tell my units I move on the terrain when they get to the far side of the terrain the shadowmap doesn't show them anymore after maybe 1/2 way. I have my shadowmatrix near plane at 1.5 and my far 300. Do I have to move the lightposition with my camera on this large of terrain sets to allow my shadowmap to shadow what is in viewing range? Thanks

Share this post


Link to post
Share on other sites
If you're making an RTS (which i assume you are, correct me if you are not), then your best bet is to make your light projection orthographic and have it follow the camera around. You'll save a lot of resolution in the shadow map this way, as you only have to make the projection large enough to render what's currently in frame. You'll also be able to cull units that are off screen during your shadow pass. You might even want to look into PSM, as RTS games are about the only situation where PSM doesn't suck, because you can be guaranteed there are no shadow casters behind the camera.

Share this post


Link to post
Share on other sites
Quote:
Original post by cwhite
If you're making an RTS (which i assume you are, correct me if you are not), then your best bet is to make your light projection orthographic and have it follow the camera around. You'll save a lot of resolution in the shadow map this way, as you only have to make the projection large enough to render what's currently in frame. You'll also be able to cull units that are off screen during your shadow pass. You might even want to look into PSM, as RTS games are about the only situation where PSM doesn't suck, because you can be guaranteed there are no shadow casters behind the camera.


Yes I am making a RTS game. So in my shadow matrix code I should have this


glOrtho(0.0, gWidth, gHeight, 0.0, -1.0, 300.0);
//instead of this
gluPerspective(60.0f, 1.0f, 50.0f, 300.0f);



if so I am seeing nothing as far as rendering into my shadowmap... I guess I am not having it follow my camera around but I did move out towards my light position and move some models in front of it and still nothing? How should I go about following the camera around with the shadowmapping? Will I have to multiply some matrixes? Or can I just translate to the camera position? How will this affect my rendering from the lightposition? Somewhat confused on what I should be doing here.... Thanks

Share this post


Link to post
Share on other sites
*bump if anyone could steer me in the right direction or a tutorial on the camera/ortho projection that would be great... Thanks

Share this post


Link to post
Share on other sites
Well mars, I'm pretty sure what he's saying has less to do with your shadow matrix setup code and much much more to do with what you're doing with it. What he's saying (and I totally agree) is that rather than having your shadow map apply to the entire terrain, FIND OUT what parts of the terrain your camera can actualy see, and then from that, compute the correct shadow matrix so that it ONLY renders shadow for area your camera can see. Not only will this save you vertexproccessing, but it should increase your shadow map resolution. Heres pseudo code.

1. Do frustum culling to determine certain bounding boxes (that represent chunks of terrain) are actually visible to the camera

2. One way or another, calculate a shadow matrix that will cover ONLY the needed chunks of terrain

3. render the visible chunks of terrain and the units/structures in those chunks of terrain into your depth texture (the shadow map)

4. render your scene with your shadow mapping

I hope that helps, and I hope I explained it well enough, cheers
-Dan

(note, as far as i know, step 2 is very nontrivial (ie hard) but I can think of several ways where it should be possible)

Share this post


Link to post
Share on other sites
Quote:
Original post by Ademan555
Well mars, I'm pretty sure what he's saying has less to do with your shadow matrix setup code and much much more to do with what you're doing with it. What he's saying (and I totally agree) is that rather than having your shadow map apply to the entire terrain, FIND OUT what parts of the terrain your camera can actualy see, and then from that, compute the correct shadow matrix so that it ONLY renders shadow for area your camera can see. Not only will this save you vertexproccessing, but it should increase your shadow map resolution. Heres pseudo code.

1. Do frustum culling to determine certain bounding boxes (that represent chunks of terrain) are actually visible to the camera

2. One way or another, calculate a shadow matrix that will cover ONLY the needed chunks of terrain

3. render the visible chunks of terrain and the units/structures in those chunks of terrain into your depth texture (the shadow map)

4. render your scene with your shadow mapping

I hope that helps, and I hope I explained it well enough, cheers
-Dan

(note, as far as i know, step 2 is very nontrivial (ie hard) but I can think of several ways where it should be possible)



:) I get what you are saying, but not sure on the how to go about it... I am doing frustum culling on my terrain using patches of 33x33 now, but that for rendering the terrain. So I should be able to tie that in some how with my shadow mapping pass I would think... But the math behind the #2 I am lost on that one. :)

Share this post


Link to post
Share on other sites
Ademan has the gist of what I was trying to say, but I wouldn't propose trying to solve the problem exactly as he suggested. What I meant was, when you call gluLookAt, you're going to have to look at a certain point. For an RTS, that point is going to be the center of wherever the player happens to be focused at the moment. Your orthographic light should follow that point around. For example, if the user is focused on (15,17), then the point that the orthographic light looks at should be (15,17).

Share this post


Link to post
Share on other sites
Quote:
Original post by cwhite
Ademan has the gist of what I was trying to say, but I wouldn't propose trying to solve the problem exactly as he suggested. What I meant was, when you call gluLookAt, you're going to have to look at a certain point. For an RTS, that point is going to be the center of wherever the player happens to be focused at the moment. Your orthographic light should follow that point around. For example, if the user is focused on (15,17), then the point that the orthographic light looks at should be (15,17).


So I should move my lightposition for the shadowmap to the gluLookAt() view coordinates? I think I understand but still a bit cloudy... :) Thanks for the help and being patience with my lack of understanding.

Share this post


Link to post
Share on other sites
*BUMP anyone else care to help clarify what cwhite told me to do. I am not 100% sure about the math... I am thinking I have to move the lightPos for the shadow rendering to a point thats equal in terms of the absolute lightPos so the lighting and shadows look like they are at the same angle, but closer to the patches I have rendered so the scene has a complete shadowmap for all the objects on the patches that are rendered. Thanks

Share this post


Link to post
Share on other sites
Imagine that there's a flashlight positioned where the camera is at.
When the camera moves, the light moves, and the rest is dark.

i.e

lightning should never be calculated for stuff that is outside the camera view.


imagine a set of squares, and only nine of the can be visible at a time (viewport limitations etc).
so in your case, that 129x129 shadowmap should follow the camera around, and be updated when needed.

Hope it helps!

Share this post


Link to post
Share on other sites
I'm in the same position with my game (well, a while back).


In previous tries, moving the light together with the camera did not work. When an object at the other side of the light, it's shadow will move. I haven't tried that with an ortho projection yet.

I'm also looking for the solution to this problem. I haven't been able to find much information on the subject of rendering shadows for a large terrain. All demo's, examples and tutorials focus on one single object rendered, in a small scene.

I wonder if the topic started has tried the light moving tip (with an ortho projection), and can share his experiences?

Thanks :)

Share this post


Link to post
Share on other sites
Quote:
Original post by ajoling
I'm in the same position with my game (well, a while back).


In previous tries, moving the light together with the camera did not work. When an object at the other side of the light, it's shadow will move. I haven't tried that with an ortho projection yet.

I'm also looking for the solution to this problem. I haven't been able to find much information on the subject of rendering shadows for a large terrain. All demo's, examples and tutorials focus on one single object rendered, in a small scene.

I wonder if the topic started has tried the light moving tip (with an ortho projection), and can share his experiences?

Thanks :)


I haven't had time to try it, and not 100% sure on how to go about it... I wish someone would write a tutorial that way I wouldn't have to ask! :) If I can I will try it, and post the results...

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