This assignment is due at
Please read all the instructions below.
All the homeworks need to be implemented on MS Windows platform using C/C++, under MS Visual Studio, unless you make prior arrangements with me. You need to email me (i.e. the instructor) a zipped archive file which contains all the relevant code, including all the source files, visual studio project, and workspace files - all ready to compile and run. Please also include a README file which at least includes your names, and name the zip archieve file with your last names followed by the assignment number (e.g. if John Doe and Jane Doe are turning in assignment 8, the zip achieve file should be named DoeDoeAS8.zip).
The grading will be based on what proportion of the functionality is implemented and running correctly. There will be no partial grading for partial implentations.
For this assignment you will implement a basic recursive ray tracer. As we discussed in class, a ray tracer adds inter-object reflections and transparency (refraction) to a simple local illumination model. The overall idea of ray tracing is that you fire primary rays from the center of projection through all of the pixels in the image plane in order to determine the color of each pixel. When a primary ray strikes an object, you calculate the intensity at the intersection point using a local illumination model that includes ambient, diffuse, and specular components and then fire one reflection ray and one refraction ray. Each of these secondary rays adds a contribution to the total intensity of the original intersection point, so the color of the pixel is determined by taking a weighted sum of the intensities derived from local illumination, reflection, and refraction. The weights are the various reflectivity and refraction coefficients for the particular object.
Your program should allow the user to change the apparent resolution of the display window by hitting '=' and '-.' You will need to divide your image plane into the appropriate number of "fake" pixels and fire a ray through each of these pixels. Your program must include both reflection and refraction rays along with a local illumination model. The required output is a display window that shows the 3D scene viewed through a camera with its c.o.p. at the world origin and its image plane some distance away down the negative z axis. The image plane should be parallel to the x-y plane and centered on the negative z axis. The user should be able to change the size and z coordinate of the image plane. When the program starts up, the image plane should be located at z = -8 and run from (-5,-5) to (5,5) in x and y.
Your program should run on scenes composed of spheres and triangles meshes. Thus, you will need to write functions to calculate the intersection of a ray with a sphere and the intersection of a ray with a triangle. Note that by "sphere" we mean an object defined by the location of its center and a radius, not a triangle mesh that approximates a sphere.
You should also support both directional and point light sources. Use the layout file format detailed below to describe your scenes. Assume that the index of refraction for the environment is 1.0, i.e. a vacuum.
For ambient illumination calculations, use a global ambient intensity of (0.3,0.3,0.3).
For full credit, all of the above functionality must be fully implemented!
"=","-" : increase/decrease the
"fake" pixel resolution of the window
"]","[" : move the image plane farther away from/closer to
the origin along the negative z axis
".","," : increase/decrases the x,y dimensions of the image
plane
"r" : redraw the image
The layout files will specify the number, locations, types, and colors of the lights in the scene along with similar info for the objects in world. The file format is as follows.
< number of lights > < number
of spheres > < number of triangle meshes >
L < light type > < x y z > < R G B >
.
.
.
S < x y z > < radius > < R G B ambient > < R G B
diffuse > < R G B specular > < k_ambient > < k_diffuse >
< k_specular > < specular_exponent > < index of refraction >
< k_reflective > < k_refractive >
.
.
.
M < file.obj > < scale > < rotX rotY rotZ > < x y z
> < R G B ambient > < R G B diffuse > < R G B specular >
< k_ambient > < k_diffuse > < k_specular > <
specular_exponent > < index of refraction > < k_reflective >
< k_refractive >
.
.
.
Lines begining with 'L' provide info about lights. Light type will be 0 for directional lights and 1 for point lights. If the light is directional, then < x y z > is its direction. If it's a point light, then < x y z > is its location. < R G B > is the intensity of the light for all illumination components.
Lines starting with 'S' describe spheres. The RGB values specified for each sphere are the sphere's ambient, diffuse, and specular colors. As we discussed in class, these are the colors of light that the object reflects in each case. The other entries are self-explanatory. Note that k_reflective is typically set to be the same as k_specular, because they both represent the specular reflectivity of the object. However, it is not unknown for scenes to be rendered with different values for these constants.
Triangle meshes are described by lines similar to those used in the layout file format for as4.
You can find a few sample layout files here.
You can find the outline of the recursive ray tracing algorithm here. (From A. Watt, 3D Computer Graphics.)
Adopted from a homework prepared by Tolga Goktekin , Lillian Chu, Michael Downes ,UCB 2002.