Home Page

Home Page

Comp 238

Programming Assignment 2:  Stochastic Ray Tracer

Page 1

Features

  • Object-oriented design
  • Simple scene description language (SDL)
  • Anti-aliasing via 4x4 jittered supersampling
  • Translucency and glossy reflections
  • Spherical light sources with soft shadows
  • Lighter shadows for translucent objects
  • Sphere, plane, and triangle primitives
  • Triangle meshes with hierarchical extents
  • Image textures with bilinear interpolation

Overview

This project represents the next evolution of my ray tracer. I implemented a ray tracer for the first time last spring in Comp 236. I performed a major upgrade to this initial implementation for the first homework of Comp 238. Now, I've made it stochastic. Specifically, I replaced the Whitted-style adaptive anti-aliasing scheme with 4x4 jittered supersampling. The reflection and refraction rays are now perturbed via jittered importance sampling. This produces glossy (i.e. blurry) reflections and "frosty" transparency (i.e. translucency). I also implemented jittered importance sampling of the spherical light sources for soft shadows. Lastly, I modified the shadow routine to create lighter shadows for transparent/translucent objects. Triangle meshes with hierarchical extents and image texturing with bilinear interpolation were already implemented as part of the "classic" ray tracer assignment. Refer to that write-up for more information.

Illumination Equation

The illumination equation did not actually change from the "classic" ray tracer implementation. However, I did not talk about it in that write-up, so I will briefly discuss it here.

The core illumination equation is:

Ia*ka + sum( Ip*kd*(N dot L) + Ip*ks*(N dot H)^specExp )

Ia is the ambient light intensity, Ip is the intensity of a particular light source, ka, kd, and ks are the material coefficients, and specExp is the phong exponent. (Note that all of the I's and k's are RGB color triples). More generally, this equation can be thought of as:

ambient + diffuse + phong specular

The shade method implements recursive reflections and transparency as described in Whitted's 1980 paper "An Improved Illumination Model for Shaded Display." So, our illumination equation becomes:

local ambient + local diffuse + local phong specular + reflections + refractions

Lastly, a texture can modulate the ambient and diffuse components:

texture*(local ambient + local diffuse) + local phong specular + reflections + refractions

Changing from "classic" to stochastic ray tracing does not really involve changing the illumination equation. Rather, various vectors involved in the shading calculation (e.g. reflection/refraction rays and shadow feelers) are randomly perturbed before being "sent on their way."

Note that with stochastic ray tracing and spherical light sources, it should be possible to eliminate the phong specular component and produce "real" highlights by intersecting the reflection rays with the light spheres. However, I did not attempt this.

Anti-Aliasing

For this project, anti-aliasing is accomplished via stochastic sampling. Specifically, I use a 4x4 jittered supersampling scheme. Each pixel is divided into a 4x4 regular grid. Then, a different randomly jittered ray is fired into each of the 16 sub-pixels. A uniform (within the limitations of the standard rand function) distribution is used to jitter the rays. Each pixel is then reconstructed with an 8x8 Gaussian filter kernel. The kernel overlaps a pixel's neighbors by half a pixel on all sides. This wide filter kernel is computationally more expensive than a simple average of the 16 sub-pixels (i.e. a box filter). However, it provides better frequency response, as shown below. Furthermore, the ray tracer spends most of its time in intersection calculations. The extra computation involved in using the Gaussian filter is insignificant compared to this.

 

Email Jason Stewart