[:|] robot frog3d
news
3d
games
icons
picts
misc
links
 

Terrain Generation Tutorial: Heightmaps

previous | next | code

Let's begin by establishing some basics. The standard way of creating 3d terrains is through the use of heightmaps. A heightmap is simply a 2d array of values. Each value in the array represents the height of the terrain at that value's position. For example, if the cell at (2, 3) has a value of 5, then the terrain contains the point (2, 3, 5). To render a heightmap in three dimensions you create a mesh by iterating through the two indices of the array and set the height at each vertex to the value of the heightmap at that point. Typically, I use the X and Y axes for the two indices, and the Z axis for the height of the terrain, but any orientation will work.


The table on the left shows the cells of the height map and the values at each cell. On the right is shown a wireframe view of the terrain generated by that map.

Heightmaps as Images

Another way to picture a heightmap is to think of it as a grayscale image, where the brightness of each pixel corresponds to the height of the terrain at that point. In this manner, dark regions on the image represent valleys and lighter regions represent peaks. For example:


The heightmap on the left generates the terrain on the right. As you can see, the black on the image becomes the low area of the terrain while the brighter letters stand out as mountains.

Procedurally Generated Heightmaps

Now that we understand how to generate terrains from heightmaps, the next step is coming up with an algorithm to generate this heightmap. There are a bunch out there already, each with it's own appearance and characteristics. For some examples (including some similar to this one) check out this and this. The algorithm shown next is a little different.

Click here to continue.

Copyright © 1999-2002 Bob Nystrom.