CS 435 Autumn 1998 --- Introduction to Interactive Graphics
Lights and Illumination
Colored Lights
The previous formulas assumed that we had white light.
The color of the light source will of course affect the
color of light reflected from a surface.
Remember, the color of an object is a function of the
incident wavelengths of light that it reflects.
Illumination with Colored Lights
To add colored lights to our illumination model, we simply
need to multiply each illumination component by the color of the light.
Diffuse and Ambient with colored lights
if (N · L) > 0
d_a.r = ka* object_color.r + kd(N · L) * object_color.r * light_color.r
d_a.g = ka* object_color.g + kd(N · L) * object_color.g * light_color.g
d_a.b = ka* object_color.b + kd(N · L) * object_color.b * light_color.b
Specular Illumination with colored lights
For our specular illumination, the color of the highlight
will now be the color of the light, so the formula gets changed as follows:
if (N · L > 0)
{
n_h = (MAX(0, (N · H) )spec_exp
spec.r = obj_ks[obj]*n_h * light_color.r;
spec.g = obj_ks[obj]*n_h * light_color.g;
spec.b = obj_ks[obj]*n_h * light_color.b;
}
final_color.r = MIN(1.0, (d_a.r + (light_color.r - d_a.r)*spec.r))
final_color.g = MIN(1.0, (d_a.g + (light_color.g - d_a.g)*spec.g))
final_color.b = MIN(1.0, (d_a.b + (light_color.b - d_a.b)*spec.b))
Multiple Lights
Multiple lights are very easy to implement.
All you need to do is to add the illumination from each
light source, making sure that you do not allow the final color values
to exceed 1.0 .
Other Light Effects
-
Directions lights:
Add a light center of interest for each light source.
Create the light direction vector as (light_coi - light_position).
Calculate the angle,
beta, between the light direction
vector and the vector from the light to the point being rendered.
Create a falloff of the light source using cos(beta)n.
-
Angle limited lights:
Add a angle of illumination of each light and check to
see if the the point being rendered is within this angular area.
if ( cos(gamma) > cos(beta) )
light_intensity = light_intensity * cosn(beta)
else
light_intensity=0
Examples of Lighting Effects
Single White Light Light |
|
Colored Lights |
|
|
|
Single Red Light Source |
Red Light Source plus a Blue Light Source |
Red Light Source, Green Light Source
Blue Light Source |
Angle and Fall-Off Effects |
|
|
|
Nomal Illumination |
Angular Fall-Off
with exponent = 800 |
Angular Cut-off (spotlight) |
Combination of Effects |
|
4 light sources of different colors and fall-offs |
David S. Ebert
November 1998