Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 18 Sep 2010
Offline Last Active Nov 21 2012 03:03 PM

#4995515 Deferred shading - problems with normal map

Posted by on 30 October 2012 - 12:51 PM

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

Attached Thumbnails

  • lightmap_bug.jpg
  • lightmap_bug_normal.jpg