title: Using a tangent-space normal map with world-space normals
body: <p>I'm working on deferred shading in GLSL. I have all of my model normals in world space, and the positions as well. The whole thing is working exactly as it should with just the world-space normals of the polygons, but I'm unsure of how to add normal mapping. I know it's recommended to do lighting in view-space, and I've tried that but I couldn't get even a quarter as far with that as I have with world-space. All I have left to fix now is adding normals. I have a regular normal map, which is in tangent-space. I've tried the following:</p>
  
  <ol>
  <li><p>Multiplying the world-space normal by the normal-map didn't seem to work.</p></li>
  <li><p>I tried adding the normal-map's normals, even though I knew that wouldn't work.</p></li>
  </ol>
  
  <p>At this point I'm not really sure what else to try. Is there any easy way to do this?</p>
  
  <p>Normal-rendering frag shader:</p>
  
  <pre><code>#ifdef NORMALMAP
  uniform sampler2D m_Normals;
  #endif
  
  varying vec3 normal;
  varying vec2 texCoord;
  
  void main() {
      vec3 normals;
      #ifdef NORMALMAP
          normals = normalize(normal * (texture(m_Normals, texCoord).xyz));
      #else
          normals = normal;
      #endif
      gl_FragColor = vec4(normals, 1.0);
  }
  </code></pre>
  
  <p>The variable "normal" is the world-space normal passed in from the vertex shader.</p>