# Deferred Rendering and Normal Mapping

I'm working on a deferred renderer and need a bit of help getting normal maps working. What I've been doing with them so far is just multiplying the normal texture with the object normals (gl_NormalMatrix * gl_Normal). That appears to be wrong.

I just need someone to explain how I can add the normal map the the normal gbuffer.

The offending line:

    vec3 normal = Normal * texture2D(normalTexture, gl_TexCoord[0]).rgb;


Edit: I managed to get it working :)

Solution:

vec3 Normal = normalize(gl_NormalMatrix * gl_Normal);
vec3 Tangent = normalize(gl_NormalMatrix[0]);
vec3 Binormal = normalize(gl_NormalMatrix[1]);
mat3 tangentToWorld = mat3(Tangent.x, Binormal.x, Normal.x,
Tangent.y, Binormal.y, Normal.y,
Tangent.z, Binormal.z, Normal.z);


and

vec3 normal = (texture2D(normalTexture, gl_TexCoord[0]).rgb * 2.0 - 1.0) * tangentToWorld;