CS 435 Autumn 1997 --- Introduction to Interactive Graphics
Implementing Phong Specular Illumination
Phong Specular Illumination Formula for Intensity (from class notes, pg. 8-12)
da=Iaka + Ipkd
(N · L )
I=da + (1-da)Ipks
(N · H)n
Add specular if N · L > 0 and N · H > 0
Object Color and Illumination
Now we need to add color into this intensity calculation. The diffuse
and ambient intensity is multiplied by the color of the
object. Specular illumination is affected by the color of the
light, not the object in the simple model. (The color of the
light actually affects all components.)
n_l = (N · L)
if (n_l > =0.0)
da = obj_amb[obj] + obj_kd[obj]*n_l
else
da = obj_amb[obj]
d_a.r = da*obj_color[obj].r
d_a.g = da*obj_color[obj].g
d_a.b = da*obj_color[obj].b
spec.r=spec.g=spec.b=0;
if (n_l > 0)
{
n_h = pow(MAX(0, (N · H)), obj_specexp[obj])
spec.r = obj_ks[obj]*n_h
spec.g = obj_ks[obj]*n_h
spec.b = obj_ks[obj]*n_h
}
final_color.r = MIN(1.0, (d_a.r + (1-d_a.r)*spec.r))
final_color.g = MIN(1.0, (d_a.g + (1-d_a.g)*spec.g))
final_color.b = MIN(1.0, (d_a.b + (1-d_a.b)*spec.b))
Faceted Shading:
- Create a structure to hold the user selected color of
each object (obj_color[obj])
- Create a structure to hold the final color after
illumination of each polygon (face_color[obj][face] )
Set face_color[obj][face]= final_color.
Examples of illumination types
David S. Ebert
Sun Nov 16 01 11:19:09 EST 1997