Allison Barlow and David German - Engineering 26 Portfolio

Lab 9: Lighting and Shading

In this lab, we created a data structure for Light objects and developed a model to compute the light color reflected by a surface in a scene. We expanded the Polygon data structure to record a surface normal for each vertex for use in this computation. We implemented Gouraud shading by performing a lighting calculation at every vertex of a polygon and interpolating the colors linearly. We integrated world-coordinatized lighting and shading into our hierarchical modeling system.

Procedure

Our graphics environment continues to follow Prof. Maxwell's Graphics Environment Specification.

To calculate the visible energy reflected from a given point on a surface, one must specify the properties of that surface and of the light sources that illuminate it. We assume that all surfaces are Lambertian, or composed of a translucent binder containing particles of pigment, and we model the following surface properties.

Every light source has an RGB color value. Reflected energy can never be more intense in any channel than the value of its source. We define four types of light sources.

The reflected energy from all sources is summed to compute the color value at the point. In Gouraud shading, this energy is computed at each vertex of a triangle; the energy at each pixel in the triangle is then found by linear interpolation of the inverses of the vertex colors.

To model a shaded scene hierarchically, we define a list of lights; the positions of point lights are specified in worldspace. We define new module elements that change the pen body color, surface color, and surface coefficient just as we did to change the pen color in lab 5. We populate a module with elements in the familiar fashion, taking care to specify surface normals for the polygons. To draw a module, we traverse it, transform every polygon to worldspace, compute the reflected energy at each vertex, and fill it using Gouraud interpolation.

Results

Group Images

a triangle with a red vertex, blue vertex, green vertex, and
     interpolated color
Image 1. A demonstration of color interpolation across a polygon.

We generated the following image using Prof. Maxwell's test code. He developed the star fury model in Blender, exported it in the Stanford PLY format, and supplied a library to read in the polygons, colors, and surface normals.

space fighters
Image 2. Star furies.

Allison's Portfolio Images

shaded spheres
Image 1. Allison doesn't care much for captions.

David's Portfolio Images

a mobile
Image 1. The mobile of Lab 8, with lighting.

Conclusions and Future Work

The basic lighting and shading system developed in this lab is functional, but it lacks some realism. As has been shown, Gouraud shading is susceptible to aliasing because true color values are only computed at polygon vertices. Phong shading, in which surface normals are interpolated and shading is calculated at every pixel, resolves this issue and is a possible future extension. Light sources are not themselves visible in the present modeling system, nor can they be included in modules or subjected to transformations. Future work may remedy this by introducing Light elements into modules, which would then require one rendering pass to world-coordinatize the light sources and another to shade polygons accordingly. Finally, no objects cast shadows under the present lighting model. Shadows can be calculated by rendering the scene from the perspective of every light source, saving the Z-buffer, and applying light from that source only to objects at the depth stored in the buffer.

Appendices

Our code is available with AES256 encryption. The passphrase is only available to Dr. Maxwell.

The entire project was pair-programmed. David wrote this writeup.