Graphics Reference
In-Depth Information
Inline Exercise 15.5: Mandatory; do not continue until you have done this:
Draw a schematic diagram of this scene from three viewpoints.
1. The orthographic view from infinity facing along the x -axis. Make z
increase to the right and y increase upward. Show the camera and its
field of view.
2. The orthographic view from infinity facing along the
y -axis. Make x
increase to the right and z increase downward. Show the camera and its
field of view. Draw the vertex normals.
3. The perspective view from the camera, facing along the
z -axis; the
camera should not appear in this image.
15.4 A Ray-Casting Renderer
We begin the ray-casting renderer by expanding and implementing our initial
pseudocode from Listing 15.2. It is repeated in Listing 15.11 with more detail.
Listing 15.11: Detailed pseudocode for a ray-casting renderer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for each pixel row y :
for each pixel column x :
let R = ray through screen space position
( x + 0 . 5, y + 0 . 5 )
closest =
for each triangle T :
d = intersect( T , R )
if ( d < closest )
closest = d
sum =0
let P be the intersection point
for each direction
v i :
sum += light scattered at P from
v i to v o
image [ x , y ]= sum
The three loops iterate over every ray and triangle combination. The body of
the for-each-triangle loop verifies that the new intersection is closer than previous
observed ones, and then shades the intersection. We will abstract the operation of
ray intersection and sampling into a helper function called sampleRayTriangle .
Listing 15.12 gives the interface for this helper function.
Listing 15.12: Interface for a function that performs ray-triangle
intersection and shading.
1
2
3
bool sampleRayTriangle( const Scene & scene, int x, int y,
const Ray &R, const Triangle &T,
Radiance3 & radiance, float & distance);
The specification for sampleRayTriangle is as follows. It tests a particular
ray against a triangle. If the intersection exists and is closer than all previously
observed intersections for this ray, it computes the radiance scattered toward the
viewer and returns true . The innermost loop therefore sets the value of pixel ( x , y )
 
 
 
Search WWH ::




Custom Search