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