Terrain Splatting

To do the terrain splatting you build an array the size of the heightmap with values [0-3] that map to the four terrain textures. Floating point is used so you can blend between the textures when creating the final output. The array is a combination of the actual height (scaled down to 0-3) and some perlin noise. Heres clean room documentation of the noise generation:

vec = global_position * 0.20319f; low_freq = perlin_noise2(vec.X * 0.222222, vec.Y * 0.222222) * 6.5; high_freq = perlin_turbulence2(vec.X, vec.Y, 2) * 2.25; noise = (low_freq + high_freq) * 2;

To build the final values in the array the start height and height range need to be used by bilinearly interpolating between the four corners of each with the current x/y position in the array. It all comes together like:

value = (height + noise - interpolated_start_height) * 4 / interpolated_height_range;

That's all there is to it basically. The rest is an exercise in texture compositing and interpolation.