Saturday, November 17, 2007

Terrain rendering

This is an early preview of the terrain rendering engine. It's using a heightmap generated from Terragen which is then imported as a grey scale bitmap. The program is rendering the mesh without any material textures but does use a precalculated ambient map.

The ambient light map is calculated by using a ray-casting algorithm to estimate the angle of the horizon at various angles for each vertex on the height field. Using these angle values, an approximation of the sky lighting contribution can be made.

The next step for lighting is to calculate the sun contribution. Using the same ray-casting algorithm the angle of the horizon will be stored in a horizon map. This can then be compared with the angle of the sun to determine if a point is in shadow or in direct sun light. The added benefit of using a horizon map is that the angle of the sun can be changed with light and shadow being generated dynamically, so different times of day can be simulated.

Pixel shaders are going to be used to incorporate the lighting and materials. I hope to also support bump mapping to give the terrain a more rough 'feel' to it.

No comments: