An Introduction to Ray Tracing CS /27/1998 Vic Baker
What is Ray Tracing? n “Ray Tracing” determines the visibility of surfaces by tracing imaginary rays of light from the viewer’s eye to the objects in the scene n Ray Tracing evolved from an algorithm used to simulate trajectories of ballistic projectiles and nuclear particles
Ray Tracing Algorithm Select center of projection and window on viewplane for (each scan line in image) { for (each pixel in scan line) { determine ray from center of projection through pixel; for (each object in scene) { if ( object is intersected and is closest thus far ) record intersection and object name; } set pixel’s color to that at closest object intersection; }
Why Speed Up Ray Tracing? n Depending on the output size of a ray traced image, as well as the complexity of the scene itself, it is not uncommon for a ray traced image to take minutes or days to render!!!! n A 1024x1024 image requires that 1 million pixels be calculated!!!!!
Why Speed Up Ray Tracing? n Since ray tracing calculates every pixel’s color, a picture of size 512 x 512 contains pixels that require a color which is dependent on its distance from the COP, your eye. n A 1024x768 image has pixels to calculate independently!
A Minimal Ray Tracing Program n In an attempt to investigate how computationally demanding rendering a 3D scene is, I will demonstrate a minimal ray tracing program known as Minray.
The History of Minray.c n Paul Heckbert (CMU, Pixar) issued a challenge to the graphics community to write the smallest ray tracing program possible. n Minray is the result of taking the best portions of the best entries and combining them into a ray tracer
Minray hierarchy chart
Frequency chart for a 32x32 image
vdot() n Calculates the dot product for two vectors n Each call to vdot requires 113 clock cycles n That’s * 113 = 13,670,514 clock cycles for a 32x32 image
vcomb() n Vcomb adds two vectors n Each call to vcomb requires 155 clock cycles n That’s 155 * = 15,408,240 clock cycles for a 32x32 image
vunit() n Normalizes vectors n Makes calls to vdot and vcomb n Costs 331 clock cycles to execute n That’s 331 * = 5,278,126 clock cycles
intersect() n Determines if a ray intersects an object n Requires vdot() and vcomb() n Costs 2547 clock cycles n Total cost for a 32x32 image is 9011 * 2547 = 22,951,017 clock cycles
trace() n Keeps track of nearest intersection of object and maps color to pixel n Costs 141 * 5998 = 845,718 clock cycles for a 32x32 image
How can we speed ray tracing up? n By using loop unrolling, straight-lining code, as well as using macros instead of function calls, you can drastically reduce overhead
What’s out there? n A good ray tracing program is the POV- Ray. n Let’s see some examples...