Hi all.

There is a new terrain shadow demo i coded today :
http://www.geocities.com/lionhttp

The demo is simply amazing. I didn't think i could get such a smooth shadow, but... here it is.

New keys :
+/- : Increases/Decreases sun rotation speed.
Page Up/Page Down : Increases/Decreases the number of frames used to interpolate.
T : still toggles view from sky
(When a setting is modified, it apears in the DOS console)

You can modify the terrain by changing some values in the HeightmapGeneration.lua file.

Technically, the shadow sampling algorithm has been improved a lot.
The quality of the shadow signal sampled each frame can contribute for 25-30% with a very smooth output. (interpolate over 3-4 frames)

Basically, it consists in traversing all the vertices of the terrain in front to back order.
Then, project each vertex on a line in the XZ plane perpendicular to the light direction.
So, this point is transformed into an index in a buffer.
In this buffer i conserve the max height found at this point on the line for the frame.
Studying the height of this point gives the result.
If it's lower than a previous projected height, it is in shadow. If it's higher, it's the new reference.

Traversing the terrain is done by raw or by column, given the direction of the light.
Each time a raw (or a column) has been processed, the height buffer can be seen like a 'signal', this signal will be merged with the one obtained for next raw (or column), and so on ... noise will apear very quickly and the shadow map will be very ugly.

To overcome this, i sample in buffer 5 times bigger than necessary, and just sample key points in this buffer. Then, every time i process one raw, i rebuild the signal with the keypoints i sampled in the new raw...
It's a lot better, but more cpu intensive. It's a trade-off.

Another thing that helps a lot is to  blur the the ouput light map (difuse-lightind + shadow) before aplying it to the vertices.

Damn, it was quite a fun thing to play with.

Go download and enjoy ! ;)
