phase 8:
illumination
cs40 assignment 8 web page
overview
the gist of this assignment was to implement illumination in our z-buffer context. i used the phong specularity model and the gouraud shading method to accomplish this. creation and manipulation of lights is fully integrated with the modeling and keyframing system, and new primitives (circle, cylinder, cone) have been added to help test the new features. at the moment, i'm a bit short on sleep, so the api does not currently reflect these changes.
illumination
the phong model of specularity is such that a light source produces both body (lambertian) reflection and specular reflection. the body reflection is proportional to the cosine of the angle between the surface normal and the vector to the light source at any given point. the specular reflection is proportional to a power of the cosine of the angle between the vector of light reflected about the normal and the vector from the point to the viewer.
the following images demonstrate both specular and body reflections on a cylinder viewed in a parallel projection, and show the difference between low specularity (left -- specular coeffecient 1) and high specularity (right -- specular coeffecient 64). the specular coefficient is the power of the cosine alluded to earlier, thus a higher specularity produces a more pronounced dropoff and thus a sharper specular highlight on the surface
new primitives
in order to create the above required image, it seemed like a good idea at the time to go ahead and tackle the problem in the most general sense by creating a cylinder primitive. its just a cirlce with quadrilateral faces, but the surface normals on the faces are averaged to get nice smooth cylinders. the circles themselves are created using "wedge" meshes, where the first point indicates the center and all subsequent points indicate the circumference. the cone is sort of a hybrid of the two, using the same wedge representation but pulling the center up out of the circle plane and blending normals to get smooth cones. for all three, the user specifies a number of segments to use, and can specify whether or not to use end caps for the cylinder and cone.
integration
the animation at the top of "spikey" says it all. we have three light sources, one of which is keyed to change color (red to yellow to green to orange to red), a capped cylinder with a bunch of cones sticking out of it, and a ring with keyed per-channel transparency (it goes from fully opaque to 1/2 opacity in red, then back to full opacity, then to 1/2 opacity in green, and so on).
lights are treated as nodes, just like everything else. the light node itself has keyable color parameters (and the spot light has keyable umbra and penumbra angles). then, the position (for positional lights) and the direction (for directional lights) are determined by applying transformations to the node (just like a camera or a primitve).
also, there is support for drawing a scene as a wireframe if you want, or as a combination of wireframe and shaded objects:
antialiasing is back!
i ditched the rather shady antialiasing of lines and polygons i had from doing 2d graphics, and decided on a postfiltering approach. now if antialiasing is turned on, the image is rendered at double size and then shrunk to the final size using a weighted average (bartlett filter). below are jaggy and non-jaggy selections of a frame from "spikey":
it can only get better...
much of the groundwork is done for doing phong shading, cook-torrence specularity, and shadows using shadow-rays. among other things, this means i spent several hours re-organizing my code so that all triangles are generated in one big monster list before any drawing happens. so stay tuned... also, in theory, i currently have both directional and spot lights, but have tested neither...