CS 315 Homework 6 - Ray Tracer

Due Date: Tues Nov 26 at 11:59pm

Overview

In this assignment, you will write a simple ray tracer. Like rasterization, ray tracing is an algorithm for rendering 3D scenes into 2D images. However, ray tracing can produce some amazing visual effects that rasterization has difficulty with: such as accurate shadows, mirror reflection, and refractions/transparencies. When you've finished with this assignment, you'll have produced a piece of software (almost entirely on your own) that can generate images such as these:

In the end, your ray tracer will be able to:

  1. Render spheres and triangles (and by extension, meshes made of triangles!)
  2. Perform basic shading using the Phong illumination model
  3. Include lighting from ambient, point, and directional light sources
  4. Capture shadows cast by objects that occlude light sources
  5. Calculate mirror reflections

If you wish, you may also include further effects: texture mapping, depth of field, soft shadows, etc.

Using these effects, you should render a scene that contains at least 3 objects, all of which cast shadows and at least one of which has mirror reflectance. You'll need to include at least one sphere and one triangle. Note that a Cornell Box is a nice way of demonstrating your ray tracer, such as by making an image similar to the right image above.

This assignment should be completed individually. You are encouraged to discuss high-level issues with other students, but your code must be your own.

Objectives

Necessary Files

Since ray tracing involves its own graphical pipeline, we won't be using OpenGL any more. This means that the code you're writing is effectively just Java code. While this can be run on Android emulators and devices, such hardware is much less efficient than the Java runtime on a laptop or desktop. And since the code is (basically) identical, why implement and test the code on Android (which may be 100x slower) instead of in straight Java?

For this reason, the starter code you should download and extract contains two different starter code sets.

Beyond those two classes, everything else in the starter projects is identical. This is because they in fact run the same code! Thus is should be trivial to take code written in one project and "port" it into the other. As part of the assignment, you will be porting the code from one platform to the other. This will involve copying most of the Java files, tweaking the contents of the RayTracer class... and that's it!

I have also included the following classes to help get your program started:

Finally, as always, the zip file also contains a README.txt file that you will need to fill out.

Other Resources

I have also made available a few other resources you might find useful. In particular, here is a a set of example scenes that you can use to test your ray tracing program as you get it developed. Each scene is described in a text file, the format of which is detailed in the included SceneFileFormat.pdf file. There is also a rendering of what the scene should look like. Note that these renderings were produced with a different program, so you might not get the exact same output.

Recommended Design Strategy

While ray tracing is a relatively simple algorithm conceptually, it requires a non-trivial amount of code to implement (because you need to do all the work yourself). If organized poorly, the program can get out of hand in a hurry. Fortunately, the ray tracing algorithm is a good target for object-oriented software design. Below is a list of classes that a ray tracer might be broken in. You can think of these as conceptual classes--ways or organizing data that may or may not have a 1:1 correspondence with Java classes. You are welcome to use or ignore these suggestions as you see fit.

Development Schedule

Get started on this right away! This is in some ways a smaller assignment than the last (less moving parts), but still has a significant number of components. Luckily, each component can be more easily tested in isolation--and since you can develop in Java, the debugging process should be quicker.

I recommend creating your program through the following steps:

  1. Start by adding in a few Spheres and making sure you can intersect with them. The sphere (and camera!) locations from the exampleScenes are good to use so you know if your Spheres are in view or not. To start, don't worry about calculating shading: just return a constant color if the ray intersects a sphere (imagine 100% ambient light). Try tweaking the camera and such to make sure that things make sense.
    This is a good target for Thurs 11/14
  2. Now that you have intersections, you can implement basic lighting and shading. This will involve transfering the logic and understanding from your last homework into your ray tracer. Get your spheres to become shaded and have specular highlights!
    This is a good target for Sun 11/17 (Saturday really, but who are we kidding?)
  3. Add triangles to your scene and make sure you can intersect and render them correctly. Note that you shouldn't have to change your lighting code, simply add another class with its own intersection function. Polymorphism will be your friend here!
    This is a good target for Tues 11/20
  4. Add in shadows to your program. This will involve casting new shadow rays. You may need to play with the "shadow bias" parameter if you notice any black speckles or shadow acne.
    This is a good target for Thurs 11/22
  5. Finally, add in recursive reflections so you can get mirror effects. Experiment with different bounce depths, and how it effects the speed of your program.
    This is a good target for Mon 11/25. That leaves you another day to finish things up before the assignment is due.
  6. Your last step should be to "port" your code into the Android project. Be sure to test that everything works. See how long it takes for your scene(s) to render! You are expected to turn in both completed projects.

Extensions

This is another somewhat open-ended assignment, so has lots of possible extensions. Up to 10 points of extra credit are available for extensions such as:

Submitting

BEFORE YOU SUBMIT: make sure your code is fully functional, but also documented and readable. Again, grading will be based primarily on functionality. I cannot promise that I can find any errors in your code that keep it from running, so make sure it works. But I will look over your code to check your implementation, so please make sure that is readable :)

Upload both the Java and Android projects (including all the src, resources, layouts, libraries, etc) to the Hwk6 submission folder on hedwig. Also include a filled-in copy of the README.txt file in your project directory!

The homework is due at midnight on Tues, Nov 26.

Grading

This assignment will be graded based on approximately the following criteria: