title: Normal Map Implementation.... am I missing something here?
body: <p>So, I have a light direction in World Space, and I calculate my normals per-vertex... I am however a little confused about my normal map implementation. Right now I'm doing this.</p>
  
  <pre><code>// Normal Map
  const float3 normalmap = (2.0f*gTextures1024.Sample(gLinearSam, float3(_in.Tex, gNormalMapIndex)).rgb) - 1.0f;
  const float3 NormalW = _in.Norm;
  const float3 TangentW = normalize(_in.TangentW.xyz - dot(_in.TangentW.xyz, _in.Norm)* _in.Norm);
  const float3 BitangentW = cross(NormalW, TangentW) * _in.TangentW.w;
  
  const float3x3 TBN = float3x3(TangentW, BitangentW, NormalW);
  
  float3 normal = normalize(mul(TBN, normalmap));
  // Lighting Calculations
  //float4 normal = normalize(float4(_in.Norm, 0.0f));
  float3 hvector = normalize(mul(-gDirLight.Direction.xyz, TBN) + gEyePos).xyz;
  //hvector = mul(hvector.xyz, TBN);
  float4 ambient  = gDirLight.Ambient * gMaterial.Ambient;
  float4 diffuse  = float4(0.0f, 0.0f, 0.0f, 0.0f);
  float4 specular = float4(0.0f, 0.0f, 0.0f, 0.0f);
  float4 texColor = float4(1.0f, 1.0f, 1.0f, 1.0f);
  
  [branch]
  if(gUseTextures)
      texColor = gTextures1024.Sample(gLinearSam, float3(_in.Tex, gDiffuseMapIndex));
  
  // diffuse factor
  float diffuseFactor = saturate(dot(normal, -gDirLight.Direction.xyz));
  [branch]
  if(diffuseFactor &gt; 0.0f)
  {
      diffuse = diffuseFactor * gDirLight.Diffuse * gMaterial.Diffuse;
      // Specular facttor &amp; color
      float HdotN = saturate(dot(hvector, normal));
      specular = gDirLight.Specular * pow(HdotN, gMaterial.Specular.w);
  }
  
  // Modulate with late add
  return (texColor * (ambient + diffuse)) + specular;
  </code></pre>
  
  <p>Am I doing something wrong here? According to me I am implementing the normal maps calculation in world space, and everything should be working just fine... Am I missing something here?</p>