Hey guys. I am having a little trouble implementing per pixel lighting in OpenGL. The scene renders, however the geometry doesn't look smooth and looks more like GL_FLAT shiz form the fixed function pipe.
A screenshot so you can take a look see.
Here is the vert shader..
varying vec3 v_lightDir;
varying vec3 v_halfVec;
varying vec3 Normal;
varying vec4 Colour;
uniform int lightIndex;
void main()
{
v_lightDir = normalize( gl_LightSource[lightIndex].position.xyz );
v_halfVec = normalize( gl_LightSource[lightIndex].halfVector.xyz );
Normal = gl_NormalMatrix * gl_Normal;
Colour = gl_Color;
gl_Position = ftransform();
}
and here is the frag shader..
varying vec3 v_lightDir;
varying vec3 v_halfVec;
varying vec3 Normal;
varying vec4 Colour;
uniform float shininess;
uniform int lightIndex;
void main()
{
// Calculate Ambient
vec4 kAmbient = gl_LightSource[lightIndex].ambient * Colour;
// Process Light Direction and Normals
float NdotL = max( dot(Normal.xyz, v_lightDir ), 0.0 );
vec4 kColour = kAmbient;
// Add Diffuse and Specular if NdotL is greater than zero
if( NdotL > 0.0 )
{
// Calculate Diffuse
vec4 kDiffuse = ( 1.0 - kAmbient ) * ( gl_LightSource[lightIndex].diffuse * Colour);
vec4 kSpecular = gl_LightSource[lightIndex].specular;
float NdotHV = max( dot(Normal.xyz, v_halfVec ), 0.0 );
kColour += kDiffuse * NdotL;
kColour += kSpecular * pow( NdotHV, shininess );
}
// Write Pixel Colour
gl_FragColor = kColour;
}
It doesn't seem like the normal is getting interpolated across the surface to me. If you can give me any advice or spot something really stupid please let me know :)