title: GLSL normal mapping shader issues
body: <p><strong>VC++ 2010, OpenGL, GLSL, SDL</strong></p>
  
  <p>So I am having two major problems. I am hoping to primarily address this first one being: The normal map shader I am using does not work with normals that are pointing in the positive or negative x direction. z and y seem to work just fine (testing the texture and normals on a cube).</p>
  
  <p><strong>edit</strong> : It does not seem to be normals in the x direction, because when I rotate the geometry, the front facing quad will still work. So it seems whatever was originally oriented facing the x doesnt work.</p>
  
  <p>Here is some simple test geometry:</p>
  
  <pre><code>glBegin(GL_QUADS);
      glNormal3f(0.0f, 0.0f, 1.0f);
      glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f, 0.0f, 1.0f);
      glTexCoord2f(0.0, 1.0); glVertex3f(-1.0f, 2.0f, 1.0f);
      glTexCoord2f(1.0, 1.0); glVertex3f(1.0f, 2.0f, 1.0f);
      glTexCoord2f(1.0, 0.0); glVertex3f(1.0f, 0.0f, 1.0f);
  glEnd();
  glBegin(GL_QUADS);
      glNormal3f(-1.0f, 0.0f, 0.0f);
      glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f, 0.0f, 1.0f);
      glTexCoord2f(0.0, 1.0); glVertex3f(-1.0f, 2.0f, 1.0f);
      glTexCoord2f(1.0, 1.0); glVertex3f(-1.0f, 2.0f, -1.0f);
      glTexCoord2f(1.0, 0.0); glVertex3f(-1.0f, 0.0f, -1.0f);
  glEnd();
  </code></pre>
  
  <p><strong>Vertex Shader</strong></p>
  
  <pre><code>#define MAX_LIGHTS 8
  #define NUM_LIGHTS 1
  
  varying vec3 lightVec[MAX_LIGHTS];
  varying vec3 viewVec;
  
  attribute vec4 glTangent4f;
  
  void main(void)
  {
      gl_Position = ftransform();
      gl_TexCoord[0] = gl_MultiTexCoord0;
  
      vec3 n = normalize(gl_NormalMatrix * gl_Normal);
      vec3 t = normalize(gl_NormalMatrix * glTangent4f.xyz);
      vec3 b = cross(n, t);
  
      vec3 v;
      vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
      int i;
      for (i=0; i&lt;NUM_LIGHTS; ++i)
      {
          vec3 lVec = gl_LightSource[i].position.xyz - vVertex;
          v.x = dot(lVec, t);
          v.y = dot(lVec, b);
          v.z = dot(lVec, n);
          lightVec[i] = v;
      }
  
      vec3 vVec = -vVertex;
      v.x = dot(vVec, t);
      v.y = dot(vVec, b);
      v.z = dot(vVec, n);
      viewVec = v;
  }
  </code></pre>
  
  <p><strong>Fragment Shader</strong></p>
  
  <pre><code>#define MAX_LIGHTS 8
  #define NUM_LIGHTS 1
  
  varying vec3 lightVec[MAX_LIGHTS];
  varying vec3 viewVec;
  
  uniform sampler2D colorMap;
  uniform sampler2D normalMap;
  
  void main (void)
  {
      vec2 uv = gl_TexCoord[0].st * 4.0;
      vec4 base = texture2D(colorMap, uv);
      vec4 final_color = vec4(0.2, 0.2, 0.2, 1.0) * base;
      vec3 vVec = normalize(viewVec);
      vec3 bump = normalize(texture2D(normalMap, uv).xyz * 2.0 - 1.0);
      vec3 R = reflect(-vVec, bump);
  
      int i;
      for (i=0; i&lt;NUM_LIGHTS; ++i)
      {
          vec3 lVec = normalize(lightVec[i]);
          float diffuse = max(dot(lVec, bump), 0.0);
          vec4 vDiffuse = gl_FrontLightProduct[i].diffuse * diffuse * base;
          final_color += vDiffuse;
  
          float specular = pow(clamp(dot(R, lVec), 0.0, 1.0), gl_FrontMaterial.shininess);
          vec4 vSpecular = gl_FrontLightProduct[i].specular * specular * diffuse;
          final_color += vSpecular;
      }
  
      gl_FragColor = final_color;
  }
  </code></pre>
  
  <p>The other problem (which I do not necessarily need to address right this moment) is the specular of the directional light seems to follow with the camera</p>