Project 3: Trace

 

Project 3: Trace

Assigned: Tuesday, 2 November 1999
Due: Tueday, 16 November 1999
Artifact: Tuesday, 23 November 1999


Project Description

Trace is a program that constructs recursively ray-traced images of fairly simple scenes.

Getting Started

To install the starting point source code, copy all the files from here. In the "examples" subdirectory, you'll find some sample scene files (all the files with the .ray extension). These are text files that describe some geometry and the coloring that should be applied to them.

Running the Sample

Before you begin coding, you should run the sample solution. It has all of the requirements implemented.
 
 

Creating Your Own Scenes

As you get into the project, you'll probably want to use some scenes of your own invention. For this you can either write your own .ray files, or you can use the modeler program from the last project to create them for you.

 If you are interested in writing your own files from scratch, a help page on the file format is available.

 To use the modeler, you first need to download this updated version that has the ability to write .ray files. Then, run the modeler and open your model like before. Adjust any sliders or widgets to values you like, then select the "Write raytrace file..." option from the file menu.

Required Extensions

After running the sample solution, you should build the skeleton code and see how it compares. You will probably notice that there is a significant difference in the quality of images rendered with the two versions. This suggests what parts of the raytracer have been written and what parts are left undone.

 If you compare the outputs of the skeleton and solution, you will see that the basic geometry-handling code is done. The skeleton code is able to cast rays into an image and draw color on the screen, resulting in flat-shaded polygonal shapes appearing a pixel at a time. In essence, this is what is happening. The skeleton code is doing ray-casting and nothing more. All the code to cast a ray and find object intersections exists, and your job is to expand that into ray-tracing.

 Specifically, each group must implement recursive ray tracing as described in class. This entails making the following extensions to the program:
 
 

     
    Extension Watt Foley, et al. Glassner
    Phong specular-reflection model 4.3 16.1 and 16.2.5
    Contribution from:
      multiple light sources,
      light attenuation,
      and these additional types of lights:
    • Directional lights 
    • Point lights
    - 16.1 (particularly in 16.1.5 and 16.1.6)
    Shadows 8.7 16.12 and 16.4
    Reflection 8.5.2 and 8.6 16.12 4.2.1
    Refraction 8.5.2 and 8.6 16.12 4.2.3 - 4.2.7
Your raytracer should recursively trace rays to account for these. Recursion should proceed to a maximum depth as set in a global variable RayGlobals::recursion_depth.
 
 

Getting Started

The Trace project is a very large collection of files and object-oriented C++ code. Fortunately, you only need to work directly with a small subset of it. However, you will probably want to spend a bit of time getting familiar with the layout and class hierarchy at first, so that when you code you know what classes and methods are available for your use.

 The starting point for where raytracing begins, and where you will be needing to add a lot of functionality, is in the trace.cpp file. This is a good file to start studying and exploring what methods get called and what they do.
 
 

Grading

This assignment will be worth a total of 10 points. The required extensions will be graded as follows:
 
Phong specular-reflection model:  2 points
Directional Lights: 1 point 
Point Lights: 1 point 
Shadows: 1 points 
Reflection: 2 points
Refraction: 2 points
Artifact: 1 point


Total: 10 points

 

Bells and Whistles

There is a lot of useful information on ray tracing in the books by Watt, Foley et al, and Glassner.  Glassner's book on ray tracing is a very comprehensive exposition of a whole number of ways ray tracing can be expanded or optimized (and it's really well written!). If you're planning on implementing any of these bells and whistles, you are encouraged to read the relevant sections in these books as well.

Remember that you'll need to establish to our satisfaction that you've implemented the extension! You should have test cases that clearly demonstrate the effect of the code you've added to the ray tracer. Sometimes different extensions can interact, making it hard to tell how each contributed to the final image. So it's also helpful to add controls to selectively enable and disable your extensions.

[whistle] Implement an adaptive termination criterion for tracing rays, based on ray contribution (see Watt, Section 8.10.1).

[bell] While the skeleton code handles materials with arbitrary indices of refraction, it assumes that objects don't intersect one another. It breaks down when objects intersect or are wholly contained inside other objects. Add support to the refraction code to handle these cases.

[bell] Implement spot lights.
 
 

[bell] Add a menu option that lets you specify a background image to replace the environment's ambient color during the rendering.
 
 

[bell+whistle] Implement more versatile lighting controls, such as the Warn model described in Foley 16.1.5. This allows you to do things like control the shape of the projected light.
 
 

[bell+whistle] Implement antialiasing by adaptive supersampling, as described in Foley, et al., 15.10.4.
 
 

[bell][bell] Implement bump mapping (Watt, Section 7.8; Foley, et al., 16.3.3).
 
 

