Gouraud Shading Assignment

Due Friday, March 9th, at 5:00PM, by electronic submission

Example code for setting individual pixels [ZIP]

The FreeImage Library [LINK]




Your task is to write a program to display Gouraud shaded polygons.
You have already written a rasterizer, so the hardest part is already complete.

The core of this assignment is coding the diffuse reflectance model, and extending
your scan converter to interpolate color.

However, there are several supporting tasks you must also complete in order
to have some objects to render, and in order to display the rendered result.

1.   Come up with a 3D object to render.

You will need a collection of 3D polygons.
You may create these by any method you wish, including but not limited to
loading a 3D model from disk, explicitly hardcoding coordinates into your program,
or procedurally generating simple objects such as cylinders and spheres using parametric
equations.

Parametric cylinders and spheres are probably the easiest choice.
Formulas for these objects can be found online and in many textbooks.

Those formulas will give you points on the surface.
It is up to you to correctly connect adjacent points
in order to form polygons. 

2.  Generate Normals

Each vertex needs a normal, in order to evaluate reflectance.
Calculate the normal either directly from the underlying curved
surface formula, or instead by finding the normals of each face
via cross products. 

If you choose the latter option, you will need to average
face normals to create vertex normals, as discussed in class.
This may be difficult if you choose the wrong data structure 
to represent your faces and vertices, so plan ahead.

2.   Hidden Surface Removal

If you display several polygons that overlap one another on the screen, the nearer
polygon must hide the more distant polygon.  You may avoid this altogether
by being careful to not create overlapping polygons.  Or you can choose to
perform backface removal by discarding polygons whose normal faces away
from the viewer.  Alternatively, you could display the polygons from back to front,
or attempt a z-buffer method, though these methods may be more work than is strictly necessary.


3.   Projection

There is no need for any complicated perspective or oblique projections.
You can scan convert the 3D polygons as if they were 2D simply by
pretending that the Z coordinate does not exist.
Of course, this means you must ensure that the X and Y coordinates
of your object represent valid pixel coordinates.


4. Evalute the reflectance

Use the formula for diffuse shading to compute the intensity
of each vertex.

5. Interpolate color.

Modify your scan conversion code to interpolate color 
across the polygon.

6.  Output

The framework code from the scan conversion assignment will not be helpful.
That framework displays pixels as large blocks, whereas we really want individual pixels.
That framework chooses on its own what color to display the pixels, whereas for Gouraud
shading you must specify the color yourself, using interpolation.

For this assignment you should replace the existing framework display code with
a display method that allows you to set individual pixels with specific colors.
There is no need to display the image directly on the screen.
Instead you may render the image in memory and write it out to disk.
PNG is the suggested file format, as it is lossless and compressed.
FreeImage is a good library for writing images to disk.
It is easy to download, install, and use, but you will need to
figure out how to do this on your own.

If you would rather have the instant feedback of an image appearing
directly on the screen, we have provided a new code framework that
provides the appropriate setpixel function. 
It is up to you to read this code and learn how to make use of it.


Submission Instructions

Create one or more images demonstrating the results of your program.
Place these images, along with source code and build instructions,
in a zip file, and turn it in using the submit command on your 
instructional account.
The assignment name on the submission system will be gouraud.