CS184 Lecture 31 summary

Ray Tracing

So far our models of lighting have assumed that light goes from a source to a surface, and then directly to the viewer's eye. VRML and OpenGL handle occlusion of surfaces from the viewer, but not occlusion of the light source, i.e. shadows.

In many environments, the light from a source bounces off several objects before reaching the viewer. Ray tracing is a method for computing the illumination due to multiple specular reflections, or due to refraction in transparent media. It produces much more realistic images with shadows, reflections and refraction effects.

Basic ray tracing starts from the viewer:

Note that ray tracing this way deals with specular reflection only. The diffuse reflections cannot be handled this way because the rays spread in too many directions.

Here is a basic ray-traced image.

scm0.jpg (52706 bytes)

It uses Pixar shaders for carpet, wood, and stone, and BMRT shaders for brick and a shiny metal surface that acts like a mirror. Here is the rib source file for it.

For certain surfaces like glass, the ray will be split into a reflected ray and a transmitted ray. The bend of the refracted ray satisfies snells law. If N is the surface normal, L is the direction of the incoming ray, and T is the direction of the transmitted ray, then

n1 sin q1 = n2 sin q2

where n1 is the refractive index of the outside material, n2 is the refractive index of the inside material (where the T ray goes), q1 is the angle of the incoming ray (between N and L) and q2 is the angle of the outgoing ray (between N and T).

Here is the environment from before with a refractive object (a glass ball).

scm1.jpg (52637 bytes)

It uses the same shaders as before, plus the glass shader from BMRT. Think about why the sphere seems to reverse the left and right scenes behind it. Here is the source for it.

Shadows

Because ray tracing only handles specular reflections, it can't directly compute shadows on diffuse surfaces. This is evident from the images you've just seen. Instead, an extra step is used, by casting rays from each light source. These rays bounce off specular surfaces at the reflection angle, but will not bounce off purely diffuse surfaces. The strength of each reflection depends on the specular reflection coefficient of the surface hit by the ray.

Following this process, we get a brightness assigned to points on each surface based on the total light intensity of source rays that reach it. Then normal ray-tracing is applied starting from the viewer, resulting in an image with acceptable shadows.

Here is the last environment after shadow tracing is turned on.

scm2.jpg (48525 bytes)

Here is the rib source file. Notice that a single command has changed, namely that shadows have been turned on.

Notice how sharp the shadows are. This environment has light sources which are essentially point sources. Most physical light sources are area sources, and these will give more realistic soft shadows. See for example the dresser image below, modified from a file in the BMRT examples directory.

dresser.jpg (22670 bytes)

Distributed Ray Tracing

You can probably tell that the above method is rather limited in dealing with general surfaces. It only allows for rays that reflect exactly at the reflection angle. For most surfaces though, their specular reflection is in a cone of rays. The idea of distributed ray tracing is to bounce a ray off the surface randomly, using a probability distribution which is given, say, by the Phong or Halfway vector rules. One average, the reflected light intensity is then given exactly by the Phong or Halfway vector rules.

The difficulty with this approach is that we only get a random guess at the intensity of the traced ray each time it is cast. To make this approach viable it is necessary to cast rays many times for each pixel of the image. Here is the last environment with the mirrored surface changed so that it now reflects at a cone of angles.

scm3.jpg (42556 bytes)

This image was computed with 64 rays per pixel. Here is the rib source file.

Distributed ray tracing is generally very expensive because of the need to send many rays from each blurry surface point. But it does give excellent results. It accurately models the full range of effects due to specular reflection.