CS-460/560, Week 15B
Spring, 1998
R. Eckert

RAY TRACING
SIMPLE PSEUDOCODE FOR A RECURSIVE RAYTRACER

depth = 0
for each pixel (x,y)
   calculate direction from eyepoint to pixel
   TraceRay (eyepoint, direction, depth, *color)
   FrameBuf[x,y] = color

TraceRay (start_point, direction_vector, recursion_depth, *color)
   if recursion_depth > MAXDEPTH
      color = Background_color
   else
      /* Interect ray with all objects */
      /* Find intersection point that is closest to start_point */
      if (no intersection)
           color = Background_color
      else
           local_color = contribution of local color model at int. pt.
           /* Calculate direction of reflection ray
           TraceRay (int. pt, refl_dir., depth+1, *refl_color)
           /* Calculate direction of transmitted ray
           TraceRay (int. pt., trans_dir., depth+1, *trans_color)
           color = Combine (local_color, refl_color, trans_color)