shadow mapping problem on large terrain

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,(float)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 ?

There is an interesting method for terrains. Look for Cascaded Shadow Maps here:

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

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

What exactly is your method, casper?

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,(float)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,

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+light_pos.Y,CameraPOS.Z+light_pos.Z,CameraPOS.X,CameraPOS.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.

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

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 :slight_smile: ) .