You are on page 1of 8

3D Polygon Rendering

• Many applications use rendering of 3D polygons


with direct illumination
3D Polygon
Rendering Pipeline
Adam Finkelstein
Princeton University
COS 426, Spring 2003

3D Polygon Rendering 3D Polygon Rendering


• Many applications use rendering of 3D polygons • Many applications use rendering of 3D polygons
with direct illumination with direct illumination

Quake II
(Id Software)

Ray Casting Revisited 3D Polygon Rendering


• For each sample … • What steps are necessary to utilize
o Construct ray from eye position through view plane spatial coherence while drawing
o Find first surface intersected by ray through pixel these polygons into a 2D image?
o Compute color of sample based on surface radiance

More efficient algorithms


utilize spatial coherence!

1
3D Rendering Pipeline (direct illumination) Example: OpenGL
3D Geometric Primitives

Modeling
Modeling Modeling
Modeling
Transformation
Transformation Transformation
Transformation
glBegin(GL_POLYGON);
glVertex3f(0.0, 0.0, 0.0);
Lighting
Lighting Lighting
Lighting glVertex3f(1.0, 0.0, 0.0);
This is a pipelined
glVertex3f(1.0, 1.0, 1.0);
Viewing
Viewing
sequence of operations Viewing
Viewing glVertex3f(0.0, 1.0, 1.0);
Transformation
Transformation to draw a 3D primitive Transformation
Transformation glEnd();
Projection
into a 2D image Projection
Projection Projection
Transformation
Transformation Transformation
Transformation

OpenGL executes steps


Clipping
Clipping Clipping
Clipping
of 3D rendering pipeline
Scan Scan
for each polygon
Scan Scan
Conversion
Conversion Conversion
Conversion

Image Image

3D Rendering Pipeline (for direct illumination) 3D Rendering Pipeline (for direct illumination)
3D Geometric Primitives 3D Geometric Primitives

Modeling
Modeling Modeling
Modeling
Transformation
Transformation Transform into 3D world coordinate system Transformation
Transformation Transform into 3D world coordinate system

Lighting
Lighting Lighting
Lighting Illuminate according to lighting and reflectance

Viewing
Viewing Viewing
Viewing
Transformation
Transformation Transformation
Transformation

Projection
Projection Projection
Projection
Transformation
Transformation Transformation
Transformation

Clipping
Clipping Clipping
Clipping

Scan
Scan Scan
Scan
Conversion
Conversion Conversion
Conversion

Image Image

3D Rendering Pipeline (for direct illumination) 3D Rendering Pipeline (for direct illumination)
3D Geometric Primitives 3D Geometric Primitives

Modeling
Modeling Modeling
Modeling
Transformation
Transformation Transform into 3D world coordinate system Transformation
Transformation Transform into 3D world coordinate system

Lighting
Lighting Illuminate according to lighting and reflectance Lighting
Lighting Illuminate according to lighting and reflectance

Viewing
Viewing Transform into 3D camera coordinate system Viewing
Viewing Transform into 3D camera coordinate system
Transformation
Transformation Transformation
Transformation

Projection
Projection Projection
Projection Transform into 2D camera coordinate system
Transformation
Transformation Transformation
Transformation

Clipping
Clipping Clipping
Clipping

Scan
Scan Scan
Scan
Conversion
Conversion Conversion
Conversion

Image Image

2
3D Rendering Pipeline (for direct illumination) 3D Rendering Pipeline (for direct illumination)
3D Geometric Primitives 3D Geometric Primitives

Modeling
Modeling Modeling
Modeling
Transformation
Transformation
Transform into 3D world coordinate system Transformation
Transformation
Transform into 3D world coordinate system

Lighting
Lighting Illuminate according to lighting and reflectance Lighting
Lighting Illuminate according to lighting and reflectance

Viewing
Viewing Transform into 3D camera coordinate system Viewing
Viewing Transform into 3D camera coordinate system
Transformation
Transformation Transformation
Transformation

