APOCALYX is a...

free Game Engine based on OpenGL (MAIL) (SITE) (FORUM) (BLOG)

Tuesday, April 29, 2008

Infinite terrains

APOCALYX supports a particular kind of terrain with no boundaries. In reality, it is a fake infinite terrain, because it simply repeats the same pattern periodically. Anyway, the pattern can be quite large and the periodicity is not easy to detect, except when recognizable shapes are built in the terrain itself.
To create this kind of terrain you have two possibilities, shown in the flight-simulator series of the demos: “Flying Circus” and “Zeke on Your Six!
The first shows also an application of the built-in “noise” library. It includes functions to generate fractal terrains with their own colors and shadows. This is the simpler and faster way to generate a terrain, but often you need a particular kind of shape for your landscape, thus a random generator of fractal noise is not the best choice.
The second possibility, that is also the obvious one in most 3D engines, is shown in the second demo. The terrain is defined with the help of several images: an height map, that encodes the heights of the terrain in a greyscale image; a color map, that encodes the very large scale color of the map, including the shadows of mountains and hills; a coarse map, that is a texture applied on the large scale; and a detail map, that is a texture applied at small scale to simulate the details of the terrain.
The last two textures are easy to find as free resources on the internet: for example, use seamless textures of rocks, concrete, grass, sand etc. The first two instead (the height map and the color map) must be tailored according to your needs. You can use terrain editors, like Terragen, that generate a ladscape given a few parameters and also provide tools to modify it.
When the editing phase is done, simply take a screenshot of your terrain in the height map editor (this is the grayscale image that defines the height map), then render your terrain applying the light conditions that you prefer (be sure to set up correctly the sun inclination, or the shadows will not match the sun position in your world) and take another screenshot from above (this is the color map with shadows). Remember that the infinite terrain requires a seamless height map, so use the same shape for the opposite sides of the map.
For more details, on how to load your brand-new maps in the engine, read the code of the demos cited above, give a look to the resources zipped in the data files and, finally… fly like an eagle!

No comments: