DirectX Texture Splatting and Terrain Patches16 Mar 2009
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:
1 2 3 4 5 6 7 8 9 10 // 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.
|Texture Splatting||Terrain Patches|