How does Ray Tracing Work?


We can "see" objects around us because light rays hit the object and travel to our eyes. Each object has a characteristic texture, color, shinyness which is a result of the way in which the light rays interact with the object. For example, a red object appears red because red light is reflected and blue and green light is absorbed. Mirrors reflect light essentially unchanged while objects with dull surfaces tend to disperse an incoming light ray in lots of directions.

Ray tracing is a method of generating realistic images in computer graphics by simulating the the interaction of light with surfaces. Light rays are emitted from light sources and are traced through the scene. The illumination and reflection properties of surfaces determine how the rays are reflected or transmitted at each intersection. The ray tracing process also results in realistic looking shadows and hidden surface removal.

The number of light rays we see are essentially infinite so we can not trace all rays. We are in fact only interested in those rays that reach our eyes. As a result we trace backwards, from our eye to a light source. If no such ray exists then we don't see anything.

Furthermore, when looking at a computer screen we are only concerned with what color to set each pixel on the screen. As a result, we really only care about the light rays that pass through a pixel on the screen and hit our eyes. Thus if we are drawing a sceen in a 100x100 window we really only need to trace 10,000 rays. Of course, this number is increased because each ray follows an eratic path as it is reflected off various objects.

Ray Tracing:

Basic Algorithm


subroutine RayTrace
{
	For each row of pixels {
		For each pixel in row {
			Determine ray from camera to pixel
			CalculateRayShade(ray)
		}
	}
}
subroutine CalculateRayShade(ray)
{
	For each object in scene {
		Determine point of intersection (if any) 
	 	 of object with ray.
	}
	Determine the closest (if any) intersection point.
	For each light in scene {
	 	Send out a shadow ray from intersection point to light.
		For each object in scene {
			Determine if shadow ray intersects the object.
		}
	  	If shadow ray does not intersect any object {
	    		Calculate the local color of that object at the intersection point.
	    		CalculateRayShade(reflected ray)
	    		CalculateRayShade(transmitted ray)
	    		Set the pixel color to a weighted average of the
			  local, reflected, and transmitted colors.
		}
}

For more details, see ray.pdf and rayImplement.pdf.


[top]

[Home]