Game Development Reference
In-Depth Information
How it works...
With this simple implementation, and by using the supplied ImageGenerator class, we
have the basics for a heightmap. We can see the result in our Projects folder under as-
sets/Textures/heightmap.png . It's an image that shifts smoothly between bright
and dark areas; here, bright areas represent a high terrain and dark areas, a low terrain.
Bright pixels have values that are close to 1, whereas dark pixels have values close to 0.
Normally, noise outputs values between -1 and 1. This is why we change the amplitude to
0.5f so that it yields a range between -0.5 and 0.5, and then we add 0.5 to the result.
A noticeable problem is that no matter how much we change the speed and frequency of
the noise, the same kind of rolling hills landscape will appear, only in different scales. By
changing the octaves' value, we will generate noise in several iterations with decreasing
amplitude. The value of each pixel for each iteration is multiplied with the previous one.
The result is called fractal noise. Using octaves is a way of adding detail by iterating over
the result with different frequencies. For each iteration, the frequency is doubled and the
amplitude is halved.
Frequency can be thought of as a scale value where a higher frequency will generate more
and smaller features. Having a higher frequency on its own will make peaks and valleys oc-
cur more frequently.
A normalization process is not strictly needed for a heightmap, unless we want to save it as
an image. Also, if we were generating a large number of heightmaps (for example, during
the runtime for a game), we would not want to normalize the terrain based on a particular
heightmap's minimum and maximum values or we would end up with very similar and
hilly landscapes.
Search WWH ::




Custom Search