August 4, 2014

Fractal Noise Using Value Noise - Tiled

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!

I mentioned in my first value noise post that I was interested in using noise for terrain generation. The terrain in my game is finite, and obvious terrain edges are jarring, so I needed to figure out a way to make the terrain wrap.

During my extensive research (i.e. googling), I found there were ways to generate noise so that it always tiled, but the math was getting a bit over my head and I began questioning if it was worth it.

Thankfully, I found a simple solution for value noise that’s good enough to fit my needs.

Because value noise samples values at powers of two, a particular octave can tile if its height and width are a multiple of its power of two.

So, for example, the octave that samples every 22 (4) values can tile at a width of twelve (a multiple of 4). This is because the last sample falls just off the edge and you can reuse the first value.

tiling diagram

Finally, if all the octaves tile, the resulting fractal noise (that combines those octaves) can also tile. Additionally, as long as the last octave tiles, the rest of the octaves can also tile. This is because multiples of 25 (for example) will always be multiples of 24, 23, 22, 21, and 20 as well.

* noise with only one octave is the same as white noise.

Here’s an example of noise that can tile:

./bin/fractal_noise -a value --seed 42 --octaves 7 -h 128 -w 128 -n

./bin/terrain -a value --seed 42 --octaves 7 -h 128 -w 128

value noise tile terrain tile

And here is the same noise tiled:

value noise tiled terrain tiled

This was good enough for me! As long as I use the correct size (height and width) and octave combination, my terrain will wrap.