
Ray Tracer
Write a ray tracer that displays basic shapes, lights, and materials. Ray tracing is, in some sense, the most natural way to generate images. By generating and casting rays, the ray tracer is able determine what color we would see if we looked in some direction from some point of view. Within the accuracy of the scene and shading models and with enough computing time, the images produced by a ray tracer can be physically accurate and can appear indistinguishable from real images. The ray tracer you are required to write for this assignment will not be able to produce physically accurate images since it is very basic, containing just the key elements regarded to be a ray tracer.
The basic idea behind ray tracing is to model the movement of photons as they travel along their path from a light source, to a surface, and finally to a viewer's eye. Tracing forward along this path is difficult, since it can be unclear which photons will make it to the eye, especially when photons can bounce between objects several times along their path (and in unpredictable ways). To simplify the system, these paths are computed in reverse; that is, rays originate from the position of the eye. Color information, which depends on the scene's light sources, is computed when these rays intersect an object, and is sent back towards the eye to determine the color of any particular pixel.
A ray tracer computes images in image order, meaning that the outer loop visits pixels one at a time. (In our framework the outer loop is found in the class RayTracer
). For each pixel it performs the following operations:
- Ray generation, in which the viewing ray corresponding to the current pixel is found. The calculations depend on the characteristics of the camera: where it is located, which way it is looking, etc. (In our framework, ray generation happens in the class
Camera
— you must complete this code). - Ray intersection, which determines the visible surface at the current pixel by finding the closest intersection between the ray and a surface in the scene. (In our framework, ray intersection is handled by subclasses of
Surface
— you must complete this code). - Shading, in which the color of the object, as seen from the camera, is determined. Shading accounts for the effects of illumination and shadows. (In our framework, shading happens in the subclasses of
Shader
— you must complete this code).
Minimally, your ray tracer must support:
- Spheres and triangle meshes
- Lambertian (diffuse) and Phone (specular) shading with textures
- Point lights with shadows (that provide illumination that does not fall off with distance)
Your ray tracer will read files in an XML file format and output PNG images. All data regarding the scene to be traced should be read from the given data file. You do not need to worry about malformed input, either syntactically or semantically. For instance, you will not be given a sphere with a negative radius or a scene without a camera. Additionally, you do not have to worry about the camera being inside an object.
You will be given a coding framework to spare you from the mundane details of GUI, I/O, vector arithmetic, etc. However, you will need to complete all of the methods of the ray tracer. Feel free to create whatever new classes or methods you think are necessary. In the end, if your program works, and is understandable, you will receive full credit.
Extra Credit
There are many possible additions to the basic ray tracer. You can earn bonus points with extremely creative or artistic solutions. Make sure that you mention your assumptions, extra features, and how to run your program (especially with regard to command line arguments) in your README file.
To get you started, here are some extra credit ideas:
- Create new and creative data files to test/show-off your project
- Support reflection among objects (i.e., mirrors)
- Support refractive objects (i.e., transparency)
- Intersect with more complex surfaces (i.e., cylinders, cones, or arbitrary functions)
- Use images to define textures (colors) on your objects
- Worry about efficiency; there are many optimizations that you can do to minimize the number of objects you must intersect with or the number of calculations each intersection requires
These features will require understanding the code framework and determining how to modify it in places not marked by a TODO
comment.
Resources
- Chapter 10 from Fundamentals of Computer Graphics by P. Shirley, M. Ashikhmin, and S. Marschner
- Introduction to Ray Tracing from Scratchapixel
- Ray Tracing Tutorial from SIGGRAPH HyperGraph