2

我试图在我的演示中在某些地形上实现多纹理和雾,但显然我在某个地方出错了,因为纹理不可见,唯一被渲染的是地形中的雾颜色。

没有任何纹理的迹象。

这是fx文件:

//------------------------------------
//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();
        
    }
}

如您所见,雾的颜色是灰色的,这就是我所得到的。这是非常令人沮丧的。

4

2 回答 2

1

I'm guessing matVP is your (view matrix) * (your projection matrix) however you will need a World, View and Projection matrix to map the location of the terrain correctly. (In other words, right now the location in which you draw your terrain at the moment is completely wrong. That's why you can't see anything).

Try passing:

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

It should work.

于 2011-05-27T01:57:20.307 回答
1

我的猜测是,FogSaturate 太高,或者换句话说,FogRange 太低,所以 lerp 调用总是返回 FogColor。尝试将 FogRange 设置得更高,看看是否有帮助。

罗伯特

于 2011-05-18T05:02:53.783 回答