Skip to main content
gamedev.net
🔒 Locked

GLSL: Smooth Normal Mapping

Started by stramit Jan 22, 2007 at 10:23 PM 3 replies 2.3k views
Original Post
stramit
stramit
Hey guys, I have recently been experimenting with normal mapping and have had a moderate degree of success. So far I can get my model mapped, and the lighting equation to look 'right', at least to a degree. The problem I am having is that it doesn't seem the shader I am using is correctly interpolating the vertex normal values across the face of the polygon. bad normals I am pretty sure the problem would be the result of the vertex shader I am using and not the fragment shader. This is based off a tutorial I found online. I am sure that the normal values I am using are correct as if I use a standard per pixel shader the objects look 'smooth'.

varying vec3 lightDir;
varying vec3 viewDir;

void main()
{
   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
   gl_TexCoord[0] = gl_MultiTexCoord0;

   vec3 vertexPos = vec3(gl_ModelViewMatrix * gl_Vertex);

   vec3 t = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz);
   vec3 b = normalize(gl_NormalMatrix * gl_MultiTexCoord2.xyz);
   vec3 n = normalize(gl_NormalMatrix * gl_Normal);

   mat3 tbnMatrix = mat3(t, b, n);

   lightDir = gl_LightSource[0].position.xyz - vertexPos;
   lightDir *= tbnMatrix;

   viewDir = -vertexPos;
   viewDir *= tbnMatrix;
}


The t,b,n vectors are all the average of the faces connected to that vertex. Any help in smoothing this baby out would be much appreciated.
stramit
stramit
I figured it out guys, after I calculated the tbn for each vertex I was passing it incorrectly to the vertex constructor. I was passing the same T and B for for each vertex, but changing the N. That's why is looked 'right' on normal shading the N was correct.

Damn copy and paste errors... sorry for wasting every bodies time.
AIRmichael
AIRmichael
Can I see a new screenshot just for fun? If you have time:)
stramit
stramit
No worries

good normals


Now for parallax mapping

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.