hey guys i am having trouble rendering textures through shaders. I really don't know why, the shader file just implements a simple phong lighting and interpolate the texture on a simple quad but all i am getting is the lighting and material colors, as if there is no texture(the texture is a Stone texture but all i am getting is white color)
here is the shader file
//------------------------------------
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, EyeVe开发者_如何学编程c), 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();
}
}
the lighting and material colors are as follows: (P.S : WHITE = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f))
Diffuse Material = WHITE; Ambient Material = WHITE; Specular Material = WHITE * 0.5f;
Diffuse Lighting = WHITE * 0.8f; Ambient Lighting = WHITE * 0.8f; Specular Lighting = WHITE * 0.5f; Specular Power = 48.0f;
Appreciate the help, guys
In your vertex shader you have
V.cTex = V.cTex;
Shouldn't this be
V.cTex = cTex;
精彩评论