is the direction of the light source from the vertex.
is the direction of the camera from the vertex.
is the direction that the light would be reflected by the face.
1 2
| vec4 ambientTerm = gl_FrontLightProduct[0].ambient; |
The ambient term is always the same.
1 2 3
| vec4 diffuseTerm = gl_FrontLightProduct[0].diffuse * max(dot(normal, light), 0.0); diffuseTerm = clamp(diffuseTerm, 0.0, 1.0); |
The diffuse term depends on how aligned the face is with the light source; if the face's normal vector is in the same direction as the light source, it is fully lit. If it is perpendicular then is is not lit at all. The dot product essentially gives a measure of how aligned
and
are.
1 2 3
| vec4 specularTerm = gl_FrontLightProduct[0].specular * pow(max(dot(reflection, eyeCoords),0.0), 0.3 * gl_FrontMaterial.shininess); specularTerm = clamp(specularTerm, 0.0, 1.0); |
The specular term depends on how aligned the camera is with the reflected light. The calculation is similar to above except the effect is transformed with a power to adjust the size of the spot you see, so that a matt sphere would have a larger bright spot than a shiny one.
Hopefully that makes it a bit clearer, check out this wikipedia page too:
http://en.wikipedia.org/wiki/Diffuse_reflection