Comp360/560 Lab3 : Ray Tracing

First Milestone - April 02, 2019, 11:59pm
Final Submission - April 14, 2019, 6:00pm


Figure 1: Modeling window

Figure 2: Ray-tracing window

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.

This project will be completed in two parts. The first part will require you to ray-trace spheres and boxes. The second part will require you to ray-trace the rest of the geometric objects listed above and also create your own interesting scenes for ray tracing. This project is worth a total of 120 points (+20 extra points).

You may work with a partner on this lab.

Important: If you find any bug in the project that you think was already there in the starter code and for which you are not responsible, report the issue to the TA ASAP.

2  Project Overview

We will provide you with a framework upon which you can build your project (link to starter code). By default, the program will load in a scene file called "default.ray" and render a polygonal representation of the scene (Figure 1). You can modify this scene using controls as described in the "Program Controls" section. Once you are satisfied with the current scene, you can ray-trace the scene by pressing F5. Another window will pop-up and then progressively ray-trace the scene (Figure 2).

The basic framework contains only the ability to parse and ray-trace spheres and boxes without shading. You will need to:

2.1  First Milestone (40 points)

For the first milestone, your program must do the following: For how to submit this part, see this section.

2.2  Final Submission (52 points)

By the project deadline, in addition to the requirements for the first milestone, your program must do the following:

2.3  Scene Files/Pretty Pictures (28 points)

Your final submission should contain at least 4 interesting scene files of your own creation. Be creative. Impress us. 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, as well as describe the scene in your README file.

2.4  Extra Credit (20 points)

For the ambitious, you are welcome to implement the following features:

3  Program Controls

Using the given framework will require familiarity with the following controls. You may add or change the controls as you wish, but document your changes in your README file.

3.1  Viewing Mode

Change the camera orientation and position:

3.2  Selection Mode

Select an object in the scene for manipulation.

3.3  Editing Mode

Edit an object's definition and position.

3.4  Application Controls

3.5  Object Adding/Removing

Although you are free to choose which keys are used to add or remove objects, here are some suggested controls (the structure already given in the starter code): Make sure to document if you choose your own controls.

4  Suggested Plan

The following is a short outline that describes a suggested plan of attack and some hints. Plan well for completing this project.

4.1  First Milestone

4.2  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 is provided in the textbook.

4.3  Implementation Notes and Hints

Here are some notes on the specifics for implementing this lab. Please read the following sections before you start coding your solution.
4.3.1  General
4.3.2  Operator
4.3.3  Code Base
Here is a short description of the files you'll be working with. This project frequently uses the visitor pattern.

5  What To Turn In

Use the given "lab_raytracer" directory. This directory should contain your source code and all files needed to build your program in Visual C++. After completing the project, you should have scene files (.ray) in files/ and rendered pictures (.bmp) in images/. The grader should be able to load your scene files and test them. Also include a README file containing: Zip up this folder and follow the submission instructions on the course web page. Don't forget to remove unnecessary files before zipping the folder.

For the first milestone:

6  Scene File Format

A 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 three parts, lighting attributes, object definitions, and the camera definition, in this specific order.
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. You may also take a look at the initial "default.ray" in the folder "files/".

6.1  Lighting Attributes

The lighting of the scene appears in the following sequence:
  1. The scene's ambient light color (three floating-point values).
  2. The number of point light sources in the scene - must be at least 1 (one integer).
  3. For each point light source:
    1. The light's position in space (three floating-point values).
    2. 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:
  1. The number of objects in the scene—must be at least 1 (one integer).
  2. For each object:
    1. The object's type, one of the strings "sphere", "ellipsoid", "box", "cone", or "cylinder" (or "torus").
    2. A set of numbers defining the object's geometry—format varies, see below.
    3. 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:
  1. The coordinates of the center of the sphere (three floating-point values).
  2. Radius of the sphere (one floating-point value).
Ellipsoid
An ellipsoid is defined by the following values:
  1. The coordinates of the center of the ellipsoid (three floating-point values).
  2. Unit vector in the direction of the ellipsoid's first axis, v1 (three floating-point values).
  3. Unit vector in the direction of the ellipsoid's second axis, v2 (three floating-point values).
  4. Unit vector in the direction of the ellipsoid's third axis, v3 (three floating-point values).
  5. Length of ellipsoid along v1 (one floating-point value).
  6. Length of ellipsoid along v2 (one floating-point value).
  7. 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:
  1. The coordinates of a corner of the box (three floating-point values).
  2. Unit vector in the direction of the box's length, vl (three floating-point values).
  3. Unit vector in the direction of the box's width, vw (three floating-point values).
  4. Unit vector in the direction of the box's height, vh (three floating-point values).
  5. Length of box (one floating-point value).
  6. Width of box (one floating-point value).
  7. Height of box (one floating-point value).
The box should be drawn on the positive side of its corner as measured by the coordinate system given by the vectors vl, vw, and vh. Note that if the three vectors are orthonormal and length = width = height, then the result is a cube.
Cylinder
An elliptical cylinder is defined by the following values:
  1. The coordinates of the center of the base of the cylinder (three floating-point values).
  2. Unit vector along the first axis of the ellipse that forms the cylinder's base (three floating-point values).
  3. Unit vector along the second axis of this ellipse (three floating-point values).
  4. Unit vector in the direction of the cylinder's central axis (three floating-point values).
  5. Length of the first axis of the cylinder's elliptical base (one floating-point value).
  6. Length of the second axis of the cylinder's elliptical base (one floating-point value).
  7. Height of the cylinder along its axis (one floating-point value).
Cone
A cone is defined by the following values:
  1. The coordinates of the center of the base of the cone (three floating-point values).
  2. Unit vector along the first axis of the ellipse that forms the cone's base (three floating-point values).
  3. Unit vector along the second axis of this ellipse (three floating-point values).
  4. Unit vector in the direction of the cone's central axis (three floating-point values).
  5. Length of the first axis of the cone's elliptical base (one floating-point value).
  6. Length of the second axis of the cone's elliptical base (one floating-point value).
  7. Height of the cone along the axis, i.e., 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:
  1. Ambient coefficients (three floating-point values between 0 and 1).
  2. Diffuse coefficients (three floating-point values between 0 and 1).
  3. Specular coefficients (three floating-point values between 0 and 1).
  4. Specular exponent (one floating-point value).
  5. Reflective coefficients (one floating-point value between 0 and 1).
  6. Transparency coefficients (one floating-point value between 0 and 1).
  7. Index of refraction (one floating-point value not less than 1).

6.3  Camera definition

After the object definitions, the next line contains 19 floating-point values. These values describe the orientation and the position of the camera. Having this description allows you to save the camera description along with your object and lighting descriptions.

6.4  Sample File

// Lighting
0.3 0.3 0.3    // 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
// More lights

// 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).
0 0 1          // Normalized vector of the direction of Height (vh).
.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

1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 2  // The camera description