I have the same problem with converting the normalmapping shader to level meshes, however the texture and shadow are correct and you can see diffuse and specular lighting.
This is incorrect as you can see and I had to multiply the diffuse and specular by a lot to see them. If anyone knows how to fix this to work please help!
Here is the first pass of the shader:
texture entSkin1; //this is the shadow map
texture entSkin2; //this is the color map
texture mtlSkin1; //this is the normal map
sampler ColorMapSampler = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};
sampler ShadowMapSampler = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};
sampler BumpMapSampler = sampler_state
{
Texture = <mtlSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};
// -------------------------------------------------------------
// 2.0
// -------------------------------------------------------------
struct VS_OUTPUT0
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD1;
float3 View : TEXCOORD3;
float3 Light1 : TEXCOORD4;
float Att1 : TEXCOORD5;
float3 Light2 : TEXCOORD6;
float Att2 : TEXCOORD7;
float Fog : FOG;
};
VS_OUTPUT0 VS_PASS0(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD0 )
{
VS_OUTPUT0 Out = (VS_OUTPUT0)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position
// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);
Out.Tex = texcoord0.xy;
float3 PosWorld = mul(Pos, matWorld);
float3 Viewer = PosWorld - vecViewPos;
Out.View = mul(worldToTangentSpace, - Viewer); // V
//light 1
float3 Light1 = PosWorld - vecLightPos[0] ;
Out.Light1.xyz = mul(worldToTangentSpace, -Light1); // L
Out.Att1 = distance(PosWorld,vecLightPos[0])/vecLightPos[0].w; // Point light
//light 2
float3 Light2 = PosWorld - vecLightPos[1] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L
Out.Att2 = distance(PosWorld,vecLightPos[1])/vecLightPos[1].w; // Point light
float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
Out.Fog = ofog;
return Out;
}
struct PS_INPUT0
{
float2 Tex : TEXCOORD1;
float3 View : TEXCOORD3;
float3 Light1 : TEXCOORD4;
float Att1 : TEXCOORD5;
float3 Light2 : TEXCOORD6;
float Att2 : TEXCOORD7;
};
float4 PS_PASS0( PS_INPUT0 psInStruct ):COLOR
{
float4 color = tex2D(ColorMapSampler, psInStruct.Tex * 16); // fetch color map
color = color * 3 * tex2D(ShadowMapSampler, psInStruct.Tex);
float3 bumpNormal = 2 * (tex2D(BumpMapSampler, psInStruct.Tex * 16) - 0.5); // fetch bump map
float4 gloss = tex2D( BumpMapSampler, psInStruct.Tex );
float3 ViewDir = normalize(psInStruct.View);
//light1
float3 LightDir1 = normalize(psInStruct.Light1);
float4 diff1 = saturate(dot(bumpNormal, LightDir1)); // diffuse component
float shadow1 = saturate(4 * diff1);
float3 Reflect1 = normalize(2 * diff1 * bumpNormal - LightDir1); // R
float4 spec1 = pow(saturate(dot(Reflect1, ViewDir)), 15);
float4 Attenuation1 = saturate(dot(psInStruct.Att1, psInStruct.Att1));
//light2
float3 LightDir2 = normalize(psInStruct.Light2);
float4 diff2 = saturate(dot(bumpNormal, LightDir2)); // diffuse component
float shadow2 = saturate(4 * diff2);
float3 Reflect2 = normalize(2 * diff2 * bumpNormal - LightDir2); // R
float4 spec2 = pow(saturate(dot(Reflect2, ViewDir)), 15);
float4 Attenuation2 = saturate(dot(psInStruct.Att2, psInStruct.Att2));
return
(
(0.3 * color) + //ambient
((shadow1 * 100 *(color * 1000 * diff1 + (spec1*gloss.w * 1)) * (1 -Attenuation1))*vecLightColor[0])+
((shadow2 * (color * diff2 + (spec2*gloss.w)) * (1 -Attenuation2))*vecLightColor[1])
);
}