DirectX Texture Splatting and Terrain Patches

Last modified: 06 Feb 2017

Here’s an implementation of texture splatting and terrain patches using DirectX and shaders. My demo combines 3 blend maps to produce the final texel.

After sampling all the blend maps, we just need to combine them like this:

// Use 1st blend map
float4 texColor = lerp(c1,c2,a.g);
texColor = lerp(texColor,c3,a.b);

// Now use 2nd blend map
texColor = lerp(texColor,c4,a2.r);
texColor = lerp(texColor,c5,a2.g);

// Return the final texel color with vertex shading and light map
return texColor * shade * l;

And that’s it. You have a splatted texture. The variable shade is vertex lighting while l is a lightmap applied to the whole terrain to produce shadows on the terrain.

The terrain patches works by instead of creating the whole terrain as one big mesh, split it into many several rectangular meshes - or patches. Then enclosed them in a bounding box or a rectangle since height does not matter, then do a camera frustum culling as usual.

Feel free to get in touch with me if you have any questions. Would love to hear from you.

Download demo and source

Texture Splatting Terrain Patches
Texture Splatting Terrain Patches