June 30, 2014

Fractal Noise Using Value Noise

Update 2014-08-13: When I originally wrote this post, I mistakenly referred to value noise as Perlin noise. I have updated this post to refer to the correct types of noise. Read More

Update 2014-11-22: Read more about Perlin noise here!

Noise is a set of randomly generated values that can be used in a variety of ways to generate content for a game. There are many different methods for generating noise, one of which is value noise. I was interested in using it to generate terrain for my game, however I found it a bit difficult to understand at first. So, I wrote some ruby code as a learning exercise. You can find it on github.

The images below were generated with the following commands using the code provided above.

./bin/fractal_noise --algorithm value --output-octaves

White noise is completely random values and might look something like this:

white noise

While this is fine for some purposes, it is not really useful for generating terrain.

Value noise can be described as more gradient noise. It takes samples of white noise (at a certain frequency) and creates a gradient between them. Combining multiple layers of value noise at different frequencies will create a form of fractal noise.

Using the same white noise as above to create value noise, you end up with fractal noise like this:

value noise

Much better!

There are two parameters you can set when generating this kind of noise: octaves and persistence. The noise above was produced with 6 octaves and 0.6 persistence. Each octave takes sample values from the white noise at a different frequency (power of two) and interpolates values in between. The octaves of value noise are then combined together using the persistence value to get fractal noise.

Confusing? For me, it was easier to understand what was going on by comparing images using different settings. First, here are each of the six octaves of value noise that were combined to generate the fractal noise above. They sample values from the white noise every 1, 2, 4, 8, 16, and 32 values and create a gradient between the samples.

octave 0octave 1octave 2

octave 3octave 4octave 5

Octaves

You could combine fewer octaves or combine a greater number of octaves for differing effects. Using the same white noise from above, here is noise with 5 octaves, 6 octaves (same as above) for comparison, and 7 octaves.

./bin/fractal_noise --algorithm value --octaves 5

./bin/fractal_noise --algorithm value --octaves 7

5 octaves6 octaves7 octaves

Combining fewer octaves produces more turbulent noise.

Persistence

Persistence is a value between 0 and 1. Using 6 octaves again, here is the same noise with 0.3 persistence, 0.6 (same as above) for comparison, and 0.9 persistence.

./bin/fractal_noise --algorithm value --persistence 0.3

./bin/fractal_noise --algorithm value --persistence 0.9

0.3 persistence0.6 persistence0.9 persistence

Persistence changes how much each octave affects the end result.

Terrain Generation

So how can you use this kind of noise to generate terrain? One simple way is to use noise values as terrain height. Everything below a certain value is water and everything above it is land. I included a simple example that does something like this.

./bin/terrain

value noisevalue noise terrain

Play around with different seeds, octaves, and persistence and you will find that there is a variety of different terrains you can generate using value noise.

Other Resources

Update 2014-08-13: These resources mistakenly refer to value noise as Perlin noise.