Projection
Projection Transform into 2D camera coordinate system Projection
Projection Transform into 2D camera coordinate system
Transformation
Transformation Transformation
Transformation

Clipping
Clipping Clip primitives outside camera’s view Clipping
Clipping Clip primitives outside camera’s view

Scan
Scan Scan
Scan
Conversion
Conversion Conversion
Conversion Draw pixels (includes texturing, hidden surface, ...)

Image Image

Transformations Transformations
3D Geometric Primitives p(x,y,z)
3D Object Coordinates Transformations map points from
Modeling
Modeling
Transformation
Transformation Transform into 3D world coordinate system one coordinate system to another
Modeling
Modeling
Transformation
Transformation
Lighting
Lighting Illuminate according to lighting and reflectance 3D World Coordinates
Viewing
Viewing 3D Camera
Transformation
Transformation y
Coordinates
Viewing
Viewing Transform into 3D camera coordinate system
Transformation
Transformation
3D Camera Coordinates z 3D Object
Coordinates
Projection
Projection Transform into 2D camera coordinate system Projection
Projection x
Transformation
Transformation Transformation
Transformation

2D Screen Coordinates
Clipping
Clipping Clip primitives outside camera’s view
Window-to-Viewport
Window-to-Viewport
Transformation
Transformation
Scan
Scan
Conversion
Conversion Draw pixels (includes texturing, hidden surface, etc.) 3D World
2D Image Coordinates
Coordinates
Image
p’(x’,y’)

Viewing Transformations Camera Coordinates


p(x,y,z) • Canonical coordinate system
3D Object Coordinates
o Convention is right-handed (looking down -z axis)

}
Modeling
Modeling
Transformation
Transformation o Convenient for projection, clipping, etc.
3D World Coordinates
Camera up vector
Viewing
Viewing maps to Y axis
Transformation
Transformation y
3D Camera Coordinates Viewing Transformations
Projection
Projection
Transformation
Transformation

2D Screen Coordinates

Window-to-Viewport
Window-to-Viewport
Transformation
Transformation Camera right vector
Camera back vector
maps to X axis
2D Image Coordinates maps to Z axis
p’(x’,y’) (pointing out of page) z x

3
Viewing Transformation Finding the viewing transformation
• Mapping from world to camera coordinates • We have the camera (in world coordinates)
o Eye position maps to origin
o Right vector maps to X axis
• We want T taking objects from world to camera
o Up vector maps to Y axis back pc = T p w
o Back vector maps to Z axis up
right • Trick: find T-1 taking objects in camera to world
z
View p w = T −1 p c
plane
Camera  x'   a b c d  x 
 y'  e f g h  y 
 z'  =  i
y
j k l  z 
 w' m n o p   w
x 

World ?

Finding the Viewing Transformation Viewing Transformations


• Trick: map from camera coordinates to world p(x,y,z)
3D Object Coordinates
o Origin maps to eye position

}
Modeling
Modeling
o Z axis maps to Back vector Transformation
Transformation
o Y axis maps to Up vector 3D World Coordinates
o X axis maps to Right vector Viewing
Viewing
Transformation
Transformation

 x '   Rx U x Bx Ex  x  3D Camera Coordinates Viewing Transformations


 y'   R U By E y  y  Projection
Projection
 = y y   Transformation
Transformation
 z '   Rz U z Bz Ez   z  2D Screen Coordinates
    
 w'  Rw U w Bw E w   w Window-to-Viewport
Window-to-Viewport
Transformation
Transformation

2D Image Coordinates
• This matrix is T-1 so we invert it to get T … easy! p’(x’,y’)

Projection Taxonomy of Projections


• General definition:
o Transform points in n-space to m-space (m<n)

• In computer graphics:
o Map 3D camera coordinates to 2D screen coordinates

FVFHP Figure 6.10

4
Taxonomy of Projections Parallel Projection
• Center of projection is at infinity
o Direction of projection (DOP) same for all points

