I'm trying to create a normal mapped cylinder (dx 9 btw) with simple diffuse + ambient light.But what im getting is this ......The part which is facing the light is getting uniformly lit and the part which is away from it is only shaded with the ambient term , and there is an abrupt transition between the two , not a continous one.And the part which is getting lit is simply getting lit , seems as if the normal map isnt working . I've attached the screen shot below(sorry but i cant seem to open imageshack on my college net and i dont know of any other site)
And also , im not using effect files(once again ) but separate pixel and vertex shaders.
the vertex shader
matrix world,view,proj;
matrix worldviewproj,viewproj;
matrix worldInv,rotation;
float4 LDir = {1.0f,0.0f,0.0f,0.0f};
vector EyePos;
struct input
{
vector position : POSITION0;
float3 tangent : TANGENT0;
float3 binormal : BINORMAL0;
float3 normal : NORMAL0;
float2 texcoord : TEXCOORD0;
};
struct output
{
vector position : POSITION0;
float2 texcoord : TEXCOORD0;
float3 toEye : TEXCOORD1;
float3 LDir : TEXCOORD2;
};
output VSMain(input ip)
{
float3x3 TBN;
TBN[0] = ip.tangent;
TBN[1] = ip.binormal;
TBN[2] = ip.normal;
float3x3 TSpace = transpose(TBN); //setup the object to tangent space matrix
output op = (output)0;
worldviewproj = mul(mul(world,view),proj);
op.position = mul(ip.position,worldviewproj);
EyePos = mul(EyePos,worldInv); // transform the eye pos from world space to object space
vector toEye = EyePos - ip.position;
op.toEye = mul(toEye,TSpace); //transform to tangent space
op.texcoord = ip.texcoord*4.0f; // pass the tiled texture coordinates
LDir = mul(LDir,rotation);
LDir = mul(LDir,worldInv); //transform light direction from world to object space
op.LDir = mul(LDir,TSpace); // transform to tangent space
return op;
}
the pixel shader
float4 LAmb = {0.3f,0.3f,0.3f,0.0f},LDff = {1.0f,1.0f,1.0f,0.0f};
float4 Mtrl = {1.0f,1.0f,1.0f,0.0f};
sampler Tex;
sampler NMap;
struct input
{
float2 TexC : TEXCOORD0;
float3 toEye : TEXCOORD1;
float3 LDir : TEXCOORD2;
};
struct output
{
float4 color : COLOR0;
};
output PSMain(input ip)
{
output op = (output)0;
ip.toEye = normalize(ip.toEye);
ip.LDir = normalize(ip.LDir);
float3 normal = tex2D(NMap,ip.TexC); //sample the normal mal
normal = 2.0f*normal - 1.0f;
normal = normalize(normal);
float s = max(dot(ip.LDir,normal),0.0f);
vector a = tex2D(Tex,ip.TexC); //get the texture color
op.color = a*Mtrl*(LAmb + (LDff * s));
return op;
}
Note : you'll see that even though im not doing any specular calculation , ive still included the toEye term,thats because earlier i had included the specular term but then omitted it since i couldnt get even the diffuse to work so decided to fix it first
thanks in advance
manpreet