shadows on terrain

i have a terrain on which trees are placed. the trees should cast a shadow.

i tried projected shadows, but the problem is that the terrain is not flat all the time.

has anybody some hints for me or links to some good sources. it´s important that the it can run in real time.


It’s just my idea (I never try it) to use 2D picture of the shadow (your projection on the bottom plane) like a texture. You must set texture coordinates (if your bottom plane is in XY you must set XY as texture coordinates) on any triangle on the ground (if you use triangles) and then you will have a shadow.

Two ideas.
a) bake the static shadow into the vertex colours or texture under the tree.
b) shadow maps or stencil buffers?

nvidia has a lot of examples.