up to Schedule & Notes
CISC/CMPE 454, Lecture 17 - Ray Tracing

Ray Tracing

OpenGL rendering can render objects lit directly from a light source. Shadows, ambient light, and antialiasing (with an accumulation buffer) can be added to increase the realism of the image.

But other lighting effect cannot be done with OpenGL rendering. Some such effects are:

Ray tracing can produce the above effects.

Ray tracing involved sending a ray ($r_1$ in the image below) from the eye (at $x_1$ below), through the pixel, and into the scene. Where the ray first hits a surface (at $x_2$ below) in the scene, light is collected and sent back to the eye.

But the collection of light is recursive: One more ray ($r_2$ above) is sent along the ideal reflection direction of the incoming ray to collect incoming light from that direction. Another ray ($s_2$ above) is sent toward each light source to collect incoming light from that source. This is called the shadow ray because it determines whether the point is in shadow.

The recursive ray, $r_2$, hits a point in the scene, $x_3$. At $x_3$, another ray, $r_3$, is sent in the ideal reflection direction to collect incoming light, and another ray, $s_3$, is sent toward each light source to collect more incoming light.

The recursion, $r_1, r_2, r_3, r_4, \ldots$, continues until the last ray either (a) does not hit an object or (b) is terminated by the program, based on some criteria that will be described later.

Sometimes the ray toward the light is blocked by an object, like $s_4$ above, in which case no light arrives directly from the light source.

Local Light Calculation

The ray tracing function, $I(x_i,r_i)$, determines the light that returns backward along ray $r_i$ to the originating point, $x_i$.

The returned light depends upon the light collected from the two "bounced" rays, $r_{i+1}$ and $s_{i+1}$, and from the surface properties at $x_{i+1}$.

To simplify the notation below, let $x \triangleq x_{i+1}$, $r \triangleq r_{i+1}$, and $s \triangleq s_{i+1}$, as shown here:

Let $I(x,r)$ be the light returned from the ideal reflection direction. This is computed with a recursive call to the ray tracing function.

Let $I(x,s)$ be the light returned from the shadow ray. This is equal to the light intensity if $s$ is not blocked, and is equal to zero if $s$ is blocked.

Then the Phong illumination model can be used to compute the light going backward along $r_i$. Ignoring ambient and emissive components and assuming that the direction vectors all have unit length, the light from $\mathbf{r}$ contributes as follows:

$\begin{array}{rll} I_R(x_i,r_i) = & k_d \; (N \cdot L) \; I( x, r ) + k_s \; (R \cdot V)^n \; I( x, r ) & \textrm{where } N, L, R, V \textrm{ are the usual vectors} \\ = & k_d \; (N \cdot r) \; I( x, r ) + k_s \; (-r_i \cdot -r_i)^n \; I( x, r ) & \textrm{because } L = r \textrm{ and } R = V = -r_i \\ = & k_d \; (N \cdot r) \; I( x, r ) + k_s \; I( x, r ) & \textrm{because } (-r_i \cdot -r_i)^n = 1 \\ = & (k_d \; (N \cdot r) + k_s) \; I( x, r ) \end{array}$

The above equation means that $k_d + k_s \leq 1$; otherwise, the outgoing light could be greater than the incoming light.

Similarly, the light from $\mathbf{s}$ contributes as follows:

$\begin{array}{rll} I_S(x_i,r_i) = & k_d \; (N \cdot L) \; I( x, s ) + k_s \; (R \cdot V)^n I( x, s ) \\ = & k_d \; (N \cdot s) \; I( x, s ) + k_s \; (R \cdot -r_i)^n I( x, s ) & \textrm{where } R \textrm{ is computed as the reflection of } s_{r+1} \textrm{ around } N \\ = & (k_d \; (N \cdot s) + k_s \; (R \cdot -r_i)^n) \; I( x, s ) \\ \end{array}$

Then the total output is the sum of the two:

$I(x_i,r_i) = I_R(x_i,r_i) + I_S(x_i,r_i)$
up to Schedule & Notes