Travis Furrer
6.837 Project 5

Ray Tracer with Refraction and Triangles

The purpose of this project is to extend a simple Ray Tracer with support for refraction, and other primitive objects. A complete Ray Tracer with ambient, directional, and point lighting and reflection was provided.

The test applet above simply renders a scene that I designed to demonstrate both refraction, and triangle primitives. The transparent sphere is refracting my initials (red), and a triangular mirror is placed behind them. There is a huge reflective sphere to the right, providing another view of the objects on interest. There is a point light source to the left of the scene.

There are a couple of bugs that exist in my ray tracer. First of all, bad things happen when triangles are viewed exactly from the edge. Secondly, it seems the refraction does not work correctly with objects built out of triangles. I was unable to determine what was causing that problem. Also, things don't always work if you have overlapping objects, especially if two overlapping solids are both transparent (in that case I gaurantee that the correct thing will not happen). Finally, it is interesting to note that transparent objects still cast a shadow. This is not a bug, but rather a simplification of the ray tracer design.

The reason I chose to add triangles to the ray tracer was that I hoped to render the same cow we used in previous projects. Indeed, I converted the cow file into a usable format for the ray tracer, and the cow renders VERY slowly. When I created the cow.ray file, I accidentally specified all the triangles in counterclockwise instead of clockwise order. This messes things up, but I switched the sign of the normals in the applet code just to render the cow once and take a screen shot. You can see that it isn't quite right due to the bug already mentioned with triangles, but it is indeed a recognizable cow!

Here are some screen shots from my various tests:

Our old friend... as best I can tell? Some balls. The exact same balls under a "magnifying lens." A ball moving behind another magnifying lens, to show a phenomenon of refraction through spheres.

Follow these links to ray trace some more tests yourself:

Objects are specified in an .ray file as follows:

    eye x y z
    lookat x y z
    up x y z
    fov degrees
    background r g b
    surface r g b  ka kd ks ns  kr kt index
    sphere x y z radius
    light r g b ambient
    light r g b point x y z
    
This format is very similar to the format used in project 4, with the additional surface properies of reflection, refraction, and index of refraction.

The code for this project is in the files: