Graphics Reference
In-Depth Information
color of a surface is determined by the relative amount of light scattered at each
wavelength, which we represent with a familiar RGB triple.
This surface mesh representation describes all the potentially visible points
at the set of locations
{
}
. To render a given pixel, we must determine which
potentially visible points project to the center of that pixel. We then need to select
the scene point closest to the camera. That point is the actually visible point for
the pixel center. The radiance—a measure of light that's defined precisely in Sec-
tion 26.7.2, and usually denoted with the letter L —arriving from that point and
passing through the pixel is proportional to the light incident on the point and the
point's reflectivity.
To find the nearest potentially visible point, we first convert the outer loop of
Listing 15.1 (see the next section) into an iteration over both pixel centers (which
correspond to rays) and triangles (which correspond to surfaces). A common way
to accomplish this is to replace “ for each visible point ” with two nested
loops, one over the pixel centers and one over the triangles. Either can be on the
outside. Our choice of which is the new outermost loop has significant structural
implications for the rest of the renderer.
P
15.2.3 Ray Casting: Pixels First
Listing 15.2: Ray-casting pseudocode.
for each pixel position ( x , y ) :
let R be the ray through
1
2
3
4
5
6
7
8
9
( x , y )
from the eye
for each triangle T :
let P be the intersection of R and T (if any)
sum =0
for each direction:
sum += ...
if P is closer than previous intersections at this pixel:
pixel [ x , y ]= sum
Consider the strategy where the outermost loop is over pixel centers, shown in
Listing 15.2. This strategy is called ray casting because it creates one ray per pixel
and casts it at every surface. It generalizes to an algorithm called ray tracing, in
which the innermost loop recursively casts rays at each direction, but let's set that
aside for the moment.
Ray casting lets us process each pixel to completion independently. This sug-
gests parallel processing of pixels to increase performance. It also encourages us
to keep the entire scene in memory, since we don't know which triangles we'll
need at each pixel. The structure suggests an elegant way of eventually processing
the aforementioned indirect light: Cast more rays from the innermost loop.
15.2.4 Rasterization: Triangles First
Now consider the strategy where the outermost loop is over triangles shown
in Listing 15.3. This strategy is called rasterization, because the inner loop is
typically implemented by marching along the rows of the image, which are called
rasters. We could choose to march along columns as well. The choice of rows is
historical and has to do with how televisions were originally constructed. Cathode
ray tube (CRT) displays scanned an image from left to right, top to bottom, the
way that English text is read on a page. This is now a widespread convention:
 
 
 
 
Search WWH ::




Custom Search