Procedural terrain generation

Let's generate a terrain procedurally.
First, we start by generating some perlin noise. We use the MurmurHash hash function to generate random numbers with a given seed (press G to randomize the seed):




Use fractal brownian motion to make it more noisy:



Compute the normals from the noise texture using a Sobel filter:



Generate a 3D grid (hold and drag to rotate):

Apply the noise texture as a heightmap for the grid:





Color the terrain depending on the height and slope:

Calculate diffuse lighting with the normals:

Add water and tile the terrain (press W and S to lower and raise the water's level):