Notes for February 16 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.

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.
 

 

Plumbing:

We wrote some code together in class, to start converting variables to uniform variables. You will use that code, which is here, as the basis for your homework.

 

At the end of the class we saw a video:

The 1986 classic Pixar film Luxo JR, directed by John Lasseter.
 

Homework (due before class on Tuesday Feb 23)

  • Implement the Phong reflectance model.

  • Using the sample code included in these course notes, change the shader properties that affect appearance to uniform variables, just as we did in class with light direction.

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

    You should also do this 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:
    • See whether you can figure out how to make a different material for each sphere in the scene. Hint: You can try using an array of ambient, an array of diffuse, etc.

  • As always, make something cool and fun, try to create something interactive and/or animated. You will now have lots more things to animate, since you will be able to control the values of many uniform variables from the Javascript level.