CSS552: Programming
Assignment #2
Fun with Phong Illumination Model
Due Time: Refer to the course
web-site.
Objective
The
goals of this programming assignment are for us to implement, experience, and
understand the effects of each of the Ambient, Diffuse, and Specular components
of the Phong Illumination model with Point, Directional, and Spot light types.
Here are more details.
Approach
Please
refer to my solution. Here are the command files. You should download and unzip
both of these files, then double click on RTViewer.exe to run the sample
program. Notice that in this version of the ray tracer:
- There are GUI support for
switching on/off for each of the Ambient, Diffuse, and Specular terms in
the Phong illumination model.
- Try switching each of the terms on/off and render to
see the effects (and combination of effects) of those terms.
- In the NdotL and (VdotR)^n computation, the
corresponding values are computed and assigned to Color.R,G,
and B to show the float result as a gray scale color. Notice that the over
saturation (very white result) is caused by addition of all the light
sources in the scene. There are three lights, so, for example, for each
visible point I compute and add NdotL for each
of the light sources, resulting in a floating number greater
than 1.0 for many of the locations.
In
this assignment, you are to compute each of the Ambient, Diffuse, and Specular
components, and depending on user settings, display your computed results
properly. Please download this starter project
(my mp1 solution, with slightly more light support plus the GUI interface) and
unzip the source code.
The RayTracer Project
By now, we should all be quite familiar with this project from our mp1
experience. In mp1 you spent time implementing the visibility computation in
the RTCore_Compute.cs file.
In mp2, we will implement the Phong illumination model in the ComputeShading()
function in the RTCore_Shade.cs file.
The ComputeShading() function is invoked once to compute for the
color of each visible sample from the ComputeImage()
function.
If you open the RTCore_Shade.cs file,
you will notice the, mShadeAmbient, mShowNdotL, mShadeDiffuse,
mShowVdotR, and mShadeSpecular
instance variables, your ComputeShading() function should compute a color by obeying these
variables:
- mShadeAmbient: If true, accumulate
ambient color from the material to your computed color.
- mShadeDiffuse: if true, compute and
accumulate diffuse term to your computed color. If mShadeDiffuse is true, you should ignore mShowNdotL.
- mShadeSpecular: if true, compute and
accumulate specular term to your computed color. If mShadeSpecular
is true, you should ignore mShowVdotR.
- mShowNdot: if true and if mShadeDiffuse is false, compute and accumulate NdotL from all of the light source. Use the result
float number as RGB of the returned color.
- mShowVdotR: if true and if mShadeSpecular is false, compute and accumulate (VdotR)^n from all of the light sources. Use the result
float number as RGB of the returned color.
The RTSupport/SceneResourceSupport/Light folder. New to
mp2 is the more careful parsing of the light source types. A
RTLight object has an instance of RTTypeLight. RTLightType
can be one of: RTLightType_Point, RTLightType_Directional,
or RTLightType_Spot. The provided code
parses the command file and create the corresponding light object with
the proper parameters. RTLight has four functions,
where each the implementation simply turns around and calls the corresponding funciton of RTLightType:
- InitializeLight(): Allows you to
initialize the RTLightType if you so desired.
- GetColor(Vector3 visiblePt): Returns the color of the light as seen by visiblePt. For example, if a visible point is outside
of the spotlight's illumination code, this color should be black.
- GetNormalizeDirection(Vector3 visiblePt): You MUST override
this function in the RTLightType class
hierarchy!! Proper L-vector must be computed and returned.
- GetLightPosition(): returns the position
of the light source.
In this programming assignment, all your code should only go into the RTLightType class hiearachy, and ComputeShading() function with minor modification (if any)
to the ComputeImage function.
Credit Distribution
Here
is how the credits are distributed in this assignment:
- 5%: Ambient: show proper color
- 30%: NdotL
- (10%): respect
and not show effects when N is pointing away from L.
- (20%): Light type support for Point,
Directional, Spot lights.
- 15%: Diffuse Shading
- (5%) include NdotL for each light once
- (5%) proper summing of
all contributions from all lights
- (5%) proper consideration of object material color
- 25%: (VdotR)^n:
- (2%) Proper reflection
of the reflection of light source vector
- (5%) respect and not
show effects when V is pointing away from L
- (3%) Proper handling of
the shiningness term.
- (15%) Light type support for Point, Directional,
and Spot lights.
- 15%: Specular Shading
- (5%) include VdotR for each light once
- (5%) proper summing of
all contributions from all lights
- (5%) proper consideration of object material color
- 10%: Proper submission and proper math operations
- (5%) no useless files
- (5%) proper usage of
all system libraries (e.g., when you can do a = b + c, you do not do a.X = b.X + c.X; a.Y = b.Y + c.Y, etc.)
Extra Credits
- 2pt: Support half-way vector (must include GUI support to
toggle the feature!).
- 2pt: Support distance attenuation of light (must include
GUI support to toggle the feature).
This programming assignment will count 10% towards your final grade for
this class.
Hints:
- When NdotL is less than zero,
illumination form the light source cannot occur! Think about it, why?
- When VdotR is less than zero,
specularity cannot be visible! Again, why?
- The XNA function: Vector3.Reflect()
gives you a direction that reversed of what you need!