Orthographic and Perspective Projection: Raycasting Object Space Renderer
Orthographic and Perspective Projection: Raycasting Object Space Renderer
Orthographic and
Perspective Projection
raycasting projection
object space renderer screen space renderer
We have been, until now, creating images by raycasting. By shooting rays from
the eyepoint out into the scene, we determine what is visible at the screen
pixel that the ray passes through. This type of renderer is called an object (or
scene) space renderer, since all viewing calculations are done in the world space
of the scene. This approach is depicted above to the left. We are about to
begin looking at OpenGL, which uses a very different approach. OpenGL uses
a screen space rendering approach, as depicted above to the right, which works
by:
63
64 CHAPTER 10. ORTHOGRAPHIC AND PERSPECTIVE PROJECTION
2
all of the pixels covered by triangle 1 the 1
Let us begin by considering how to transform the scene into camera coordinates.
We want to view the scene from the camera’s point of view. As a convention, in
camera space we will let the camera’s viewpoint be the origin xc = (0, 0, 0), the
camera’s view direction the negative z axis uc = (0, 0, −1), and the viewscreen’s
up direction the y axis (0, 1, 0). If the camera does not start out in this position
and orientation in world space, we have to make a change of coordinates. This
amounts to first translating the entire scene so that the camera is at the origin,
then rotating the scene about the x and y axes so that the view direction vector
uc is along the −z axis, and finally rotating the scene about the z axis so that
camera is in the desired orientation. This last operation can be facilitated by
specifying a vector that we will call vup , and rotating the scene so that vup lies in
the upper half of the y-z plane. The figure below illustrates this transformation.
vup
xc
uc
uý vúp
uć
uy ux́
uź o=xć
O
ux
uz
Mview = RT.
utx
R = uty ,
utz
since
1 0 0
Rux = 0 , Ruy = 1 , and Ruz = 0 .
0 0 1
xc uc
dn
Thus the transform is x0 = z x.
dn (x0, y0, z0)
z
The view volume is the volume swept out by the screen through space in the
projection system being used. For an orthographic projection, this is a rect-
angular solid, as shown in Figure 10.1. We use the distance dn to denote the
distance of the front face, or near plane, of the volume and df to denote an
arbitrary, or far plane depth of the volume. Screen space cameras are generally
set up to ignore (or clip away) any part of the scene not in the view volume.
The width and height of the volume are determined by camera screen width w
and height h.
xc
uc h
dn
df
far plane
near plane
w
uc
xc h
dn
df
1
has non-zero terms in the fourth row of the matrix and will transform points in
the homogenous coordinates to points in 4-space that are not homogenous.
In order to place projected points back into homogeneous coordinates, the per-
spective matrix multiplication is followed by a normalization of each transformed
point by dividing by its own w coordinate, to complete the perspective trans-
form.
Note that
x x
y y = x0 .
z = sz z + tz
Px = P
1 z
After normalizing by the w coordinate to place the result back in homogeneous
coordinates, we have
x/z
1 0 y/z
x = x00 =
1
.
z sz + t
z z
1
Thus, the final perspective matrix, transforming from camera space to the
canonical view volume is
2dn /w 0 0 0
0 2dn /h 0 0
Ppersp = P S =
0 dn +df 2dn df
0 dn −df dn −df
0 0 −1 0