shadow mapping problem on large terrain

i have two problems with my shadow mapping technique implemented on a large terrain :
an image can be found here :

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 :

and i setup an ortho projection for the light projejection

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:

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 .

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

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 ?

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