Comp 360 Lab 3 : Rendering Scenes with Ray Tracing
First milestone due Monday, 26 October 2009, 11:59 PM
Completed project due Wednesday, 4 November 2009, 11:59 PM
Overview
In this project you will implement a static ray-tracer for scenes containing primitive 3-dimensional objects, including right circular cylinders, ellipsoids, boxes, cylinders, and cones. Your renderer will support multiple light sources, object shadows, reflection, refraction, and transparency. Additionally, you will create at least one interesting 3-dimensional scene, and render this scene with your ray-tracer. The whole project is worth 150 points.
For this lab, you must work with a partner other than the partners you worked with in the first two labs. As soon as possible, send an email with your partner's name and username to powei.feng@rice.edu. If you have trouble finding a partner, let us know and we will try to pair you up.
Specification
Your program will take a single command-line argument: the name of a text file that defines a scene to render. The format of the text file is given in the section "Scene File Format" below. Under the Windows OS, the path to a file is passed as an argument to a program if the program is opened by dragging the file onto the program's icon.
When the program starts, the window will contain only a black background. Once the scene file is successfully parsed, your program should begin rendering the scene. The scene should be rendered progressively- that is, as soon as you have calculated the color for a pixel, that pixel should be colored in the window. Your program should not wait for the rendering procedure to finish before displaying the scene.
All images should be rendered at a resolution of 500 by 500 pixels. (You can modify the constants WIDTH and HEIGHT in OpenGLFrame.h to set the window size automatically).
Milestone 1 (65 points)
By the first milestone deadline, your program must do the following:
- Render scenes containing any number of light sources and right circular cylinders. The other object types are not required at this time.
- Implement the ray-tracing illumination model.
- Implement shadow effects and reflection, refraction, transparency effects for right circular cylinders.
Final Submission (65 points)
By the final project deadline, in addition to the requirements for milestone 1, your program must do the following:
- Be able to ray trace all 5 object types: spheres, ellipsoids, boxes, cylinders, and cones
- Render any scene given in the file format specified below.
Sample Files / Pretty Pictures (20 points)
Your final submission should contain one or more scene files of your own creation. Be creative. Your files should demonstrate all the various ray tracing effects and all the object types. (Though you can get full credit for only one scene, you are encouraged to submit several). For each scene file you create, please include a picture file in jpg format that contains your renderer's output for that scene.
You will receive extra credit if you implement the torus.
Implementation Notes
- See the lecture notes posted on the course web site for the algorithms and calculations used in recursive ray tracing. For alternative presentations, you might also want to look at Foley and van Dam's book or on the web.
- You may assume that the viewer is at the origin (0,0,0) and looking towards the negative z axis (0,0,-1). Choose a reasonable viewing angle (60 degrees is average) and document your choice.
- As usual, you must use your own code for mathematical computations.
- Remember, when a ray intersects a reflective or refractive surface, rays are traced recursively from the point of intersection.
- Shadow rays are NOT refracted. If a shadow ray hits an object with a positive transparency coefficient t, scale the contribution of the light source by t and continue tracing the shadow ray.
- Your program may assume that input files are well-formed.
- Your program must implement near and far clipping planes. Please document what these planes are in your README file.
- You will use OpenGL to display images on the screen, but you will only interact with OpenGL at the 2-dimensional level. Consider using the function glDrawPixels() to efficiently display 2-dimensional pixel sets. You can find documentation for this function on the web or in the OpenGL Red Book.
Sample Outline
The following is a short outline that describes a suggested plan of attack. If you accomplish each of these tasks
in a day or two, you should have ample time to complete this project.
First Milestone
- In your scene file, assign n distinct colors to n cylinders. For each pixel, shoot a ray into your scene and determine the right circular cylinders that the ray intersects. Find the closest intersection point and assign the color of the pixel to the color of the right circular cylinder. If there is no intersection, just color the pixel black. Do not worry about dealing with light intensities at this time.
- Now that you are confident that the rays are successfully intersecting with the objects in the scene and the closest point of intersection can be faithfully determined, compute the intensity of the light at a point of intersection based on the lecture notes.
- Add recursive rays that act as shadow rays to determine shadowing effects in your scene.
- Add reflective rays for mirror effects.
- Add refractive rays for transparency effects.
Final Submission
After the first milestone, you should have the majority of the functionality of the ray tracer.
The only remaining tasks are computing normals to the other surfaces and computing intersection
points between the other surfaces and rays. Pseudo-code for these computations are provided in the
lecture notes.
What To Turn In
Create the directory lab3. This directory should contain your source code and all files needed to build your program. Also include a README file containing:
- The names of the members of your team.
- A brief overview of how your code is organized.
- Information about your scene files.
- Any known bugs or incomplete features.
- Any other implementation details you think your grader should know.
Zip up this folder and follow the instruction on the course web page for submission.
Turning In Milestone 1
Please follow the same submission directions as above when you complete Milestone 1. The README for the milestone requires only your names and a list of the features your milestone code supports.
Scene File Format
A lab 3 scene file is an ASCII text file containing data that define lighting and geometry for a ray-traced scene. A scene file is organized into two parts, lighting attributes and object definitions. Lighting attributes are always given first.
In a scene file, values are separated by one or more blank spaces. Scene files support C++-style double-backslash (//) comments- the double backslash characters mean that input should be ignored until the next newline character. An example file appears at the end of this document.
Lighting Attributes
The lighting of the scene appears in the following sequence.
- The scene's ambient light color. (Three floating point values).
- The number of point light sources in the scene - at least 1. (One integer).
- For each point light source
- The light's position in space. (Three floating point values).
- The light's color. (Three floating point values).
Object Definitions
Beneath the lighting attributes, the input file will contain at least one object definition. Object definitions are given with the following sequence.
- The number of objects in the scene - at least 1. (One integer).
- For each object
- The object's type, one of the string "Sphere", "ellipsoid", "box", "cone", or "cylinder".
- A set of numbers defining the object's geometry- format varies, see below.
- A set of numbers defining the object's material properties. This format is the same for all objects.
The object definition formats are as follows.
Right Circular Cylinder
An right circular cylinder is defined by the following values.
- The coordinates of the center of the base of the cylinder. (Three floating point values).
- Unit vector in the direction cylinder's central axis. (Three floating point values). The cylinder grows up from its base along the axis vector.
- Height of the cylinder along its axis (One floating point value).
- Radius of the cylinder's circular base (One floating point value).
Note that the right circular cylinder is a special case of the elliptical cylinder. You might consider first building the code structure for the elliptical cylinder and pass the parameters for the right circular cylinder. This approach will avoid duplication of code when you tackle the second milestone.
Ellipsoid
An ellipsoid is defined by the following values.
- The coordinates of the center of the ellipsoid. (Three floating point values).
- Unit vector in the direction of the ellipsoid's first axis, v1. (Three floating point values).
- Unit vector in the direction of the ellipsoid's second axis, v2. (Three floating point values). Dot product of v1 and v2 should be zero.
- Unit vector in the direction of the ellipsoid's third axis, v3. (Three floating point values). v3 should be the cross product of v1 and v2.
- Length of ellipsoid along v1 (One floating point value).
- Length of ellipsoid along v2 (One floating point value).
- Length of ellipsoid along v3 (One floating point value).
Note that if all axis lengths are equal, the result is a sphere.
Box
A box is defined by the following values.
- The coordinates of a corner of the box. (Three floating point values).
- Unit vector in the direction of the box's length, vl. (Three floating point values).
- Unit vector in the direction of the box's width, vw. (Three floating point values). Dot product of vl and vw should be zero.
- Unit vector in the direction of the box's height, vh. (Three floating point values). vh should be the cross product of vl and vw.
- Length of box (One floating point value).
- Width of box (One floating point value).
- Height of box (One floating point value).
The box should be drawn on the positive side of its corner as measured by the coordinate space given by the vectors vl, vw, and vh. Note that if length = width = height, the result is a cube.
Cylinder
An elliptical cylinder is defined by the following values.
- The coordinates of the center of the base of the cylinder. (Three floating point values).
- Unit vector along of the first axis of the ellipse that forms the cylinder's base. (Three floating point values).
- Unit vector along the second axis of this ellipse. (Three floating point values). Dot product of this vector and the vector along the first axis should be 0.
- Unit vector in the direction cylinder's central axis. (Three floating point values). This vector should be the cross product of the first two vectors. The cylinder grows up from its base along the axis vector.
- Height of the cylinder along its axis (One floating point value).
- Length of the first axis of the cylinder's elliptical base (One floating point value).
- Length of the second axis of the cylinder's elliptical base (One floating point value).
Note that if the last two values are equal, the cylinder's base is a circle, and the result is a right circular cylinder.
Cone
A cone is defined by the following values.
- The coordinates of the center of the base of the cone. (Three floating point values).
- Unit vector along of the first axis of the ellipse that forms the cone's base. (Three floating point values).
- Unit vector along the second axis of this ellipse. (Three floating point values). Dot product of this vector and the vector along the first axis should be 0.
- Unit vector in the direction cone's central axis. (Three floating point values).
- Height of the cone along the axis (the distance from the center of the cone's base to the vertex of the cone). (One floating point value).
- Length of the first axis of the cone's elliptical base (One floating point value).
- Length of the second axis of the cone's elliptical base (One floating point value).
Material Properties
Immediately after the definition of an object's geometry, its material properties are given as follows.
- The object's ambient coefficient. (Three floating point values between 0 and 1).
- The object's diffuse coefficient. (Three floating point values between 0 and 1).
- The object's specular coefficient. (Three floating point values between 0 and 1).
- The object's specular exponent. (One floating point value).
- The object's reflective coefficient. (One floating point value between 0 and 1).
- The object's transparency coefficient. (One floating point value between 0 and 1).
- The object's index of refraction. (One floating point value).
Sample File
// Lighting
1 1 1 // R, G, B of ambient color
1 // Number of light sources
10 10 0 // x, y, z position of the first light source
1 1 1 // Color of the first light source
// Objects
2 // Number of objects
// First object
cylinder // Type
0 0 0 // x, y, z coordinates of center of the base of the cylinder
1 0 0 // Normalized vector of first axis of the ellipse forming the
// base of the cylinder
0 1 0 // Normalized vector of the second axis of the ellipse
0 0 1 // Normalized vector of the direction of cylinder axis
20 // Height of the cylinder (along the axis)
5 6 // Length of each axis of the ellipse
0.1 0.1 0.1 // Ambient coefficient
0.45 0.45 0.45 // Diffuse coefficient
0.5 0.5 0.5 // Specular coefficient
5 // Specular exponent
0.5 // Reflection coefficient
0.1 // Transparency coefficient
1.6 // Index of refraction
// Second object
box // Type
0 0 0 // x, y, z coordinates of corner of box
1 0 0 // Normalized vector of the direction of Length (vl)
0 1 0 // Normalized vector of the direction of Width (vw).
// (Dot product of vl and vw should be zero.)
0 0 1 // Normalized vector of the direction of Height (vh).
// (vh should be the cross product of vl and vw.)
5 5 10 // The Length, Width, and Height of the box, in floats.
0.1 0.1 0.1 // Ambient coefficient
0.45 0.45 0.45 // Diffuse coefficient
0.5 0.5 0.5 // Specular coefficient
5 // Specular exponent
0.5 // Reflection coefficient
0.1 // Transparency coefficient
1.1 // Index of refraction
File translated from
TEX
by
TTH,
version 3.85.
On 15 Oct 2009, 12:54.