CS-460/560, Assignment 8
Due Date: 5-10-08
(Absolute last date program will be accepted: 5-12-08)
This assignment should build upon Assignment 7. You are to add to your
VC++ (no OpenGL) program the capability of displaying a flat shaded
rendition of the 3-D scene. Specifically, you are to add to the "Render"
popup menu a "Flat Shaded" menu item.
If the user selects "Flat Shaded", you are to add illumination and
reflection, as described by the Phong illumination/reflection discussed
in class. Assume that each object has an intrinsic color--in other words
specific values of diffuse reflection coefficients kd(R), kd(G), kd(B).
For example, if your scene contains a house, the ground, trees, the walls
of the house could be yellow [kd(G)= kd(R)= 0.85, kd(B)=0.1], the roof
light blue [kd(R)=0.5, kd(G)=0.7, kd(B)=0.95)], the ground medium green
[kd(r)=0, kd(g)=0.85, kd(b)=0.1]; the trunk of a tree brown [kd(R)=0.25,
kd(G)=0.15, kd(B)=0.2]; and the upper part of a tree dark green [kd(G)=0.4,
kd(R)=0.05, kd(B)=0]. (The values given here are just suggestions -- you
can use whatever colors you like. Or better yet, use any Windows application
that has the Windows "Common Color Dialog Box" to look at color palettes and
obtain their corresponding RGB values. If you do this, however, you'll have
to convert the values from the common color dialog box that are based on a
maximum of 255 to values between 0 and 1.) The program should mathematically
position at least one light source of a given intensity somewhere in the
3-D scene. There should also be ambient light in the scene with an
intensity less than that of the light source(s). Then using the Phong
illumination/reflection model, with diffuse reflection only, the program
should calculate the R, G, B intensities of the light reflected from each
visible polygon in the scene. (Polygons that face away from the light
source receive no light and therefore reflect no light and are not seen.)
For each polygon, the results should be scaled to obtain RGB values, each
between 0 and 255, and the resulting values stored with the other
information on the polygon in the polygons array. Then, whenever a polygon
is to be displayed, it should be drawn in the that color (using a brush
with its stored RGB values).
You should also add to your program the ability to move and/or change the
position and/or intensity of the light source. This should be done in a
convenient way for the user. For example, there might be a "Light Source"
popup menu in which the menu items could be something like "increase x
coordinate", "decrease x coordinate", "increase y coordinate", "decrease
y coordinate", "increase z coordinate", "decrease z coordinate", "increase
intensity", "decrease intensity". Subsequent mouse clicks would then
increment or decrement the selected coordinate of the light source by a
given amount or increase/decrease its intensity by a given amount.
Note that in "flat Shaded" mode, any time the light source changes, the
intensity values for each polygon in the scene will have to be recomputed
using the Phong model, since its position relative to the light source will
have changed. This will not be the case if the viewing parameters change
since we are only considering diffuse and ambient reflection, and, in the
Phong model, those are independent of the position of the viewer.
All displays (fly-about, zooming, etc.) should be done using the current
rendering mode ("All Faces", "Remove Hidden Faces", or "Flat Shaded").
Extra Credit Possibilities--
1. (Maximum of 10 points extra credit) Add Z-Buffer hidden surface removal.
2. (Maximum of 10 points extra credit) Add specular reflection. In other
words, assign to each object a specular reflection coefficient (ks) and a
specular exponent (n) to each object's intrinsic color description, and
include the specular term from the Phong equation. If you do this, you will
need to recompute the intensities of light reflected off the polygons each
time the observer moves.
3. (Maximum of 10 points extra credit) Add Gouraud interpolated shading to
objects that are supposed to have curved surfaces (e.g., the trunk and
upper part of the trees).
4. (Maximum of 10 points extra credit) Add Phong smooth interpolated
shading to objects that are supposed to have curved surfaces.
For any of these extra credit options, there should be appropriate menu
items that allow the user to select them.