Recursive Ray-Tracing Shell

from J. D. Foley and A. Van Dam Fundamentals od Computer Graphics

select center of projection(cp) and window on view plane;
for (each scan line in the image ) {
	for (each pixel in scan line ) {
		determine  ray from the cp through the pixel ; 
		pixel = RT_trace(ray, 1);
	}
}

/* Intersect ray with objects and compute shade at closest intersection.	*/
/* Depth is current depth in ray tree.	*/

RT_color RT_trace (RT_ray ray; int depth)
{
	determine closest intersection of ray with an object;
	if (object hit) {
		compute normal at intersection;
		return RT_shade (closest object hit, ray, intersection, normal, depth);
	}
	else
		return BACKGROUND_VALUE;
}

/* Compute shade at point on object, tracing rays for shadows, reflection, 	*/ /* refraction.			*/

RT_color RT_shade (
	RT_object object,	/* Object intersected	*/
	RT_ray ray,			/* Incident ray	*/
	RT_point point,	/* Point of intersection to shade	*/
	RT_normal normal,	/* Normal at point	*/
	int depth )			/* Depth in ray tree	*/
{
RT_color  color;		/* Color of ray	*/
RT_ray rRay, tRay, sRay;	/* Reflected, refracted, and shadow rays	*/

	color = ambient term ;
	for ( each light  ) {
		sRay = ray to light from  point;
		if (  dot product of normal and direction to light is positive  ) {
			compute how much light is blocked by opaque and transparent 				surfaces, and use to scale diffuse and specular terms before
			adding them to color.
		}
	}
	if ( depth < maxDepth ) {	/* Return if depth is too deep. 	*/
		if ( object is reflective ) {
			rRay = ray in reflection direction from point ;
			rColor = RT_trace(rRay, depth + 1);
			scale   rColor by the specular coefficient and add to color ;
		}
		if ( object  is transparent  ) {
			tRay = ray in refraction direction from point ;
			if ( total internal reflection does not occur  ) {
				tColor = RT_trace(tRay, depth + 1);
				scale  tColor by transmission coefficient and add to color ;
			}
		}
	}
	return color;	/* Return the color of the ray	*/
}

Last Updated: December 20,2005, 10:54 a.m. by

Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #202WVH,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/COM3370/RRTrace.html