Terrain Development Guide
Chapter 2: In Depth - Basic Terrain
Terrain Elevation Map
Properties and Structure of the Terrain Elevation Map
The Terrain Elevation Map contains all the information that the graphics engine needs to determine the height of each point in the terrain grid. The terrain grid matches the layout of the raster format used by the map file described previously. An illustration of this grid is provided below:

The data points provided in the terrain grid are used by the terrain graphics engine to form the polygons that actually make up the visual scene. Two polygons (triangles, specifically) are generated from each grid square:

An example of how these polygons are formed within the terrain scene is provided below (blue lines outline the polygons):

Scale
The value assigned to Scale in the Terrain Descriptor File sets the size of polygons displayed within the terrain. The value you use for Scale can have two effects. First it controls the overall size of your terrain.
For example, in the Target Korea mod, the Elevation Map measures 1000 x 1000 pixels and depicts a region that in the real-world measures 1000 kilometers x 1000 kilometers. We chose to model this terrain as true size (1:1), so the scale value necessary to do this is 250 meters/pixel (250km * 1000 m/km / 1000 pixels). This means that each square making up the terrain grid will measure 250 meters on a side in game-world dimensions.
The second effect of using a smaller scale value is that it can provide a dramatic improvement in the visual quality of the scene. The smaller the value, the smaller the polygons and the more realistic the terrain appears.

Before immediately going to very small scale values, however, you need to keep in mind some potential disadvantages:
- As you make the resolution smaller and smaller, you will force the drawing of more and more polygons. As the number of polygons increase, your terrain will begin to negatively affect the frame-rate of the Players flying in your world. There is a trade-off here that you will have to experiment with.
- As smaller values are used for scale, the size of your terrain files will grow dramatically. Since Players using your terrain will have to download these files, it can be a concern should the files get very large.
- The size of each terrain square will affect how your individual terrain textures (farms, forests, rice paddy, etc) are drawn. If you make terrain textures that have objects drawn on them, you'll want to make sure you draw them appropriate for the scale of the terrain. Otherwise you could end up with trees, roads, etc that look huge (or tiny) when rendered in the game-world. See the section on Ecology Maps for more information.
Hint: Our experience at Targetware is that a scale value of 200-250 m/pixel provides a nice compromise between visual quality, framerate, and size.
Graphics Format for Elevation Map
The format that the Targetware engine uses for the Elevation Map is that of the Targa graphics file (.tga). See Chapter 4 for some more information on how the file is structured if you aren't familiar with it.
So, why a graphics file to store data? Well, first you need to know that a graphics file is simply a data file with some extra stuff thrown in it that allows that data to be presented to the screen by color rather than just a long stream of confusing numbers. In addition to providing a nice standardized data structure, the Targa format (because it is a graphics format) permits the data to be viewed and edited using any drawing package capable of viewing and manipulating this format.
Specifically, the Elevation Map Targa (.tga) file must adhere to the following specifications:
- 256 color gray-scale image
- 8 (or 24)-bit Color-Indexed (mapped) palette
- 8-bit indices (data, pixels)
- Non-compressed
An example of an Elevation Map is provided below

How the Elevation Map is Used
To understand how an elevation map is used, you need to first understand that a grey-scale image consists of 256 palette values (colors), ranging from 0 (black) to 255 (white). Since each pixel in the elevation map corresponds exactly to the location of a terrain grid point, the value at that pixel (0-255) is used to define the elevation of that grid point. The elevation at each point is calculated per the following formula:

Elevation units will be in meters, and in integer format (i.e. no decimal values, rounded to the next greatest integer).
So, wherever palette index 0 (black) is used, the elevation in the terrain will be whatever value you set for minimum height in the Terrain Descriptor File. Meanwhile, index 255 (white) produces the value of maximum height you set for minimum height in the Terrain Descriptor File. The varying levels of grey in between black and white will produce elevations between the minimum and maximum settings.
Because each color represents a palette or elevation value, you can draw or edit any point you want using the standard drawing tools available in your graphics editor. If you want an area to be lower in elevation, make the color darker (grey towards black), if you want it higher in elevation, make the color lighter (grey towards white). Many graphics editors even have blending features that can smooth the colors and create other effects.
Low Byte Height Maps (Optional)
There is one disadvantage to using this graphics format to store elevation data. If you look at the equation above you can see that there can be only 256 elevation values used in your terrain.
For example, if your min_height was 0 and your max_height was 1000 meters, your terrain can only use a set of fixed elevation values: 0 meters, 4 meters, 7 meters...996 meters, 1000 meters (0, 1000/255, 2000/255, 3000/255...254000/255, 255000/255). Therefore, in this particular situation your world could not have an elevation of 3.5 meters, 5 meters, etc.

In some cases this could make your terrain look "stair-stepped". To remedy this issue, there is an optional Elevation Map (called "low byte") that you can use to "fill in" the gaps between the fixed elevation values generated by the primary (or "high byte") map.
The Low Byte map is a grey-scale image just like the High Byte Map. The elevation values it produces are generated using the following equation:

The value generated in the equation is then added to that generated by the base elevation equation.
Final drawn height = base height + low byte height
So, the advantage of the low byte map is that it gives you an additional 256 elevation positions between each value calculated using the high byte map. This means that at a worst case where your terrain contains Mt. Everest (highest point on Earth at 8852 meters) and the Dead Sea (lowest point on Earth above water, -396 meters), your terrain resolution will still be better than 0.15 meters (0.5 feet)! This is much more than any flight simulator will require.

Because the low byte data is just filling in the gaps created by the high byte data, its elevation map tend to be formless and chaotic. An example is given below:

To add a low-byte map to your terrain, specify its file name in the header of Terrain Descriptor File to the variable "height2".
Hint:
Even if you are building your own hypothetical terrain, you should still make use of the low byte map feature. Most graphics editors have random noise-generation features. If you create a low byte map using that generator, you will find it gives your terrain a much more realistic appearance.
|