next up previous
Next: ii_ray_tr Up: ii_ray_tr Previous: ii_ray_tr

1. The setup

To keep things simple, we shall concentrate on a single convex object with a diffusely reflective surface, illuminated by a single light source of monochrome light at infinity. The corresponding setup is shown in Figure [*]. We take the viewpoint to be $ (0,0,H)$ (with $ H > 0$). The object is shown on the side of the viewplane with $ z < 0$, but it could actually be anywhere with $ z < H$. The light source is at infinity with direction given by the unit vector    s$ $.

Figure: Setup for ray-tracing
book/14dir/setup.eps

Physically, light travels from the light source to the object and then to the viewpoint (the eye). This will not work computationally, however, since we would have to trace a great number of rays, only a few of which would reach the eye. A much easier procedure is to trace the rays in the opposite direction, one for each pixel on the screen. The lines involved are the same either way!



1.1 Method: For each pixel position $ P = (a,b,0)$ in the viewplane (screen):

Step 1. Find the equation of the line (ray) from the viewpoint $ (0,0,H)$ to $ P = (a,b,0)$. This will be x$ = (1-t)(0,0,H) +
t(a,b,0)$, which simplifies to x$ = (at,bt,(1-t)H)$.

Step 2. Find the point $ Q$ where this line first intersects the object, if it does at all. (If it does not intersect the object, then the brightness of the pixel is 0; stop here.)

Step 3. Find the outward unit normal n at $ Q$.

Step 4. Use ``Phong shading'': The brightness of the pixel at $ P$ is n$ \cdot$   s, representing a fraction of the maximum possible brightness, provided n$ \cdot$   s$ \geq
0$; otherwise the brightness is 0. This formula does not involve the direction of the ray itself, because diffuse reflection scatters light equally in all directions.



1.2 Example

Suppose the viewpoint is $ (0,0,4)$, the lighting direction is s$ = (0,1,0)$ (straight up, which is the positive $ y$ direction), the object is the sphere of radius 3 centered at $ (0,0,-3)$, and we are interested in the pixel at $ (1,1)$, so $ P = (1,1,0)$. The equation of the sphere is then

$ (x-0) ^ 2 + (y-0) ^ 2 + (z-(-3)) ^ 2 = 3 ^ 2$, or

$ x ^ 2 + y ^ 2 + (z+3) ^ 2 = 9$.

In Step 1, the line is x$ = (t,t,4-4t)$.

In Step 2, we simply substitute $ x=t$, $ y=t$, $ z = 4-4t$ into the equation for the sphere. We get $ t ^ 2 + t ^ 2 + (7-4t) ^ 2 = 9$. Expanding and collecting terms we get $ 18 t ^ 2 -56 t + 40 = 0$, or after division by 2 to simplify, $ 9 t ^2 -28 t + 20 = 0$.

By the quadratic formula, the roots are $ t = {\frac{\displaystyle -(-28) \pm \sqrt{(-28) ^ 2
-4 \cdot 9 \cdot 20}}{\displaystyle 2 \cdot 9}}$ $ = $ $ {\frac{\displaystyle 14 \pm \sqrt{14 ^ 2 - 180}}{\displaystyle 9}}$ $ = $ $ {\frac{\displaystyle 14 \pm 4}{\displaystyle 9}}$, so $ t = \frac {10}9$ or $ t = 2$.

Because the ray starts at the viewpoint with $ t=0$, the first time it reaches the sphere is at $ t = \frac {10}9$, which corresponds to the point $ Q = (\frac {10}9,\frac {10}9,-\frac
49)$.

In Step 3, notice that the equation for the sphere has the form $ F(x,y,z)=c$, a ``level surface'' of $ F$. One normal is therefore the gradient, $ \nabla F = (2x,2y,2(z+3))$, which at $ Q$ is $ (\frac {20}9, \frac {20}9, \frac {46}9)$ $ = $ $ \frac
29 (10,10,23)$. Because $ F(x,y,z)$ for the sphere grows from the center out, the gradient gives an outward normal.

Now we need to normalize the gradient to get the unit outward normal vector n. It is harmless to scale first by a positive scalar, so let's leave off the factor of $ \frac 29$ and use the outward normal $ (10,10,23)$. The length of this vector is $ \sqrt{10 ^ 2 + 10 ^ 2 + 23 ^ 2}$ $ = $ $ \sqrt
{729}$ $ = $ $ 27$, so the unit outward normal is n$ =
(\frac {10}{27}, \frac {10}{27}, \frac {23}{27})$.

In Step 4, n$ \cdot$   s$ = (\frac {10}{27}, \frac
{10}{27}, \frac {23}{27}) \cdot (0,1,0) = \frac {10}{27}$. Again, this is the fraction of the maximum possible brightness.




next up previous
Next: ii_ray_tr Up: ii_ray_tr Previous: ii_ray_tr
Kirby A. Baker 2002-03-07