I've used the FOG0 semantic, which is available on PS2.0 (not in PS3.0, though...) to map some fog, and may show if it is enabled, (but that part is untested) I hope you find it interesting and even useful

The good thing is that it is faster than the regular terrain splatter shaders, because it only reads textures twice, the bad thing is that, for now, it is only restricted to 2 textures.
Code: Select all
//Terrain vertex Shader
float4x4 matWorldViewProjection;
float4x4 matWorldInverse;
struct VS_INPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
float3 Normal : NORMAL0;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float fog : FOG0;//If fog is set, it will be used.
float2 Texcoord : TEXCOORD0;
float3 Normal : TEXCOORD1;
};
VS_OUTPUT vs_main( VS_INPUT Input )
{
VS_OUTPUT Output;
Output.Position = mul( Input.Position, matWorldViewProjection );
Output.Texcoord = Input.Texcoord;
Output.Normal = mul(Input.Normal, matWorldInverse);
Output.fog = Output.Position.z/Output.Position.w;
return( Output );
}
//Terrain Pixel Shader
float tiles;//Allows to repeat the textures many times as wished, or needed
sampler2D base1; //"Ground" Texture
sampler2D base2; //"Wall" Texture
struct PS_INPUT
{
float2 Texcoord : TEXCOORD0;
float3 Normal : TEXCOORD1;
};
float4 ps_main( PS_INPUT Input ) : COLOR0
{
float3 upVect = float3(0,1,0);
float dp = dot(upVect,Input.Normal);
dp = clamp(4*dp-2.5,0,1);
float4 col1 = tex2D( base1, Input.Texcoord*tiles );
float4 col2 = tex2D( base2, Input.Texcoord*tiles );
return lerp(col2,col1,dp);
}
