Terrain Generation Tutorial: Normalize
previous | next
| code
One facet of the terrain algorithm we are using is that it does not automatically
clamp height values into some numeric range. This means that after generating,
our lowest valley could be above zero, and the highest mountain could
be anywhere. This makes things a bit difficult. Ideally, the height values
would range from zero to one, so that we can scale the entire terrain
to make it as tall as we want without affecting anything else. To do this,
we need to normalize the terrain.
Normalizing is a simple mathematical process of getting values in some
range, and mapping them to another range. Graphically, it looks some like
this:

The graph on the left shows a curve which has not
been normalized. Its values fit the
range (1.0, 4.0). After normalization, you can see that the curve has
been smoothly
scaled to fit the range (0.0, 1.0 ).
To do this to our terrain, we simply scan through all of our height values,
keeping track of the lowest and highest ones found. Once we know this
minimum and maximum, we scan through the heightmap again, this time normalizing
each height from the range (minimum, maximum) to the range (0, 1). The
equation to do that looks like this:

Now, we know that the lowest point in our terrain will always be zero,
and the highest peak will always be one. This will come in handy later.
To see how, click here.
Copyright © 1999-2002 Bob Nystrom.
|