2011-03-10 120 views
1

嘿傢伙 我無法通過着色器渲染紋理。我真的不知道爲什麼,着色器文件只是實現了簡單的phong照明,並在簡單的四邊形上插入了紋理,但我得到的是燈光和材質顏色,就好像沒有紋理一樣(紋理是石材紋理但所有我得到是白色)Direct3D中的紋理映射問題

這裏着色器文件

//------------------------------------ 
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:WHITE = D3DXCOLOR(1.0F,1.0F,1.0F ,1.0f))

Diffuse Material = WHITE; Ambient Material = WHITE; Specular Material = WHITE * 0.5f;

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

感謝幫助,夥計們

回答

1

在你的頂點着色器,你有

V.cTex = V.cTex; 

不應該這個是

V.cTex = cTex; 
+0

織補,我忘了這一個,我經過一個空的紋理一直以來。謝謝 – DBoxer 2011-03-10 18:14:36