Original Post
Hello,
I'm implementing a deferred shading renderer based on OpenGL. I got everything setup and lighting seems to work but I can't figure out why the light is appearing on the faces that should be completely dark.
For non-normal-mapped objects everything works fine. So I guess there is something wrong with my tangent-space normalmaps.
Here's the code for generating g-buffer-normal-map (in view-space):
[source lang="cpp"]Vertex Shader:
normal = normalize(gl_NormalMatrix * gl_Normal);
vec3 t = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz);
vec3 b = cross(normal,t);
TBN = mat3(t,b,normal);
Fragment Shader:
vec3 n = (texture2D(normalMap,gl_TexCoord[0].st).rgb-0.5)*2;
n = normalize(TBN * n);
gl_FragData[2] = vec4((n+1)*0.5,1); [/source]
Even if I only display dot(normal,lightdir) I get light artifacts on the faces the light shouldn't reach ...
Here are images of the "final" lightmap render and the normalmap from the g-buffer.
Thanks for your help
I'm implementing a deferred shading renderer based on OpenGL. I got everything setup and lighting seems to work but I can't figure out why the light is appearing on the faces that should be completely dark.
For non-normal-mapped objects everything works fine. So I guess there is something wrong with my tangent-space normalmaps.
Here's the code for generating g-buffer-normal-map (in view-space):
[source lang="cpp"]Vertex Shader:
normal = normalize(gl_NormalMatrix * gl_Normal);
vec3 t = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz);
vec3 b = cross(normal,t);
TBN = mat3(t,b,normal);
Fragment Shader:
vec3 n = (texture2D(normalMap,gl_TexCoord[0].st).rgb-0.5)*2;
n = normalize(TBN * n);
gl_FragData[2] = vec4((n+1)*0.5,1); [/source]
Even if I only display dot(normal,lightdir) I get light artifacts on the faces the light shouldn't reach ...
Here are images of the "final" lightmap render and the normalmap from the g-buffer.
Thanks for your help