Tutorial 4: Simple Lighting

Here, we limit ourselves to doing fixed function lighting. OpenGL has built in support for the phong lighting equation. Phong is surprisingly versatile, but unfortunately tends to give everything a plastic like look.

The phong lighting equation is made up of 4 parts, emissive, ambient, diffuse, and specular. Emissive is how much an object glows. This is a local effectand will not illuminate other objects in your scene. Ambient is a global ambient term, because OpenGL does not have a global lighting solution, your scene will tend to be too dark, ambient is a way to get around that deficiency. Diffuse lighting is the unshiny part of an object. That is, the intensity of point on the surface does not change relative to the viewers position. For example, most cotton clothing would be almost all diffuse. Specular is the shiny part of a reflection, it is sort of like glare, or your ability to see the light on the object. This does change with respect to the viewing angle.

Emissive and ambient are one time gains on the surface, whereas diffuse and specular are determined for every light in the scene.

In general, lighting in computer graphics is tricky and something of a black art. One of the reasons that lighting is so tough is because in reality, our eye can make order of magnitude adjustments to light intensity, whereas in computer graphics we are stuck on a fixed exposure, 0.0-1.0 range for three color bands. The computer simulation is a long way away from being an accurate model of how light interacts with surfaces, but on the other hand, what we have in OpenGL has the benefit of being tractable. The other reason lighting is messed up in computer graphics is because human perception is really screwy. If you don't believe me, check out this link.

In order for OpenGL to properly light our surface, we must send down surface normals with our geometry.

Links