簡體   English   中英

Direct3D中的紋理映射問題

[英]Texture Mapping Problem in Direct3D

大家好,我無法通過着色器渲染紋理。 我真的不知道為什么,着色器文件只是實現了一個簡單的phong照明並將紋理插值到一個簡單的四邊形上,但是我所得到的只是照明和材質顏色,好像沒有紋理一樣(該紋理是Stone紋理)但我得到的只是白色)

這是着色器文件

//------------------------------------
uniform extern float4x4 matWVP;
uniform extern float4x4 matITW;
uniform extern float4x4 matW;
uniform extern float4 DiffMatr;
uniform extern float4 DiffLight;
uniform extern float4 AmbLight;
uniform extern float4 SpecLight;
uniform extern float4 AmbMatr;
uniform extern float3 LightPosW;
uniform extern float4 SpecMatr;
uniform extern float SpecPower;
uniform extern float3 EyePos;
uniform extern texture Tex;


//------------------------------------

sampler sTex = sampler_state
{
    Texture = <Tex>;
    Minfilter = LINEAR;
    Magfilter = LINEAR;
    Mipfilter = POINT;
    AddressU = WRAP;
    AddressV = WRAP;
};

struct vOut {
    float4 posH : POSITION0;
    float3 posW : TEXCOORD0;
    float3 normW: TEXCOORD1;
    float2 cTex : TEXCOORD2;
};

//------------------------------------
vOut VS_Def(float3 posL : POSITION0
 , float3 normL : NORMAL0
 , float2 cTex : TEXCOORD0)
{
    vOut V = (vOut)0;

    V.posH = mul(float4(posL, 1.0f), matWVP);
    V.posW = mul(float4(posL, 1.0f), matW).xyz;

    V.normW = mul(float4(normL, 1.0f), matITW).xyz;
    V.normW = normalize(V.normW);

    V.cTex = V.cTex;
    return V;

}

float4 PS_Def(float3 posW : TEXCOORD0
    ,float4 normW : TEXCOORD1
    ,float2 cTex : TEXCOORD2 ): COLOR
{
    float3 LightVec = LightPosW - posW;
    LightVec = normalize(LightVec);

    float3 RefLightVec = reflect(-LightVec, normW);

    float3 EyeVec = EyePos - posW;
    EyeVec = normalize(EyePos - posW);

    float d = max(0.0f, dot(normW, LightVec));
    float s = pow(max(dot(RefLightVec, EyeVec), 0.0f), SpecPower);

    float3 Diff = d * (DiffMatr * DiffLight).rgb;
    float3 Amb  =     (AmbMatr * AmbLight).rgb;
    float3 Spec = s * (SpecMatr * SpecLight).rgb;

    float3 TexColor = tex2D(sTex, cTex.xy).rgb;
    float3 color = Diff + Amb;

    return float4(color * TexColor + Spec, DiffMatr.a);;
}


//-----------------------------------
technique DefTech
{
    pass p0 
    {        
        VertexShader = compile vs_2_0 VS_Def();
        PixelShader = compile ps_2_0 PS_Def();

    }
}

燈光和材質顏色如下:(PS:白色= D3DXCOLOR(1.0f,1.0f,1.0f,1.0f))

漫射材料=白色; 環境材料=白色; 鏡面材質=白色* 0.5f;

漫射照明=白色* 0.8f; 環境照明=白色* 0.8f; 鏡面照明=白色* 0.5f; 鏡面功率= 48.0f;

謝謝大家的幫助

在您的頂點着色器中

V.cTex = V.cTex; 

這不應該是

V.cTex = cTex;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM