Implementing Phong Specular Illumination

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
           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
        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:

Examples of illumination types

Ambient Illumination  Diffuse plus Ambient Illumination  Specular plus Diffuse plus 
Ambient Illumination 

David S. Ebert