Shadowmapping with Large terrains

Started by
10 comments, last by MARS_999 17 years, 11 months ago
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
Advertisement
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.
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 thisgluPerspective(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
*bump if anyone could steer me in the right direction or a tutorial on the camera/ortho projection that would be great... Thanks
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)
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
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. :)
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).
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.
*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
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!
"Game Maker For Life, probably never professional thou." =)

This topic is closed to new replies.

Advertisement