CS 435 Autumn 2000 --- Introduction to Interactive Graphics


Simple Ray Tracing Guide


Viewing

The simplest ray tracer does hidden surface removal, lighting, and shadows.

To simplify things further, you can trace the scene in a restricted world (eye) space by requiring the viewer to be at the origin, looking down the negative Z-axis 

To calculate the field of view, assume that your rays go from
X: -tan(theta) to tan(theta)
Y: -ratio*tan(theta) to ratio*tan(theta), where
ratio = (Vyt - Vyb)/(Vxr - Vxl) 

General Algorithm Outline


Ray Intersection

For this lab, you need to calculate the intersection of a parametric semi-infinite ray with a sphere:

Let the ray be R(t) = O + D*t
 

Rx = O.x + t* D.x
Ry = O.y + t* D.y
Rx = O.z + t* D.z
    where O is the origin of the ray, D is the direction of the ray, and t > 0 traces out the ray.


If we have a sphere centered at (cx,cy,cz) with radius r, then the points on the sphere satisfy
(x -cx)2 + (y -cy)2 + (z -cz)2= r2
To solve this, we put the ray's Rx, Ry, Rz into the sphere equation and solve for t:
(O.X + D.x * t - cx)2 + (O.y + D.y * t - cy)2 + (O.z + D.z * t - cz)2 = r2 or At2 + Bt + C = 0 with:
A = D.x2 + D.y2 + D.z2
B = 2 * (D.x * (O.x - cx) + D.y * (O.y - cy) + D.z * (O.z - cz))
C = (O.x - cx)2 + (O.y- cy)2 + (O.z - cz)2 - r2
So, the quadratic equation can be used to solve for the t's. If no real roots exist, then there is no intersection.
Choose the smallest t for the closest point..

David S. Ebert