cos426.jpg (39279 bytes)

Computer Graphics, Spring 2005


Assignment 2: Ray Tracing

Due on March 8 (Wednesday) at 11:59 PM


Overview

In this assignment you will implement a basic raytracer. There is a large amount of flexibility in how sophisticated you may make your program, but at a minimum your raytracer will be able to make images like the one on the right.

You are responsible for implementing the interesting parts of the raytracer, including the recursive raytracing functions, the shape intersection functions, the light and shadow computation functions, and any acceleration datastructures you wish. The rest of the infrastructure of the raytracer is provided in our skeleton code, which includes data structures for managing the ray traced objects, linear algebra functions (vector and matrix objects and operations), a function for loading scene graph files into a prescribed node tree stucture, a BMP image file importer/exporter (for images and textures, etc), and a couple of supporting data structures for lights, materials, etc. Be sure to read the overview of the included skeleton code for help.

The raytracer uses a special .ray file format to specify its scenes. Read the overview of the ray file syntax for details. To help you debug, we provide a standalone utility that can render .ray files. The utility is implemented in OpenGL and does not support recursive ray-casting and transparency, but at least for the first few parts of the assignment your image should roughly agree with the image generated by the viewer. The viewer is available for Linux, Mac and Windows architectures (you might need glut32.dll if you're using Windows). Note that rayviewer assumes that if you are looking at the front of the triangle the vertices are indexed in counter-clockwise order.

We also provide several extra .ray files and an exporter for the 3D modeling program Blender. Check out the Blender .ray exporter page.

Matt Plough, 2005
 


Getting Started

You should use the code available here (2.tar.gz, 2.zip), as a starting point for your assignment. We provide you with:

As mentioned above, we provide extensive documentation for the provided files:

After you copy the provided files to your directory, the first thing to do is compile the program. If you are working on a Windows machine, double click on tracer.dsp and select build from the build menu. If you are developing on a UNIX machine, type make. In either case an executable called tracer (or tracer.exe) will be created.


How the Program Works

The program takes in to mandatory arguments, the input (.ray) file name and the output file name (.bmp). It is invoked from the command line with:
% tracer -src in.ray -dst out.bmp
Additionally, you can specify image height, image width, recursion depth and contribution limit as follows:
% tracer -src in.ray -dst out.bmp -width w -height h -rlim r -clim c
Feel free to add new arguments to deal with the new functionalities you are implementing. Just make sure they are documented.

What You Have to Do

The following is a list of features that you may implement. We strongly advise that you implement the features roughly in the order they are described, and test your code after you implement each feature. This assignment will require a significant amount of programming, so it is very important to make sure that the basic parts of your raytracer are correct before moving on. We provide images of the correct output for the first few features.

The assignment is worth 20 points. The number in parentheses corresponds to how many points a feature is worth.  Options in bold are mandatory.

By implementing all the required features, you get 13 points. There are many ways to get more points:

It is possible to get more than 20 points. However, as in the previous assignment, after 20 points, each point is divided by 2, and after 22 points, each point is divided by 4.


What Has Not Been (Completely) Implemented

The following functions have not been completely implemented:

What to Submit

You should submit:

The writeup should be a HTML document called assignment2.html which may include other documents or pictures. It should be brief, describing what you have implemented, what works and what doesn't, how you created the art contest images and/or movies, and any relevant instructions on how to run your interface.

Make sure the source code compiles on the machines in Friend 017. Always remember the late policy and the collaboration policy.


Hints

         int i,j; 
         Ray ray,r; 
         FILE* fp; 
         ... 
         fp=fopen("temp.ray","w"); 
         assert(fp); 
         scene.write(fp); 
         for(i=0;i<width;i++){ 
           for(j=0;j<height;j++){ 
             ray=Ray(...); 
             ... 
             if(i%20 ==0 & j%20==0){ 
               Line(Ray(ray.p,ray(5.0)),scene.getMaterial(0)).write(0,fp); 
             } 
             ... 
           } 
         } 
         fclose(fp); 
         ... 
           

Then run

tracer -src RayFiles/simple_sphere.ray -dst out.bmp 

Now you can call

viewer -src temp.ray
and after moving around a bit you will get an image that looks like this:

You should make sure that all of your rays are coming out of a single point and that they are all heading towards the sphere.


FAQ