Noise is useful for many things, from texture generation for natural objects to heightmap generation. This small article will explain how I use a psuedo-random noise function to generate the planet heightmaps.
First, let me just outline what noise is and the different applications it can be used for. Let’s consider the following:
5 + a = x.
Looking at the simple equation, you can see that we can control the output ‘x’ by supplying a specific variable ‘a’. What’s even better is that even if you reset the computer, as long as the variable ‘a’ stays the same, you will always get the same output. Now this may seem like a huge oversimplification, but that is effectively what Pseudorandom numbers’ are. As long as we keep the seed the same ( our ‘a’ variable ), the outcome will always be the same. This has many uses, especially if you are trying to create textures that are ‘natural’ looking, such as fire, clouds, wood, marble, and for me, terrain heightmaps. This is great for planets, because I don’t need to save any heightmap information at all, as it is now all generated on the fly.
There are many different kinds of noise that can be used, with the most common probably being Perlin Noise.
The perlin noise function should return a value within the [-1,1] range. When you pass in variables in small increments, then the results should also have only small changes. If you pass in random values to the noise function, then you will get seemingly random values as output.
Perlin noise also works best if you take ‘samples’ of noise (called octaves) and modify the output by the amplitude (which decreases per octave of noise). This works like follows:
You can see here that the result will be sampled and refined the desired number of times.
Here is a link to Ken Perlin’s original improved noise function, which can be easily converted to c#.
In the second part of the Noise articles I will show you have to use perlin noise to generate heightmaps using 3d coordinates, as well as the actual code 🙂
You can Read Noise Part II here,