A shader for using an RGBA Map to texture map a primitive with four textures.
The first texture is the base texture splat map. The image on this blog entry is a texture splat map that I’ve used, anywhere there is a green component is grass, anywhere there is blue is sand/dirt, and anywhere there is red is rock/road. The colour component acts as a blend value.
The other three textures represent the area I just mentioned, there is room for texture to be applied to the same texture splat if the alpha channel is used, but I prefer to save that for use as a height map in the vertex stage.
// --- [ structs ] --------------------------------------------
//
struct VS_OUTPUT
{
float4 position : POSITION;
float2 uv : TEXCOORD0;
};
struct VS_INPUT
{
float4 position : POSITION;
float2 uv : TEXCOORD0;
};
// --- [ vertex program ] -------------------------------------
//
VS_OUTPUT main_vp( VS_INPUT In, uniform float4x4 worldViewProj )
{
VS_OUTPUT Out;
Out.position = mul(worldViewProj, In.position );
Out.uv = In.uv;
return Out;
}
// --- [ fragment program ] -----------------------------------
//
float4 main_fp( float2 uv : TEXCOORD0, uniform sampler2D texBase, uniform sampler2D tex0, uniform sampler2D tex1, uniform sampler2D tex2 ) : COLOR
{
float3 colour = tex2D(texBase, uv).rgb;
return tex2D(tex0, uv) * colour.r + tex2D(tex1, uv) * colour.g + tex2D(tex2, uv) * colour.b;
}