Notes for February 13 class -- Phong shading

Phong model for specular reflection

The first really interesting model for surface reflection was developed by Bui-Tong Phong in 1973. Before that, computer graphics surfaces were rendered using only diffuse lambert reflection. Phong's was the first model that accounted for specular highlights.

The Phong model begins by defining a reflection vector R, which is a reflection of the direction to the light source L about the surface normal N.

As we showed in class, and as you can see from the diagram on the right, it is given by:

R = 2 (N • L) N - L
Once R has been defined, then the Phong model approximates the specular component of surface reflectance as:
srgb max(0, E • R)p )
where srgb is the color of specular reflection, p is a specular power, and E is the direction to the eye (in our case, E = -W, the reverse of the ray direction). The larger the specular power p, the "shinier" the surface will appear.

We can have more than one light. To get the complete Phong reflectance, we sum over the lights in the scene:

argb + i lightColori ( drgb max(0, N • Li) + srgb max(0, E • R) p )
where argb, drgb and srgb are the ambient, diffuse and specular color, respectively, and p is the specular power.


Mirror reflection

You can also implement mirror reflection by mixing in the result of forming a reflection ray (V',W'):
W' = reflect -W about N

V' = S + ε W'

where S is the point on the sphere surface and ε is a small positive number such as 0.001.


At the end of the class we saw a video:

The 2012 film The Centrifuge Brain Project.

Homework (due before class on Tuesday Feb 20)

  • Implement the Phong reflectance model.

  • Using your ray tracing code from last class, and using the sample code included in these course notes, incorporate Phong shading.

    In this version of the library code, I have included the noise function. Feel to use noise anywhere in your code, as we did in class, to create interesting textures and shading effects.

    You should do this with the x,y,z,r that define each sphere.

    Feel free to play with light color, as well as the properties that control surface material: ambient color, diffuse color, specular color and specular power.

  • If you haven't done so yet, implement multiple spheres. At each pixel, your ray tracer should render the nearest sphere (if any).

  • Extra credit:
    • Implement mirror reflection, so that one sphere can be seen as a mirror reflection in another.

    • Try using noise to modify normal vector N. That can look especially cool when combined with mirror reflection.

    • See whether you can figure out how to make a different material for each sphere in the scene.

  • See if you can make something cool and fun, try to make it animated.