CHAPTER 6:    SHADING

The Phong Reflection Model:

 Phong Model for Specular Reflection

 Phong Reflection Model

 Phong Reflection Model

 BRDF and PHONG

The Bidirectional Reflection Distribution Formula (BRDF) describes the behavior of light as it reflects of a particulat surface.  It relates incoming light energy in direction to outgoing intensity in direction.  It accounts for the angle of incidence, the icident wavelength, the properties of teh surface material, etc.  BRDF can be split into components.
Specular
Directional Diffuse
Ideal Diffuse

Blue represents incoming light, green, the resulting BRDF cmponent
The specular component is a mirror-like reflction, where the reflected angle is the same as the incident angle of the incoming light.  In specular reflection, reflection is stronger in one viewing direction, i.e., there is a bright spot called a specular highlight, readily apparent on shiny surfaces.  For an ideal reflector, the angle of incidence equals the angle of specular reflection.  If R is the direction of specular reflection, and V is the direction of the viewer, then for an ideal reflector, the specular reflection is visible only when V and R coincide.  For real objects (not perfect reflectors), the specular reflection can be seen even if V and R do not coincide, i.e., it is visible over a range of values.  The shinier the surface, the smaller the range for specular visibility.

Phong Bui-Tuong observed that for very shiny surfaces, the specular highlight was small and the intensity fell off rapidly, while for duller surfaces, it was lagrer, and fell off more slowly.  Reflected intensity is a function of (cos a)n with n >= 200 for a shiny surface and n small for a dull surface. For a perfect reflector n equals infinity, and for a piece of cardboard n equals 0 or 1. In the diagram below we can see how the function (cos a)n behaves for different values of n.
Behavior of (cos a)n for different values of n

Specular reflection is also a function of the light incidence angle q. An example is glass which has almost no specular reflectance
for q = 0 degrees but a very high specular reflectance for q > 80 degrees. Some substances, such as copper, actually change
color with change in the incidence angle, as shown in the following plot of the reflectance curve as a function of the incident
angle for copper. .

A full specular reflectance function is the Bi-directional Reflectance Distribution Function (BRDF). For glass the BRDF at 0
degrees incidence equals 0 and for light incident at 90 degrees, it equals 1. Since for many materials the BRDF is approximately
constant, Phong called this term the specular coefficient (ks) and assumed it was constant. Then, since cos a = V·R, a
complete illumination intensity model for reflection including diffuse reflection from ambient light and a point light source, and the
Phong model for specular reflection is:

I = ka * Ia + kd * Ii * (N·L) + ks * Ii * (V·R)n

I = total intensity
Ia = ambient intensity
Ii = light source intensity
ka, kd, ks = empirical coefficients
N = surface normal
L = light direction vector
V = viewing direction vector
R = Reflection vector
n = speculation-reflection parameter

For color there will be versions of the above equation for Red, Green, and Blue components. The coefficient of specular
reflection ks is usually not the same as the coefficient of diffuse reflection kd or the ambient reflection ka. The assumption is
often made that the specular highlights are determined by the color of the light source, not the material, e.g.,  ksR = ksG = ksB
= 1.0 This is true of plastic which is why many computer graphics images appear to be plastic.

Lambert's Law:

A lambertian surface is a surface of perfectly matte properties, which means that it adheres to Lambert's cosine law.

                  Lambert's cosine law states that the reflected or transmitted luminous intensity in any
                  direction from an element of a perfectly diffusing surface varies as the cosine of the angle
                  between that direction and the normal vector of the surface. As a consequence, the
                  luminance of that surface is the same regardless of the viewing angle.

Lambert's Cosine Law 
 

Lambert's cosine law states that the intensity of radiation along a direction which has angle  with the normal to the surface is:

where In is the intensity of radiation in normal direction.

Gouraud Shading:
 

                         The vast majority of 3-D objects created for computer games are made up of polygons. A polygon
                         is an area defined by lines. To have a polygon, you must have at least three lines.

                                     A simple triangular polygon. Each point of the triangle is a vertex.
 

                         The lines connect a series of coordinates in the three-dimensional "space" the computer creates. The
                         point where the lines connect in known as a vertex. Each vertex has X, Y and Z coordinates.

                              X determines the position relative to right or left in the virtual space
                              Y determines the position relative to top or bottom in the virtual space
                              Z determines the position relative to front or back in the virtual space

                         Once each polygon has a set of vertices to define its shape, it needs information that tells it what to look
                         like. There are four common ways to do this:

                              Flat shading
                              Gouraud shading
                              Phong shading
                              Texture mapping

                         Flat shading simply assigns a single color to a polygon. It is very simple and fast, but makes the object
                         look very artificial. Gouraud shading is more involved. Colors are assigned to each vertex, then they are
                         blended across the face of the polygon. Since each vertex is typically associated with at least three
                         distinct polygons, this makes the object look natural instead of faceted. Look at this example:

                                        The same object with flat and Gouraud shading applied.
 

                         You will notice that the ball with Gouraud shading appears much smoother than the flat shaded one. But
                         look closely at the outlines of the two balls. That is where you can tell that both balls have the exact same
                         number of polygons!

                         A more complex version of shading, Phong, is rarely used in games. Where Gouraud shading
                         interpolates colors by averaging between the vertices, Phong shading averages each pixel based on the
                         colors of the pixels adjacent to it.

                         Another common technique for determining the appearance of a polygon is to use texture mapping.
                         Think of texture mapping like wrapping a present. Each side of the box you are wrapping is a blank
                         polygon. You could paint the box, but it would be very difficult to make it match all the designs on the
                         wrapping paper. However, if you take the wrapping paper and tightly cover the box with it, you have
                         completely transformed the box with just a little effort.

                         Texture mapping works the same way. Mapping requires the use of another image. This other image
                         essentially is stretched over the object like a skin. Most video game consoles and computer graphics
                         adapters contain a special chip and dedicated memory that stores the special images used for texture
                         mapping and applies them to each polygon on the fly. This allows games such as Tomb Raider to have
                         incredibly detailed 3-D environments that you can interact with in real time.

Snell's law is named after Willebrord van Roijen Snell

 Refraction
Snell's Law:

Snell's Law:   n1 sin(theta1) = n2 sin(theta2)
 Demonstration of Snell's Law

 Problems in Snell's Law

Example:  If the angle of incidence in Lucite is 60 degrees, what is the angle of refraction?