DOP

View
FVFHP Figure 6.10 Plane Angel Figure 5.4

Orthographic Projections Oblique Projections


• DOP perpendicular to view plane • DOP not perpendicular to view plane

φ = 45 φ = 45
Front
Cavalier Cabinet
o
(DOP α = 45 ) o
(DOP α = 63.4 )

Top Side Angel Figure 5.5 H&B Figure 12.24

Parallel Projection View Volume Parallel Projection Matrix


• General parallel projection transformation:

 x s  1 0 L1 cos φ 0  x c 
 y  0 1 L1 sin φ 0  y c 
 s =   
 z s  0 0 0 0  z c 
    
H&B Figure 12.30  ws  0 0 0 1  1 

5
Taxonomy of Projections Perspective Projection
• Map points onto “view plane” along “projectors”
emanating from “center of projection” (COP)

sr
c to
je
o
Pr
Center of
Projection
View
Plane

FVFHP Figure 6.10 Angel Figure 5.9

Perspective Projection Perspective Projection View Volume


• How many vanishing points?

View
Plane

3-Point 2-Point 1-Point


Perspective Perspective Perspective

Angel Figure 5.10 H&B Figure 12.30

Perspective Projection Perspective Projection


• Compute 2D coordinates from 3D coordinates • Compute 2D coordinates from 3D coordinates
with similar triangles with similar triangles
y y
(x,y,z) -z (x,y,z) -z
D D
-z (0,0,0) z -z (0,0,0) z

View (xD/z, yD/z) View


What are the coordinates
Plane Plane
of the point resulting from
projection of (x,y,z) onto -y -y
the view plane?

6
Perspective Projection Matrix Perspective Projection Matrix
• 4x4 matrix representation? • 4x4 matrix representation?
xs = xc D / zc xs = xc D / zc x' = xc
y s = yc D / z c y s = yc D / z c y ' = yc
zs = D zs = D z ' = zc
ws = 1 ws = 1 w' = zc / D

 xs  ? ? ? ?  xc   xs  ? ? ? ?  xc 
 ys  ? ? ? ?  y c   ys  ? ? ? ?  y c 
 z  = ? ? ? ?  z c   z  = ? ? ? ?  z c 
 s  ? ? ? ?  1   s  ? ? ? ?  1 
 ws      ws    

Perspective Projection Matrix Taxonomy of Projections


• 4x4 matrix representation?
xs = xc D / zc x' = xc
y s = yc D / z c y ' = yc
zs = D z ' = zc
ws = 1 w' = zc / D

 x s  1 0 0 0  xc 
 y s  0 1 0 0   yc 
 z  = 0 0 1 0  z c 
 s  0 0 1/ D 0  1 
 ws    
FVFHP Figure 6.10

Perspective vs. Parallel Classical Projections


• Perspective projection
+ Size varies inversely with distance - looks realistic
– Distance and angles are not (in general) preserved
– Parallel lines do not (in general) remain parallel

• Parallel projection
+ Good for exact measurements
+ Parallel lines remain parallel
– Angles are not (in general) preserved
– Less realistic looking

Angel Figure 5.3

7
Summary What’s next?
3D Geometric Primitives
• Camera transformation
o Map 3D world coordinates to 3D camera coordinates Modeling
Modeling Transform into 3D world coordinate system
Transformation
Transformation
o Matrix has camera vectors as rows
Lighting
Lighting Illuminate according to lighting and reflectance

• Projection transformation Viewing


Viewing
Transformation
Transformation
Transform into 3D camera coordinate system
o Map 3D camera coordinates to 2D screen coordinates
o Two types of projections: Projection
Projection Transform into 2D camera coordinate system
Transformation
Transformation
» Parallel
» Perspective Clipping
Clipping Clip primitives outside camera’s view

Scan
Scan
Conversion
Conversion Draw pixels (includes texturing, hidden surface, etc.)

Image

You might also like