OpenGL approximates light and lighting, breaking it into red, green, and blue components. Thus, the color of a light source is characterized by the amount of red, green, and blue light it emits. Furthermore, the material of a surface is characterized by the percentage of the incoming red, green, and blue components that is reflected in various directions.
In the OpenGL lighting model, the light in a scene comes from several light sources. Some light comes from a particular position, and some light is scattered throughout 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 bounces off one, two, three or more walls. This bounced light is called ambient light, which seems to come from no particular direction but disappears if the light source is turned off. You can modify this light by setting the Ambient color property of the LightSource object. There may also be a global 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. You can control this global ambient light by modifying the GlobalAmbientLight color property of the LightModel object.
In the OpenGL lighting model, 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, scatter some light, or reflect light in a desired direction like a mirror.
In general, OpenGL represents lighting with four independent components: emissive, ambient, diffuse, and specular. All four are computed independently and then added together.
Ambient light as already mentioned is the light scattered so much that its original light source is impossible to determine.
Diffuse light comes from a particular direction, so it is brighter if it comes squarely down on a surface than if it barely glances off the surface. But once it hits the surface, it is scattered equally in all directions. You can modify the diffuse component of a particular light source by modifying the Diffuse color property of the LightSource object.
Specular light comes from a particular direction and bounces off a surface in a preferred direction. You can modify the specular component of a particular light source by modifying the Specular color property of the LightSource object.
In addition, you can modify the attenuation factors for every light source. In the real world, the intensity of light decreases as distance from the light increases. You can control this process by modifying the ConstantAttenuation, LinearAttenuation, and QuadraticAttenuation properties of the LightSource object. OpenGL attenuates a light source by multiplying the contribution of that light source by an attenuation factor using the following formula:
Attenuation factor = 1 / (KC + KL * D + KQ * D * D)
where KC is Constant Attenuation, KL is Linear Attenuation, KQ is Quadratic Attenuation, and D is the distance from the light source to the object.
On the other hand, materials are characterized by the percentages of light they reflect from different light components. You can modify these percentages by changing the values of the Ambient, Diffuse, and Specular properties of the FillEffect object attached to almost every object in the chart. In addition to this, materials can also emit light. You can modify the emissive light of a material by changing the value of the Emissive property of the FillEffect object. By default this value is RGB(0, 0, 0), which means that the object does not emit any light.
At this point, there may be some confusion: when we changed the fill effect in the previous chapters we did not touch any of these properties, and yet the chart still displays nicely when lighting is turned on. The reason for this behavior is that the FillEffect object automatically modified the material properties according to the current type of fill effect. For example, when you assign a solid color to the fill effect via the SetSolidColor function, FillEffect modifies the Ambient and Diffuse colors "behind the scenes" to match the specified color. This ensures that when you turn lighting on, the object will have the same color. When you assign an image, gradient, pattern or advanced gradient, these two colors are modified to White. So in general you'll seldom need to modify the material properties because they've already been assigned by the control.
Related Examples
Windows Forms: Lights\General