//Application fed data
const float4x4 matWorld; // World matrix
texture Sand_BM, Grass_BM, Rock_BM, Snow_BM;
// ColorMap Samplers
sampler SandSampler = sampler_state
{
Texture = <Sand_BM>;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler GrassSampler = sampler_state
{
Texture = <Grass_BM>;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler RockSampler = sampler_state
{
Texture = <Rock_BM>;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler SnowSampler = sampler_state
{
Texture = <Snow_BM>;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
// Vertex Shader:
void TerrPaintVS(
in float4 InPos: POSITION,
in float2 InTex: TEXCOORD0,
out float4 OutPos: POSITION,
out float2 OutTex: TEXCOORD0)
{
// Transform the vertex from object space to world space:
OutPos = mul(InPos, matWorld);
// Pass the texture coordinate to the pixel shader:
OutTex = InTex;
}
// Pixel Shader:
float4 TerrPaintPS(
in float4 InPos: POSITION,
in float2 InTex: TEXCOORD0): COLOR
{
float4 Color;
if(InPos.y<16) Color = tex2D(SandSampler, InTex);
else if(InPos.y<50) Color = tex2D(GrassSampler, InTex);
else if(InPos.y<75) Color = tex2D(RockSampler, InTex);
else Color = tex2D(SnowSampler, InTex);
return Color;
}
// Technique:
technique AmbientTechnique
{
pass P0
{
VertexShader = compile vs_2_0 TerrPaintVS();
PixelShader = compile ps_2_0 TerrPaintPS();
}
}