[bell][bell] Implement solid textures or some other form of procedural texture mapping, as described in Foley, et al., 20.1.2 and 20.8.3. Solid textures are a way to easily generate a semi-random texture like wood grain or marble.
 
 

[bell][bell] Add some new types of geometry to the ray tracer. Consider implementing torii or general quadrics. Many other objects are possible here.
 
 

[bell][bell] Add support for height-fields. Click here for a discussion on what they are and how they can be generated.
 
 

[bell][bell] Extend the ray-tracer to optionally create a Single Image Random Dot Stereogram (SIRDS) instead of a standard picture. Click here for a brief explanation of how to view SIRDs, and click here to read a paper on how to make them. This page may also have some helpful information. [Note from Craig: I can't see SIRDS, but you better not try to fool me!]
 
 

[bell][bell]for first,[bell]for each additional
Implement stochastic or distributed ray tracing to produce one or more or the following effects: depth of field, soft shadows, motion blur, glossy reflection or antialiasing (See Glassner, chapter 5, or Foley, et al., 16.12.4).
 
 

[bell][bell][bell] Add texture mapping support to the program. The most basic kind of texture mapping is to apply the map to the diffuse colour of a surface. But many other parameters can be mapped. Reflected colour can be mapped to create the sense of a surrounding environment. Transparency can be mapped to create holes in objects. Additional (variable) extra credit will be given for such additional mappings.  (See Watt, Sections 7.5 and 7.6).
 
 

[bell][bell][bell] Use data generated by the raytracer to implement a non-photorealistic rendering style. See, for example, Cassidy Curtis's excellent Loose and Sketchy Animation page.
 
 

[bell][bell][bell] Add some higher-level geometry to the ray tracer, such as surfaces of revolution, extrusions, metaballs or blend surfaces.
 
 

[bell][bell][bell] Implement ray-intersection optimization using either hierarchical bounding volumes or spatial subdivision (See Watt 8.10.2, Glassner 6.4 and 6.5, Foley, et al., 15.10.2). This is a pretty technical extension, but it results in a big win: you'll be able to raytrace very large, complicated scenes much, much faster than before!
 
 

[bell][bell][bell][bell] Implement a more realistic shading model. Credit will vary depending on the sophistication of the model. A simple model factors in the Fresnel term to compute the amount of light reflected and transmitted at a perfect dielectric (e.g., glass). A more complex model incorporates the notion of a microfacet distribution to broaden the specular highlight. Accounting for the color dependence in the Fresnel term permits a more metalic appearance. Even better, include anisotropic reflections for a plane with parallel grains or a sphere with grains that follow the lines of latitude or longitude. Sources: Watt, Section 4.10; Foley et al, Section 16.7; Glassner, Chapter 4, Section 4; Ward's SIGGRAPH '92 paper; Schlick's Eurographics Rendering Workshop '93 paper.

This all sounds kind of complex, and the physics behind it is. But the coding doesn't have to be. It can be worthwhile to look up one of these alternate models, since they do a much better job at surface shading.

Theoretically, you could also invent new shading models. For instance, I'm really interested in trying to implement a less realistic model! Could you implement a shading model that produces something that looks like cel animation? Variable extra credit will be given for these "alternate" shading models.

[bell][bell][bell][bell] Implement CSG, constructive solid geometry. This extension allows you to create very interesting models. See page 108 of Glassner for some implementation suggestions. An excellent example of CSG was built by a grad student here in last winter's grad graphics course.
 
 

[bell][bell][bell][bell] Add particle systems (see Watt, Section 12.2).
 
 

Note: Do not consider attempting either of these extensions unless you plan to spend every minute of every day for the next two weeks hacking the ray tracer.

[bell][bell][bell][bell][bell][bell] Implement radiosity to correctly handle diffuse interreflection (see Watt, Chapter 10).
 
 

[bell][bell][bell][bell][bell][bell][bell] Create a system to do rotoscoping, the embedding of synthetic objects in a real-world scene. For instance, given a video of a room, you need to somehow derive the camera position and use it to raytrace an object in a virtual version of the room. Extract the object and composite it back into the original video. For extra fun, try to match up the depth-of-field of the camera so that the synthetic object has a level of focus appropriate for its distance from the real camera.
 


There are innumerable ways to extend a ray tracer. Think about all the visual phenomena in the real world. The look and shape of cloth. The texture of hair. The look of frost on a window. Dappled sunlight seen through the leaves of a tree. Fire. Rain. The look of things underwater. Prisms. Do you have an idea of how to simulate this phenomenon? Better yet, how can you fake it but get something that looks just as good? You are encouraged to dream up other features you'd like to add to the base ray tracer. Obviously, any such extensions will receive variable extra credit depending on merit. Feel free to discuss ideas with the course staff before proceeding!