OpenGL Lighting

 

If you’ve tried using the GLUT solid objects so far, you have noticed that they turn out to be big colored blobs on the screen. This is because you have given them no knowledge of lighting behaviors.

The typical computer graphics lighting model is based on the diagram below:

 

 


 

 

 

 

 

 

 

The light has 3 color components: red, green, and blue. The object material’s ability to reflect light has 3 components: red, green, and blue. These are pairwise multiplied for ambient, diffuse, and specular to see how much of each component is re-transmitted by the object.

Red = LR*MR;

Green = LG*MG;

Blue = LB*MB;

These three equations are performed separately for ambient, diffuse, and specular. The diffuse product is then multiplied by cos(q) and the specular component is multiplied by coss(f).

If there is one light and one material, the following things can be set independently:

• Global scene ambient red, green, blue

• Light ambient red, green, blue

• Material ambient red, green, blue

• Light diffuse red, green, blue

• Material diffuse red, green, blue

• Light specular red, green, blue

• Material specular red, green, blue

• Material specular shininess

• Light position: x, y, z

This makes for 25 things that can be set for just one light and one material! While many combinations are possible, some make more sense than others.

 

Ways to Simplify Too Many Options

1. Set the ambient light globally using glLightModelfv( GL_LIGHT_MODEL_AMBIENT, *). Set it to some low intensity of white.

2. Set the light’s ambient component to zero.

3. Set the light’s diffuse and specular components to the full color of the light.

4. Set each material’s ambient and diffuse to the full color of the object.

5. Set each material’s specular component to some fraction of the light color.