Ogre Planet

In 2008 I was inspired by the (at the time of writing still yet to be released) Infinity MMO and the associated development blog. This project is an attempt to build a system that will render planet(oid) scale objects at animation frame rates (30 fps). The Ogre3D renderer was used and code is actually based on an original concept by 'HexiDave' in the Ogre3D forums. Others have since taken planetary rendering further producing some very impressive results.

At start up, vertices for planet are created at the highest possible level of detail using the 'sphere slicing' method described here. The heights of mountains are greatly exaggerated to better show the effect at a distance (can all be changed in the source code).

A quad tree is constructed for each of the twelve faces of a cube and linked together. Height information from the 'sphere slicing' algorithm is applied to each vertex.  At runtime for each quad tree chunk, a decision is made (based on the distance from the camera) as to how many subdivisions should be rendered. All generated vertices are 'spherized' then added to a single large vertex buffer. During this phase, adjacent quads are stitched together by adding triangles.  Finally during rendering, a slope/height algorithm is applied to decide on which blend of four base textures (dirt, grass, rock, snow) to use for a given vertex. Water is applied with alpha blending as a second pass at the original radius of the sphere.

This approach eats memory (local RAM and video RAM) and has a finite number of pre-computed subdivisions. A better approach would be to retrieve the planetary height map through some form of procedural function.  Rounding errors aside, a procedural function allows for an infinite level of detail. Getting procedural functions to work in real time is challenging. Perlin noise shaders work reasonably well, unfortunately the graphics card that I had at the time was an ATI 9500 which had only basic ps_2_x pixel shader support and I quickly blew out the instruction count limit.

Keen eyes will also spot that there is an issue with the textures.  All textures are a single 2D map and to wrap seamlessly around a planet, textures need to be cube maps (six textures one for each face).  This creates big problems for asset generation, again procedurally generated 3D textures are probably the best approach ('real' artists have told me that procedural textures often look 'too procedural').  I began looking at procedural texture generation but did not make much progress.  Around this time I also made a (very small) contribution to Ogre3D - volumetric 3D DDS file saving support, so I am now listed as a contributor in the contributors file included with the Ogre3D source.

This code is not actively maintained and is provided "AS IS" under the MIT license for educational purposes in the hope it will be useful to someone.

Technologies: VC2008 C++, Ogre3D (1.4.7)

 

File Attachments: