# Enter Sandman

In the last post I mentioned that I used this Turbulence Library to create noise textures on the GPU which are then used to create heightmaps of the terrain. It’s a great library with lots of common noise functions – Perlin, Voronoi, Simplex etc. which are commonly used to generate realistic looking terrain from jagged mountains to rolling plains.

Rather than just using Perlin noise, which is perhaps the most well-known noise function, I’ve been experimenting with adding some other variations and layering additional functions to try to create unique terrain profiles for each of the environments in Nome.

For the desert environment, for example, I found that applying ridged turbulence to the noise function – subtracting the absolute value from 1 as in the following function – created soft valleys and sharper peaks much like you’d expect in a dune field:

float ridgedNoise(float2 p, float seed) {
return 1.0f-abs(perlinNoise(p, seed));
}

Then I found this article which describes a mathematical function for the side profile of a typical dune. Dunes are created when aand builds up on the windward face until a certain point when the sand dome collapses under its own weight. It stops collapsing when the angle of the collapsed face reaches the angle of repose (about 34 degrees for sand). This is all rather neatly described by:

$\frac{p\cdot s+1}{2} \cdot 1-cos\left( \frac{\pi}{p\cdot s+1} \cdot \frac{X - s}{X_m - s} \right)$

So I layered this function on top of the ridged Perlin noise to create a texture, and then used that to deform a mesh – which resulted in the following terrain:

Which, when viewed in-game, gives these nice sand dunes which are fun to run down: