Comp 360 Lab 3 : Rendering Scenes with Ray Tracing
1 Overview
In this project you will implement a static ray tracer for scenes containing primitive 3-dimensional objects, including spheres, ellipsoids, boxes, cylinders, and cones. Your renderer will support multiple light sources, object shadows, reflection, refraction, and transparency. Additionally, you will create at least four interesting 3-dimensional scenes and render these scenes with your ray tracer.
2 Specification
We will provide you with a framework upon which you can build your project. By default, the program will load in a scene file called "default.ray" and render a polygonal representation of the scene. You can modify this scene using controls as described in the "Program Controls" section. Once you are satisfied with the scene, you can ray trace the scene by pressing a button (F5). Another window will pop-up, and it will progressively ray trace the scene.
The basic framework contains only the ability to parse and ray trace a sphere without shading. You will need to rewrite the sphere intersection code using the algorithm in the text book. You will fill out the rest of the code for ray tracing other objects. You will also write a few user-interface/applicational enhancements to the given framework.
2.1 First Milestone (1 Weeks, 11/15/2010, 11:59pm)
By the first milestone deadline, your program must do the following:
- Rewrite the ray-sphere intersection code using the algorithm in text book.
- Ray trace scenes containing any number of light sources and spheres. The other object types are not required at this time.
- Implement the ray tracing illumination model.
- Implement shadow effects and reflection, refraction, transparency for spheres.
- Implement the ability to dynamically add and remove spheres from the scene.
2.2 Second Milestone (1 Weeks, 11/22/2010, 11:59pm)
By the second milestone deadline, your program must do the following:
- Render the polygonal representation of the cylinder.
- Ray trace scenes containing any number of light sources and cylinders. The other object types are not required at this time.
- Implement the ability to dynamically add and remove cylinders from the scene.
- Implement the ability to save the current scene into a file in the format as described in "Scene File Format".
2.3 Final Submission (1.5 Weeks, 12/1/2010, 11:59pm)
By the final project deadline, in addition to the requirements for the first milestone, your program must do the following:
- Render polygonal versions of 3 additional object types: ellipsoids, boxes, and cones.
- Ray trace all 5 object types: spheres, ellipsoids, boxes, cylinders, and cones.
- Implement the ability to dynamically add and remove any object from the scene.
- Render any scene given in the file format specified below.
2.4 Sample Files / Pretty Pictures
Your final submission should contain at least 4 scene files of your own creation. Be creative. Your files should demonstrate all the various ray tracing effects and all the object types. For each scene file you create, please include a picture file in the bmp format that contains your renderer's output for that scene.
2.5 Extra Credit
- Ray trace the torus.
- Add GUI for interactive adding/removing/manipulating of light sources.
- Implement soft shadows (http://www.devmaster.net/articles/raytracing_series/part5.php).
3 Program Controls
Using the given framework will require familiarity with the following controls. You may add or change the controls as you wish. Document your changes in your README file.
Viewing Mode
Change the camera orientation and position.
- Rotate: left-click and drag to rotate the camera.
- Zoom: right-click and drag to zoom the camera in and out.
- Pan: Hold 'Alt', left-click and drag to pan the camera.
Selection Mode
Select an object in the scene for manipulation.
- Hold Ctrl to enter Selection Mode.
- Place mouse cursor on an object to outline the object in red.
- Left-click on the object to select it. A property window will pop up.
Editing Mode
Edit an object's definition and position.
- A single object should be semi-transparent with a positioning widget (three orthogonal arrows) at the center of the object.
- Place the mouse cursor on the one of the three arrows to highlight the arrow in yellow.
- Left-click and drag while an arrow is selected to move the object in one of the three orthogonal directions.
- Change the values in the Property window to interactively update the scene.
- To exit Editing Mode: hold Ctrl to enter Selection Mode; left-click in an empty region to deselect the current object.
Application Controls
- Open File: Press Ctrl + 'o'
- Open Ray trace window: Press 'F5'
- Close Ray trace window: Press 'F4'
4 Suggested Plan
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.
4.1 First Milestone
- Rewrite the sphere intersection code using the algorithm in the text book. You need to compute the intensity of the light at a point of intersection.
- 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.
4.2 Second Milestone
- Repeat the intersection and normal calculations for the cylinder as you have done for the sphere.
- Implement the functionality to save a scene.
4.3 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 text book.
4.4 Implementation Notes
- Read implementation_notes.txt for details on the structure of the code.
- See the course text book 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.
- 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.
5 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.
5.1 Turning In First/Second Milestone
Please follow the same submission directions as above when you complete the First and Second Milestones. The README for the milestone requires only your names and a list of the features your milestone code supports.
6 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.
6.1 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).
6.2 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.
Sphere
A sphere is defined by the following values.
- The coordinates of the center of the sphere. (Three floating point values).
- Radius of the sphere (One floating point value).
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.
- 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).
- Height of the cylinder along its axis (One floating point value).
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).
- 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).
- 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).
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
0 5 5 // 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
sphere // Type
0 0 0 // x, y, z coordinates of center of the sphere
1.5 // radius of the sphere
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 1 // 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.89.
On 09 Nov 2010, 11:24.