Upload
kelley-hall
View
214
Download
0
Embed Size (px)
Citation preview
What is Ray Tracing?
“Ray Tracing” determines the visibility of surfaces by tracing imaginary rays of light from the viewer’s eye to the objects in the scene
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?
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!!!!
A 1024x1024 image requires that 1 million pixels be calculated!!!!!
Why Speed Up Ray Tracing?
Since ray tracing calculates every pixel’s color, a picture of size 512 x 512 contains 262144 pixels that require a color which is dependent on its distance from the COP, your eye.
A 1024x768 image has 786432 pixels to calculate independently!
A Minimal Ray Tracing Program
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
Paul Heckbert (CMU, Pixar) issued a challenge to the graphics community to write the smallest ray tracing program possible.
Minray is the result of taking the best portions of the best entries and combining them into a ray tracer
Minray hierarchy chartP ip e lin e fo r M in ray.c
vcom b vd ot
vu n it() vcom b ()
vd o t vcom b
in te rsec t vd o t vcom b vu n it
trace()
m a in ()
Frequency chart for a 32x32 image
0
20000
40000
60000
80000
100000
120000
140000
vdotvcombvunitintersecttracemain
vdot()
Calculates the dot product for two vectors Each call to vdot requires 113 clock cycles That’s 120978 * 113 = 13,670,514 clock cycles
for a 32x32 image
vcomb()
Vcomb adds two vectors Each call to vcomb requires 155 clock
cycles That’s 155 * 99408 = 15,408,240 clock
cycles for a 32x32 image
vunit()
Normalizes vectors Makes calls to vdot and vcomb Costs 331 clock cycles to execute That’s 331 * 15946 = 5,278,126 clock
cycles
intersect()
Determines if a ray intersects an object Requires vdot() and vcomb() Costs 2547 clock cycles Total cost for a 32x32 image is 9011 * 2547
= 22,951,017 clock cycles
trace()
Keeps track of nearest intersection of object and maps color to pixel
Costs 141 * 5998 = 845,718 clock cycles for a 32x32 image
How can we speed ray tracing up? By using loop unrolling, straight-lining
code, as well as using macros instead of function calls, you can drastically reduce overhead