I am trying to implement a multi-texturing and fog on some terrain in my demo, but apparently i am going wrong somewhere because the texturing is not visible, the only thing that is being rendered is the fog color in the terrain.
No sign of texturing whatsoever.
Here is the fx file:
//------------------------------------
//Stuff for the Terrain
uniform extern float4x4 MatVP;
uniform extern float3 SunPos;
uniform extern texture Tex0;
uniform extern texture Tex1;
uniform extern texture Tex2;
uniform extern texture TexGS;
uniform extern float3 EyePos;
//------------------------------------
sampler sTex0 = sampler_state
{
Texture = <Tex0>;
MagFilter = LINEAR;
MinFilter = ANISOTROPIC;
MaxAnisotropy = 8;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler sTex1 = sampler_state
{
Texture = <Tex1>;
MagFilter = LINEAR;
MinFilter = ANISOTROPIC;
MaxAnisotropy = 8;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler sTex2 = sampler_state
{
Texture = <Tex2>;
MagFilter = LINEAR;
MinFilter = ANISOTROPIC;
MaxAnisotropy = 8;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler sTexGS = sampler_state
{
Texture = <TexGS>;
MinFilter = LINEAR;
Magfilter = LINEAR;
Mipfilter = POINT;
AddressU = WRAP;
AddressV = WRAP;
};
const float3 FogColor = {0.5f, 0.5f, 0.5f};
const float FogStart = 10.0f;
const float FogRange = 200.0f;
struct vOut {
float4 PosH : POSITION0;
float2 cTexTiled : TEXCOORD0;
float2 cTexNonTiled : TEXCOORD1;
float shade : TEXCOORD2;
float FogSaturate : TEXCOORD3;
};
//------------------------------------
vOut VS_Def(float3 PosW : POSITION0
, float3 NormW : NORMAL0
, float2 cTex : TEXCOORD0)
{
vOut V = (vOut)0;
V.PosH = mul(float4(PosW, 1.0f), MatVP);
float3 SunVec = normalize(SunPos - EyePos);
V.shade = saturate(max(0.0f, dot(NormW, SunVec)) + 0.25f);
float Dist = distance(PosW, EyePos);
V.FogSaturate = saturate((Dist - FogStart)/FogRange);
V.cTexTiled = cTex * 16.0f;
V.cTexNonTiled = cTex;
return V;
}
float4 PS_Def(float2 cTexTiled : TEXCOORD0
, float2 cTexNonTiled : TEXCOORD1
, float shade : TEXCOORD2
, float FogSaturate : TEXCOORD3): COLOR
{
float3 Tex0 = tex2D(sTex0, cTexTiled).rgb;
float3 Tex1 = tex2D(sTex1, cTexTiled).rgb;
float3 Tex2 = tex2D(sTex2, cTexTiled).rgb;
float3 TexGS= tex2D(sTexGS,cTexNonTiled).rgb;
float inv = 1 / (TexGS.r + TexGS.g + TexGS.b);
Tex0 *= TexGS.r * inv;
Tex1 *= TexGS.g * inv;
Tex2 *= TexGS.b * inv;
float3 TexColor = (Tex0 + Tex1 + Tex2) * shade;
float3 FinalColor = lerp(TexColor, FogColor, FogSaturate);
return float4(FinalColor, 1.0f);
}
//-----------------------------------
technique DefTech
{
pass p0
{
VertexShader = compile vs_2_0 VS_Def();
PixelShader = compile ps_2_0 PS_Def();
}
}
as you can see, the fog color is gray, and that is all I am getting. It is very depressing.