Basic Concepts of Height Maps
Heightmap's are use to Create Terrains in many 3D Engines using Greyscale
images. A greyscale image contains pixels that range from white to black with
shades of grey in between. The shades of grey in the image relate to the height
of points on the terrain. The dark values are low points in the terrain and the
bright values are the high points in the terrain.
A short discussion about color space might be in order. The most popular color
space used in paint programs today is the R-G-B color space model. In this model
each primary color value (red, green and blue) is represented by a numeric value
ranging from 0 - 255, where 0 is completely dark and 255 is completely bright.
Some examples are: 255,0,0 = bright red, 0,255,0 = bright green, 0,0,127 = blue
at 50% brightness, 255,255,0 = yellow (by combining red and green).
Whenever the RGB values are all the same (such as 64,64,64 or 157,157,157) what
you get is a grey pixel. So in a greyscale displacement map, all the color
values have equal red, green and blue values.
Technical Concepts of Height Maps
The midpoint displacement algorithm can be implemented using a
one-dimensional array of height values which indicate the vertical location of
each line segment vertex. This array is a one-dimensional height map. It maps
its indices (X values) to height values (Y values).
Terrain is used via a two-dimensional array of height values which will map
indices (X and Z values) into height values (Y values). Note that although our
end goal here is to generate three-dimensional coordinates, the array only needs
to store the height (Y) values; the horizontal (X and Z) values can be generated
on the fly as we parse through the array. By assigning a color to each height
value, you could display a height map as an image. Here, high points in the
terrain (large values) are represented by white, and low points (small values)
are represented by black: