Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

How does 2D/3D Perlin Noise (Terrain Generation) work?

Asked by 7 years ago

I've seen this used in a lot of games involving custom terrain generation. This has been on my mind for a while now and I'm sure it'll benefit other developers coming here as well. I have no grounds for basis and the wiki article didn't help much. Therefor, I have no example scripts to show. Please give a detailed explanation, enough to the point that I can at least understand the wiki article, at most do something with it. Thank you!

1 answer

Log in to vote
3
Answered by 7 years ago

A basic explaination of Perlin noise.

The way Perlin noise works is that you give it one, two or three values (corresponding to coordinates in one, two or three dimensions) and it will give you a value based on those coordinates. Using the same input values will always result in the same output value.

Using this for terrain

With terrain, we generally use Perlin noise to create a heightmap (a table which holds the height of the terrain at each 2D position); for every X/Z location in the terrain, we pass it the X and Z coordinates of that position, then multiply the return value by some number (the returned value is between -0.5 and 0.5 and so is too small for use in a heightmap, so we multiply it).

If you're interested, I have a terrain generator here. (#ShamelessSelfAdvertising)

Finally, remember that the coordinates cannot be integers; this has caught me out a few times. You can divide the coordinates by some large fixed constant to produce values with a decimal position.

Hopefully this helps you to understand.

Ad

Answer this question