Hi, I’ve managed to implement the diffuse lighting but I can’t get the specular lighting right. I’ve the following code:
vertex shader
varying vec3 normal, eyeVec;
void main()
{
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
normal = normalize(gl_NormalMatrix * gl_Normal);
eyeVec = -vec3(gl_ModelViewMatrix * gl_Vertex);
}
fragment shader
varying vec3 normal, eyeVec;
vec4 light0 ()
{
vec4 color;
vec3 lightDir = normalize(vec3(gl_LightSource[0].position));
vec3 eyeVecNormal = normalize(eyeVec);
vec3 reflectVec = normalize(-reflect(lightDir, normal));
vec4 ambient = gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
vec4 diffuse = gl_LightSource[0].diffuse * max(dot(normal,lightDir),0.0) * gl_FrontMaterial.diffuse;
vec4 specular = gl_FrontMaterial.specular * pow(max(dot(reflectVec, eyeVecNormal), 0.0), gl_FrontMaterial.shininess);
color = ambient + diffuse + specular;
return color;
}
void main()
{
gl_FragColor = light0;
}
When I added the specular light, instead of making a shiny spot in the middle of the object, the spot in the middle is unchanged and the rest is made black. It’s a directional lightsource, the lightsource itself doesn’t have any position. Anyone know what the problem is?