I’ve been interested in procedurally generating fantasy settings for a long time. Terrain is one part of that problem, and noise is a useful place to start. The name doesn’t tell you much, though. What does noise have to do with making a map?
In this context, noise is a function that takes a position and returns a number that appears random. If we use that number as the height of the ground, we get a heightmap. That’s what the examples below show: a map viewed from above, with black representing low ground and white representing high ground.
I’ve included a few little JavaScript toys to make this easier to see. They start with the same settings. Changing the seed gives you a different map; using the same seed and settings gives you the same map again. The controls work with a keyboard, too.
Basic noise
The simplest approach is to pick a random height for each tile. This is often called white noise. Each tile is independent of its neighbors, so a very low tile can sit right next to a very high one. Make the tiles small enough and it looks like television static.
That’s useful for things like scattering pebbles around a map. However, it doesn’t do a very good job of giving us terrain. We need some relationship between neighboring heights.
Perlin noise
Perlin noise gives us that relationship. It assigns random directions, called gradients, to points on a square grid, then smoothly blends their influence between those points. Nearby positions end up with similar heights. The result looks much more like hills and valleys.
The square grid can sometimes leave visible directional patterns. Still, this is already a useful starting point. If you’re curious about the code, Ken Perlin has a reference implementation of improved Perlin noise.
Simplex noise
Simplex noise was also developed by Perlin. In two dimensions, it uses a grid of triangles instead of squares, with a different way of combining the gradients’ contributions. It produces smooth variation with less of the square grid’s directional bias. It’s also more efficient as the number of dimensions increases (though that doesn’t necessarily make this two-dimensional example faster). Perlin goes into the details in Noise Hardware.
Making it look like terrain
On their own, the smooth examples look a little… blobby. Try setting either one to four layers. Each additional layer has smaller features (twice the frequency) and half the strength of the previous one. That adds little bumps to the bigger hills. This technique is often called fractal Brownian motion, or fBm.
Then turn on terrain colors and play with the sea level. The low areas become water, and the higher areas become grass, rock, and snow. This is a pretty simple way of coloring a map; figuring out where those things would actually occur takes more work.
There’s a lot more to generating terrain, especially once you start thinking about rivers, erosion, and climate. However, a heightmap gives us something to work with. It’s a start.
If you want a more detailed explanation, Red Blob Games has a guide to making maps with noise functions, with interactive examples covering everything from layering noise to choosing biomes.