When you look at a physical surface, your eye's perception of the color depends on the distribution of
photon energies that arrive and trigger your cone cells. (See "Color Perception" in Chapter 4.) Those
photons come from a light source or combination of sources, some of which are absorbed and some of
which are reflected by the surface. In addition, different surfaces may have very different properties -
some are shiny and preferentially reflect light in certain directions, while others scatter incoming light
equally in all directions. Most surfaces are somewhere in between.
OpenGL approximates light and lighting as if light can be broken into red, green, and blue components.
Thus, the color of light sources is characterized by the amount of red, green, and blue light they emit, and
the material of surfaces is characterized by the percentage of the incoming red, green, and blue
components that is reflected in various directions. The OpenGL lighting equations are just an
approximation but one that works fairly well and can be computed relatively quickly. If you desire a
more accurate (or just different) lighting model, you have to do your own calculations in software. Such
software can be enormously complex, as a few hours of reading any optics textbook should convince
you.
In the OpenGL lighting model, the light in a scene comes from several light sources that can be
individually turned on and off. Some light comes from a particular direction or position, and some light
is generally scattered about the scene. For example, when you turn on a light bulb in a room, most of the
light comes from the bulb, but some light comes after bouncing off one, two, three, or more walls. This
bounced light (called ambient) is assumed to be so scattered that there is no way to tell its original
direction, but it disappears if a particular light source is turned off.
Finally, there might be a general ambient light in the scene that comes from no particular source, as if it
had been scattered so many times that its original source is impossible to determine.
In the OpenGL model, the light sources have an effect only when there are surfaces that absorb and
reflect light. Each surface is assumed to be composed of a material with various properties. A material
might emit its own light (like headlights on an automobile), it might scatter some incoming light in all
directions, and it might reflect some portion of the incoming light in a preferential direction like a mirror
or other shiny surface.
The OpenGL lighting model considers the lighting to be divided into four independent components:
emissive, ambient, diffuse, and specular. All four components are computed independently and then
OpenGL Programming Guide (Addison-Wesley Publishing Company)
http://heron.cc.ukans.edu/ebt-bin/nph-dweb/dynaw...@Generic__BookTextView/10431;cs=fullhtml;pt=9601 (4 of 35) [4/28/2000 9:45:36 PM]
added together.
Ambient, Diffuse, and Specular Light
Ambient illumination is light that's been scattered so much by the environment that its direction is
impossible to determine - it seems to come from all directions. Backlighting in a room has a large
ambient component, since most of the light that reaches your eye has first bounced off many surfaces. A
spotlight outdoors has a tiny ambient component; most of the light travels in the same direction, and
since you're outdoors, very little of the light reaches your eye after bouncing off other objects. When
ambient light strikes a surface, it's scattered equally in all directions.
The diffuse component is the light that comes from one direction, so it's brighter if it comes squarely
down on a surface than if it barely glances off the surface. Once it hits a surface, however, it's scattered
equally in all directions, so it appears equally bright, no matter where the eye is located. Any light
coming from a particular position or direction probably has a diffuse component.
Finally, specular light comes from a particular direction, and it tends to bounce off the surface in a
preferred direction. A well-collimated laser beam bouncing off a high-quality mirror produces almost
100 percent specular reflection. Shiny metal or plastic has a high specular component, and chalk or
carpet has almost none. You can think of specularity as shininess.
Although a light source delivers a single distribution of frequencies, the ambient, diffuse, and specular
components might be different. For example, if you have a white light in a room with red walls, the
scattered light tends to be red, although the light directly striking objects is white. OpenGL allows you to
set the red, green, and blue values for each component of light independently.
Material Colors
The OpenGL lighting model makes the approximation that a material's color depends on the percentages
of the incoming red, green, and blue light it reflects. For example, a perfectly red ball reflects all the
incoming red light and absorbs all the green and blue light that strikes it. If you view such a ball in white
light (composed of equal amounts of red, green, and blue light), all the red is reflected, and you see a red
ball. If the ball is viewed in pure red light, it also appears to be red. If, however, the red ball is viewed in
pure green light, it appears black (all the green is absorbed, and there's no incoming red, so no light is
reflected).
Like lights, materials have different ambient, diffuse, and specular colors, which determine the ambient,
diffuse, and specular reflectances of the material. A material's ambient reflectance is combined with the
ambient component of each incoming light source, the diffuse reflectance with the light's diffuse
component, and similarly for the specular reflectance and component. Ambient and diffuse reflectances
define the color of the material and are typically similar if not identical. Specular reflectance is usually
white or gray, so that specular highlights end up being the color of the light source's specular intensity. If
you think of a white light shining on a shiny red plastic sphere, most of the sphere appears red, but the
shiny highlight is white.
In addition to ambient, diffuse, and specular colors, materials have an emissive color, which simulates
light originating from an object. In the OpenGL lighting model, the emissive color of a surface adds
OpenGL Programming Guide (Addison-Wesley Publishing Company)
http://heron.cc.ukans.edu/ebt-bin/nph-dweb/dynaw...@Generic__BookTextView/10431;cs=fullhtml;pt=9601 (5 of 35) [4/28/2000 9:45:36 PM]
intensity to the object, but is unaffected by any light sources. Also, the emissive color does not introduce
any additional light into the overall scene.
RGB Values for Lights and Materials
The color components specified for lights mean something different than for materials. For a light, the
numbers correspond to a percentage of full intensity for each color. If the R, G, and B values for a light's
color are all 1.0, the light is the brightest possible white. If the values are 0.5, the color is still white, but
only at half intensity, so it appears gray. If R=G=1 and B=0 (full red and green with no blue), the light
appears yellow.
For materials, the numbers correspond to the reflected proportions of those colors. So if R=1, G=0.5, and
B=0 for a material, that material reflects all the incoming red light, half the incoming green, and none of
the incoming blue light. In other words, if an OpenGL light has components (LR, LG, LB), and a
material has corresponding components (MR, MG, MB), then, ignoring all other reflectivity effects, the
light that arrives at the eye is given by (LR*MR, LG*MG, LB*MB).
Similarly, if you have two lights that send (R1, G1, B1) and (R2, G2, B2) to the eye, OpenGL adds the
components, giving (R1+R2, G1+G2, B1+B2). If any of the sums are greater than 1 (corresponding to a
color brighter than the equipment can display), the component is clamped to 1.
|