Original Post
Can someone please help me. I cant seem to get my specular reflections on the bumpmap to come out correctly they keep moving whenever i move my view around( I would liek them to only move when i move the camera)
void NormalMap_Diffuse_VS2(float4 Pos : POSITION,float3 Normal : NORMAL,float2 Tex : TEXCOORD0,float3 Tan : TANGENT,
out float4 oPos : POSITION,
out float2 oTex : TEXCOORD0,
out float3 oLight1 : TEXCOORD1,
out float3 oView : TEXCOORD2,
out float4 ovPos : TEXCOORD3)
{
oPos = mul(Pos, matWorldViewProj);
ovPos = mul(Pos, matWorld);
float3x3 TanMatrix;
TanMatrix[0] = mul(Tan,matWorldView);
TanMatrix[1] = mul(cross(Normal,Tan),matWorldView);
TanMatrix[2] = mul(Normal,matWorldView);
float3 LightDir = mul(matWorldViewInv,Light1Pos-Pos);
oLight1 = mul(TanMatrix,LightDir);
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// I THINK THIS IS WHAT IS CAUSEING IT TO MOVE WHEN I DONT WANT IT TOO
// BUT IM NOT SURE
float3 EyeVec = normalize(vecEye );
oView = mul(matWorldViewInv,-Light1Pos) + EyeVec;
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// THIS LINE KEEPS THE LIGHT STILL BUT WONT REFLECT THE SPECULAR CORRECTLY
//oView = mul(vecEye.xyz-Pos, matWorld);
oTex = Tex;
}
float4 NormalMap_Diffuse_PS2(float2 Tex: TEXCOORD0,
float3 Light1: TEXCOORD1,
float3 View : TEXCOORD2,
float3 vPos : TEXCOORD3): COLOR
{
float4 Ambient = tex2D( g_samScene, Tex ) * 0.3f;
float3 vLight = normalize( float3( vPos - Light1Pos ) );
if( dot( vLight, -normalize(Light1Pos) ) > 0.78539816339744830961566084581988 ) // Light must face the pixel (within Theta)
{
float3 Normal = (tex2D(g_samBump,Tex));
Normal = (Normal) * 2 - 1;
float3 ViewVec = normalize(View);
Light1 = normalize(Light1);
float diff = saturate(dot(Normal, Light1));
float3 R = normalize(2 * diff * Normal - (Light1));
float spec = max(dot(R,ViewVec),0);
float SelfShadow = saturate(4*diff);
float4 specular = SelfShadow*pow(spec,Shinyness) * (Scolor*Sintensity) ;
float4 Diffuse = SelfShadow*diff*Light1Color;
//return Ambient + ( tex2D( g_samScene, Tex ) * (Diffuse+specular));
//return Diffuse+specular;
//return Diffuse;
return (tex2D( g_samScene, Tex )*0.3) + specular;
}
else
return Ambient;
}