//Application fed data
const float4x4 matWorldViewProj;
const float4x4 matWorld;
texture Sand_BM_bmap, Grass_BM_bmap, Rock_BM_bmap, Snow_BM_bmap;
// ColorMap Samplers
sampler SandSampler = sampler_state { Texture = <Sand_BM_bmap>; };
sampler GrassSampler = sampler_state { Texture = <Grass_BM_bmap>; };
sampler RockSampler = sampler_state { Texture = <Rock_BM_bmap>; };
sampler SnowSampler = sampler_state { Texture = <Snow_BM_bmap>; };
// Vertex Shader:
void TerrPaintVS( in float4 InPos: POSITION, in float2 InTex: TEXCOORD0,
out float4 OutPos: POSITION, out float2 OutTex: TEXCOORD0,
out float Height: TEXCOORD1 )
{
// Temporarily transform the vertex from object space to world space:
OutPos = mul(InPos, matWorld);
// Capture the HEIGHT data of the vertices
Height = 1-(OutPos.y/OutPos.w);
// Transform the vertex from object space to projected world space:
OutPos = mul(InPos, matWorldViewProj);
// Pass the texture coordinate to the pixel shader:
OutTex = InTex;
// Pass the calculated depth to the pixel shader: ... APPARENTLY
}
// Pixel Shader:
float4 TerrPaintPS( in float4 InPos: POSITION, in float2 InTex: TEXCOORD0,
in float Height:TEXCOORD1 ): COLOR
{
float4 Color;
if(Height < 0.16) Color = tex2D(SandSampler, InTex);
else if(Height < 0.50) Color = tex2D(GrassSampler, InTex);
else if(Height < 0.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();
}
}