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.
- The octave sampling at 21 (2) can tile at sizes of 2, 4, 6, etc.
- The octave sampling at 22 (4) can tile at sizes of 4, 8, 12, etc.
- The octave sampling at 23 (8) can tile at sizes of 8, 16, 24, etc.
- …
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.
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 using 1 octave* can tile sizes that are at multiples of 20 (1)
- noise using 2 octaves can tile sizes that are at multiples of 21 (2)
- noise using 3 octaves can tile sizes that are at multiples of 22 (4)
- noise using 4 octaves can tile sizes that are at multiples of 23 (8)
- noise using 5 octaves can tile sizes that are at multiples of 24 (16)
- noise using 6 octaves can tile sizes that are at multiples of 25 (32)
- noise using 7 octaves can tile sizes that are at multiples of 26 (64)
- …
* 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
And here is the same noise 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.