Noise Part I

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.
Perlin Noise

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:


float lfResult = 0;

float lfPersistance = 0.8f;
for(int i = 0; i < octaves; i++)
{
float freq = i * 2;
float amplitude = lfPersistence * i;
lfResult += PerlinNoise(xyz * freq) * amplitude;
}

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,

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: