Ray Tracer
Eric Risser (ear2128)
Kevin Chiu (kgc2113)


Introduction
In this writeup, we will present:

Renderings
Chess

Spheres


Dice (scene2, required)





Table (scene3)





Implementation

Category / Requirement
   
Implemented
   
Comments





File Format




size




maxdepth




output



fixed filename: result.ppm
Camera




camera




Geometry




sphere




maxverts



parsed, but unused1
maxvertnorms



parsed, but unused1
vertex




vertexnormal




tri




trinormal




Transformations




translate




rotate




scale




pushTransform




popTransform




Lights




directional




point




attenuation




ambient




Materials




diffuse




specular




shininess




emission




Camera




Ray-Surface Intersection Tests




Lighting and Shadows




Recursive Ray Tracing




Extras




area lights6



soft shadows
dielectric4



Physically correct refraction (Snell's Law)
translucency5


enhanced physical correctness
textures



complex surface colors
models2



OBJ files used to make models
acceleration structure3


bounding spheres






  1. The parsed maximum numbers are included because of assignment requirements. We use STL vectors to hold our parsed variables; so, recording the specified maximum number of elements is not necessary.
  2. Each model consists of an OBJ file and PPM texture file pair. To specify a model in the scene file, put "model filename.ppm filename.obj" .
  3. Whenever a model is imported, a bounding sphere is calculated for that model. During ray tracing, the rays are first tested against the bounding spheres, and only tested against the models if the ray intersected the corresponding bounding spheres.
  4. Scene file format: "dielectric x" where x is a non negative number.
  5. Scene file format: "translucency x" where x is a number between 0 and 1 inclusive.
  6. Scene file format: "area x y z r" where x, y, and z specify a coordinate, and r is the radius of the light source.


Discussion
Our project consists of several main components. The RayTracer class includes our main function and thus the entry point to our program. This class relies heavily on objects of type camera, scene and intersectionTest.

The Camera class does all the work for setting up a camera, so after you initialize the new camera object with a look-from look-at, up, width, height and fov, you can then give it an x and y position greater than 0 and less than your width and height respectively and it will return for you the vector going from your camera's look-from point in the direction towards the point on your virtual image plane that corresponds with the (x,y) pixel in your output image.

The Scene class calculates and maintains the relevant data structures to represent the scene. Every piece of representative data is calculated in the scene class. This includes geometry, lighting properties, material properties, models, acceleration structures, per-element matrices and inverse matrices etc. Our custom implementation of models uses textures (PPM) and geometry (OBJ) files to easily handle custom geometry and art assets. Transformations are held in a helper class, ModelViewMatrix, which takes care of model view stack maintenance and calculations.

For each pixel in the output image the main function gets a primary ray from the camera class and casts it into the scene. The scene object is used for inputting the scene from the .test files as well as finding an intersection of a ray with any polygon or sphere inside that scene. To help tackle this problem, the intersectionTeset object is used for individual ray polygon or sphere tests, so that the scene object deals with managing ray intersections with entire objects and then loops through each polygon in that object and runs the intersectionTest on each, where the intersectionTest object serves two purposes, to offer intersection testing helper functions and to store persistent data with regards to the current intersection point, normal, texture coordinates as well as a host of material properties for that given point of intersection.

The RayTracer class also includes a recursive ray tracing function which for each light in the scene creates a light object (light objects compute the specular and diffuse components as well as hard/soft shadows due to direction, point or area light sources). For each light in the scene the specular and diffuse components are summed up and added to the ambient and emissive components. Then depending whether the object is reflective or translucent, reflected and/or refracted rays will be recursively cast for n number of iterations where the final color will be a contribution of all three factors.

Our code implements and adheres to all the required assignment specifications. We chose to add some additional features including soft shadows, textures, models, bounding sphere acceleration and refraction. Area lights are used to achieve soft shadows by sampling several shadow rays from the intersection point to random points on the area light, the randomness eliminates banding. Textures are done in the standard way (interpolating the texture coordinates for each vertex using the barycentric coordinates in the intersection test). Models are inputted from .obj files and for each .obj file we average all the points to find a center for the model, and then get the farthest distance from the center to any given point and use that as the radius for a bounding sphere, thus when testing models we can do a quick ray-sphere intersection first and if the ray doesn't collide then we save having to do many expensive ray-triangle intersection tests. Finally translucency and dielectric values are supported which allows an object to support both refraction, reflection and standard shading all at the same time. The refracted ray is computed using Snells law and is thus physically correct.

Examples of soft shadows, textures and refraction can be seen in the "Spheres" screen-shot up above. The central sphere is mostly translucent (as can be seen by the checkerboard refracting off the top of it and the sky refracting off the bottom) while still maintaining a small amount of opacity which results in the specular shine as well as the diffuse shading, reflection and light shadow that contribute to its final appearance. The surrounding spheres are all perfect mirrors except for a slight diffuse and specular contribution.


Downloads
Source code, scenes, and executable can be downloaded here:

http://svn2.assembla.com/svn/graphics_hw4