HLSL Multi-texturing with fog problem in Direct3D

Hey guys I'm trying to implement multi-texturing and fog on some terrain in my demo, but apparently I didn’t understand something because the texturing is not visible, the only thing that is displayed is the color of the fog on the terrain. No signs of texturing at all

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 color of the fog is gray, and that’s all I get. This is very depressing!

thanks for the help

+3
source share
2 answers

I assume that FogSaturate is too high, or, in other words, FogRange is too low, so calling lerp always returns FogColor. Try installing FogRange above and see if it helps.

Robert

+1
source

, matVP ( ) * ( ), , World, View . ( , , . ).

:

pEffect->SetMatrix( "MatVP", &(matW*matV*matP));

.

+1

All Articles