PDA

View Full Version : shadow mapping problem on large terrain



casper sky
11-10-2009, 01:43 AM
hello,
i have two problems with my shadow mapping technique implemented on a large terrain :
an image can be found here :
http://www.flickr.com/photos/44541011@N06/4092454962/

the first problem :

as u can see the top of the montain is not shadowed correctly? how can i eliminate this ?

the second question is:

i tried to setup the light to look always at the viewer position like this :
gluLookAt((float)light_pos.X,(float)light_pos.Y,(f loat)light_pos.Z,CameraPOS.X,CameraPOS.Y,CameraPOS .Z,0,0,1);

and i setup an ortho projection for the light projejection
glOrtho(-bb.x,bb.x,-bby,bby,CameraPOS.length()-500.0f,CameraPOS.length()+500.0f);

but the problem that is that with this configurations, when the viewer moves u will see the shadow moved,

i think this is not the best way for shadow mapping on large terrain bcoz there is a lot of problems that appears ,

so can someone suggest me any improvements for my method ?

AdrianPi
11-10-2009, 04:51 AM
There is an interesting method for terrains. Look for Cascaded Shadow Maps here:

http://developer.download.nvidia.com/SDK/10.5/opengl/samples.html

casper sky
11-10-2009, 07:57 AM
tx u for the reply and the link,
but i want to know if there is any improvments for my own method b4 getting into cascaded shadow maps .
tx

Brolingstanz
11-10-2009, 09:32 AM
What exactly is your method, casper?

casper sky
11-10-2009, 11:00 AM
tx brolingstanz for ur response ,
well my method is a classic projective shadow mapping:
first i render the scene from the light point of view into a shadow texture, i pass that texture to a shader that will reproject the vertices from the eye camera space to light clip space and calculate the shadowed area.
the only difference that i am doing is that when i am calculating the shadow map from the light view i am setting the lookat function to look at the eye position :
gluLookAt((float)light_pos.X,(float)light_pos.Y,(f loat)light_pos.Z,CameraPOS.X,CameraPOS.Y,CameraPOS .Z,0,0,1);
as u can see from the glulookat i am looking at the CameraPos.

the shadows are working correctly on the different objects on the terrain( trees, houses...) but the problem is when i calculate the shadow for the montain on the terrain ( u can see the image attached with the post) and the second problem i have is that when the camera moves on the terrain the shadows will move with bcoz of my glulookat.
so i am asking how can i improve my method to eliminate this problems,

AdrianPi
11-10-2009, 05:16 PM
To have more info... is it a parallel (directional) or a perspective (spot) projection the one you use for the light/shadows?

If the latter, that's the source of your problem. Even if you try making both the light position and the light target relative to the camera, something like:

// a lantern or flashlight floating over the camera but maintaing the same direction.
gluLookAt(CameraPOS.X+light_pos.X,CameraPOS.Y+ligh t_pos.Y,CameraPOS.Z+light_pos.Z,CameraPOS.X,Camera POS.Y,CameraPOS.Z,0,0,1);

Even with that, your shadows will move as they are originating from a single point.

To simulate a distant light -like the sun- you need a parallel projection for the shadow map.

casper sky
11-11-2009, 02:26 AM
can u explain a little how to make this parallel projection for the shadow map ?

is not the same as i am doing with the glOrtho ?
as far as i know glOrtho will create a cube volume so all light beams are uniform like the sun? is it true what i am saying ?
tx

Dark Photon
11-11-2009, 05:18 AM
can u explain a little how to make this parallel projection for the shadow map ? is not the same as i am doing with the glOrtho ?
Same thing. glOrtho generates an orthographic aka parallel projection, which you'd use for rendering shadow maps from directional light sources.


as far as i know glOrtho will create a cube volume so all light beams are uniform like the sun? is it true what i am saying ?
Yes, so all light beams are parallel as from the sun (at 93 million miles distance anyway :) ) .