Many of the shaders I find myself writing require some sort of blending between textures. The most common example of this is for terrain shaders, or shaders for terrain type objects. These are usually controller by a splat map, where each color channel dictates the amount of a given texture to use. Another reasonably common example is a model where this data is fed in through the vertex colors instead of a texture map. A rarer example is an effect where the blending is controlled by world position, or even procedural noise.
Everything here is written using C# or HLSL/Cg in Unity, but the maths and principal are valid for any DirectX or OpenGL engine.
In this post we’ll be looking at how to implement texture blending, starting with a basic linear blend and ending up with a fancy height-blended approach. There’s a cginc to download at the end so you can quickly and easily implement these effects into your own shaders.