the 3d rasterization pipeline€¦ · viewport transformation scan conversion viewing...
TRANSCRIPT
![Page 1: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/1.jpg)
The 3D Rasterization Pipeline
COS 426, Spring 2020
Felix Heide
Princeton University
![Page 2: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/2.jpg)
3D Rendering Scenarios
• Offline One image generated with as much quality as possible
for a particular set of rendering parameters
▪ Take as much time as is needed (minutes)
▪ Targets photorealistism, movies, etc.
➢ Interactive Images generated dynamically, in fraction of a second
(e.g., 1/30) as user controls rendering parameters (e.g.,
camera)
▪ Achieve highest quality possible in given time
▪ Visualization, games, etc.
![Page 3: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/3.jpg)
3D Polygon Rendering
• Many applications use rendering of 3D polygons
with direct illumination Valve
![Page 4: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/4.jpg)
3D Polygon Rendering
• Many applications use rendering of 3D polygons
with direct illuminationAssignment 2
![Page 5: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/5.jpg)
Ray Casting Revisited
• For each sample … Construct ray from eye position through view plane
Find first surface intersected by ray through pixel
Compute color of sample based on illumination
![Page 6: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/6.jpg)
3D Polygon Rasterization
• We can render polygons faster if we take
advantage of spatial coherence
![Page 7: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/7.jpg)
3D Polygon Rasterization
• How?
![Page 8: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/8.jpg)
3D Polygon Rasterization
• How?
![Page 9: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/9.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
This is a pipelined
sequence of operations
to draw 3D primitives
into a 2D image
![Page 10: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/10.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
OpenGL executes steps
of 3D rendering pipeline
for each polygon
glBegin(GL_POLYGON);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glEnd();
![Page 11: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/11.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
Transform into 3D world coordinate system
![Page 12: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/12.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
Transform into 3D world coordinate system
Illuminate according to lighting and reflectance
![Page 13: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/13.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
Transform into 3D world coordinate system
Transform into 3D camera coordinate system
Illuminate according to lighting and reflectance
![Page 14: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/14.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
Transform into 3D world coordinate system
Transform into 3D camera coordinate system
Transform into 2D camera coordinate system
Illuminate according to lighting and reflectance
![Page 15: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/15.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
Transform into 3D world coordinate system
Transform into 3D camera coordinate system
Clip primitives outside camera’s view
Transform into 2D camera coordinate system
Illuminate according to lighting and reflectance
![Page 16: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/16.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
Transform into 3D world coordinate system
Transform into 3D camera coordinate system
Clip primitives outside camera’s view … in clip space
Transform into 2D camera coordinate system
Illuminate according to lighting and reflectance
![Page 17: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/17.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
Transform into 3D world coordinate system
Transform into 3D camera coordinate system
Clip primitives outside camera’s view
Transform into 2D camera coordinate system
Illuminate according to lighting and reflectance
Transform into image coordinate system
![Page 18: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/18.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
Transform into 3D world coordinate system
Transform into 3D camera coordinate system
Draw pixels (includes texturing, hidden surface, ...)
Clip primitives outside camera’s view
Transform into 2D camera coordinate system
Illuminate according to lighting and reflectance
Transform into image coordinate system
![Page 19: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/19.jpg)
Rasterization Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
ViewingTransformation
Transform into 3D world coordinate system
Transform into 3D camera coordinate system
Draw pixels (includes texturing, hidden surface, ...)
Clip primitives outside camera’s view
Transform into 2D camera coordinate system
Illuminate according to lighting and reflectance
Transform into image coordinate system
![Page 20: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/20.jpg)
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
Transformations map points from
one coordinate system to another
p(x,y,z)
p’(x’,y’)
3D World
Coordinates
3D Camera
Coordinates
3D Object
Coordinatesx
z
y
![Page 21: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/21.jpg)
Viewing Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
p(x,y,z)
p’(x’,y’)
Viewing Transformations
![Page 22: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/22.jpg)
Review: Viewing Transformation
• Mapping from world to camera coordinates Eye position maps to origin
Right vector maps to X axis
Up vector maps to Y axis
Back vector maps to Z axis
x
y
z
World
rightup
back
Camera
View plane
![Page 23: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/23.jpg)
Review: Camera Coordinates
Camera right vector
maps to X axis
Camera up vector
maps to Y axis
Camera back vector
maps to Z axis
(pointing out of page)
• Canonical coordinate system Convention is right-handed (looking down -z axis)
Convenient for projection, clipping, etc.
x
y
z
![Page 24: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/24.jpg)
Finding the Viewing Transformation
• Trick: map from camera coordinates to world Origin maps to eye position
Z axis maps to Back vector
Y axis maps to Up vector
X axis maps to Right vector
• This matrix is T-1 so we invert it to get T … easy!
=
w
z
y
x
EBUR
EBUR
EBUR
EBUR
w
z
y
x
wwww
zzzz
yyyy
xxxx
'
'
'
'
![Page 25: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/25.jpg)
Finding the viewing transformation
• We have the camera (in world coordinates)
• We want T taking objects from world to camera
• Trick: find T-1 taking objects in camera to world
wpTcp =
cpTwp 1−=
![Page 26: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/26.jpg)
Viewing Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
p(x,y,z)
p’(x’,y’)
Viewing Transformations
![Page 27: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/27.jpg)
Projection
• General definition: Transform points in n-space to m-space (m<n)
• In computer graphics: Map 3D camera coordinates to 2D screen coordinates
![Page 28: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/28.jpg)
Taxonomy of Projections
FVFHP Figure 6.10
![Page 29: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/29.jpg)
Taxonomy of Projections
FVFHP Figure 6.10
![Page 30: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/30.jpg)
Parallel Projection
Angel Figure 5.4
• Center of projection is at infinity Direction of projection (DOP) same for all points
DOP
View
Plane
![Page 31: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/31.jpg)
Orthographic Projections
Angel Figure 5.5Top Side
Front
• DOP perpendicular to view plane
![Page 32: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/32.jpg)
Parallel Projection Matrix
![Page 33: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/33.jpg)
Parallel Projection Matrix
• General parallel projection transformation:
=
11000
0000
0sin10
0cos01
c
c
c
s
s
s
s
z
y
x
L
L
w
z
y
x
![Page 34: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/34.jpg)
Parallel Projection View Volume
H&B Figure 12.30
![Page 35: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/35.jpg)
Taxonomy of Projections
FVFHP Figure 6.10
![Page 36: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/36.jpg)
Return to Perspective Projection
Angel Figure 5.9
• Map points onto “view plane” along “projectors”
emanating from “center of projection” (COP)
Center of
ProjectionView
Plane
![Page 37: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/37.jpg)
Perspective Projection
• Compute 2D coordinates from 3D coordinates
with similar triangles
(0,0,0) z
-y
-z
y
D
(x,y,z)
View
Plane
-z
What are the coordinates
of the point resulting from
projection of (x,y,z) onto
the view plane?
![Page 38: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/38.jpg)
Perspective Projection
• Compute 2D coordinates from 3D coordinates
with similar triangles
(0,0,0) z
-y
-z
y
D
(x,y,z)
View
Plane
-z
(xD/z, yD/z)
![Page 39: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/39.jpg)
Perspective Projection Matrix
• 4x4 matrix representation?
=
1????????????????
c
c
c
s
s
s
s
z
y
x
w
z
y
x
1
//
====
s
s
ccs
ccs
wDz
zDyyzDxx
![Page 40: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/40.jpg)
Perspective Projection Matrix
• 4x4 matrix representation?
=
1????????????????
c
c
c
s
s
s
s
z
y
x
w
z
y
x
1
//
====
s
s
ccs
ccs
wDz
zDyyzDxx
Dzwzzyyxx
c
c
c
c
/''''
====
'/''/''/'
wzzwyywxx
s
s
s
===
![Page 41: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/41.jpg)
Perspective Projection Matrix
• 4x4 matrix representation?
1
//
====
s
s
ccs
ccs
wDz
zDyyzDxx
=
10/100010000100001
c
c
c
s
s
s
s
z
y
x
Dw
z
y
x
Dzwzzyyxx
c
c
c
c
/''''
====
'/''/''/'
wzzwyywxx
s
s
s
===
![Page 42: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/42.jpg)
• In practice, want to compute a value related to
depth to include in z-buffer
Perspective Projection Matrix
1///
=−=
==
s
cs
ccs
ccs
wzDzzDyyzDxx
−=
10/100
1000
0010
0001
c
c
c
s
s
s
s
z
y
x
Dw
z
y
x
Dzwz
yyxx
c
c
c
/'1'
''
=−=
==
'/''/''/'
wzzwyywxx
s
s
s
===
![Page 43: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/43.jpg)
Perspective Projection View Volume
H&B Figure 12.30
View
Plane
![Page 44: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/44.jpg)
Perspective vs. Parallel
• 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
![Page 45: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/45.jpg)
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
Transformations map points from
one coordinate system to another
p(x,y,z)
p’(x’,y’)
3D World
Coordinates
3D Camera
Coordinates
3D Object
Coordinatesx
z
y
![Page 46: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/46.jpg)
Viewport Transformation
• Transform 2D geometric primitives from
screen coordinate system (normalized device
coordinates) to image coordinate system (pixels)
ImageScreen
Viewport
Window
![Page 47: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/47.jpg)
Viewport Transformation
vx1 vx2vy1
vy2
wx1 wx2wy1
wy2Window Viewport
Screen Coordinates Image Coordinates
(wx,wy) (vx,vy)
vx = vx1 + (wx - wx1) * (vx2 - vx1) / (wx2 - wx1);
vy = vy1 + (wy - wy1) * (vy2 - vy1) / (wy2 - wy1);
• Window-to-viewport mapping
![Page 48: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/48.jpg)
Summary of Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
p(x,y,z)
p’(x’,y’)
Viewing transformations
Modeling transformation
Viewport transformation
![Page 49: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/49.jpg)
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
ViewingTransformation
3D World Coordinates
2D Image Coordinates
![Page 50: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/50.jpg)
Clipping
• Avoid drawing parts of primitives outside window Window defines part of scene being viewed
Must draw geometric primitives only inside window
Viewing
Window
![Page 51: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/51.jpg)
Polygon Clipping
• Find the part of a polygon inside the clip window?
Before Clipping
![Page 52: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/52.jpg)
Polygon Clipping
• Find the part of a polygon inside the clip window?
After Clipping
![Page 53: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/53.jpg)
Sutherland Hodgeman Clipping
• Clip to each window boundary one at a time
(for convex polygons)
![Page 54: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/54.jpg)
Sutherland Hodgeman Clipping
• Clip to each window boundary one at a time
![Page 55: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/55.jpg)
Sutherland Hodgeman Clipping
• Clip to each window boundary one at a time
![Page 56: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/56.jpg)
Sutherland Hodgeman Clipping
• Clip to each window boundary one at a time
![Page 57: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/57.jpg)
Sutherland Hodgeman Clipping
• Clip to each window boundary one at a time
![Page 58: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/58.jpg)
Clipping to a Boundary
• Do inside test for each point in sequence,
Insert new points when cross window boundary,
Remove points outside window boundary
Outside
Inside
Window
Boundary
P1
P2
P5
P4
P3
![Page 59: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/59.jpg)
Clipping to a Boundary
• Do inside test for each point in sequence,
Insert new points when cross window boundary,
Remove points outside window boundary
Outside
Inside
Window
Boundary
P1
P2
P5
P4
P3
![Page 60: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/60.jpg)
Clipping to a Boundary
• Do inside test for each point in sequence,
Insert new points when cross window boundary,
Remove points outside window boundary
Outside
Inside
Window
Boundary
P1
P2
P5
P4
P3
![Page 61: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/61.jpg)
Clipping to a Boundary
• Do inside test for each point in sequence,
Insert new points when cross window boundary,
Remove points outside window boundary
Outside
Inside
Window
Boundary
P1
P2
P5
P4
P3
![Page 62: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/62.jpg)
P’
Clipping to a Boundary
• Do inside test for each point in sequence,
Insert new points when cross window boundary,
Remove points outside window boundary
Outside
Inside
Window
Boundary
P1
P2
P5
P4
P3
![Page 63: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/63.jpg)
P’
Clipping to a Boundary
• Do inside test for each point in sequence,
Insert new points when cross window boundary,
Remove points outside window boundary
Outside
Inside
Window
Boundary
P1
P2
P5
P4
P3
![Page 64: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/64.jpg)
P’
Clipping to a Boundary
• Do inside test for each point in sequence,
Insert new points when cross window boundary,
Remove points outside window boundary
Outside
Inside
Window
Boundary
P1
P2
P5
P4
P3
![Page 65: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/65.jpg)
P’’P’
Clipping to a Boundary
• Do inside test for each point in sequence,
Insert new points when cross window boundary,
Remove points outside window boundary
Outside
Inside
Window
Boundary
P1
P2
P5
P4
P3
![Page 66: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/66.jpg)
P’’P’
Clipping to a Boundary
• Do inside test for each point in sequence,
Insert new points when cross window boundary,
Remove points outside window boundary
Outside
Inside
Window
Boundary
P1
P2
![Page 67: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/67.jpg)
Sutherland Hodgeman Failure
• Concave Polygons
![Page 68: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/68.jpg)
3D Rendering Pipeline (for direct illumination)
Viewing
Window
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
ViewingTransformation
3D World Coordinates
2D Image Coordinates
![Page 69: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/69.jpg)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
ViewingTransformation
3D World Coordinates
2D Image Coordinates
Standard (aliased)
Scan Conversion
P1
P2
P3
3D Rendering Pipeline (for direct illumination)
![Page 70: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/70.jpg)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
ViewingTransformation
3D World Coordinates
2D Image Coordinates
Antialiased
Scan Conversion
P1
P2
P3
3D Rendering Pipeline (for direct illumination)
![Page 71: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/71.jpg)
Scan Conversion
• Render an image of a geometric primitive
by setting pixel colors
• Example: Filling the inside of a triangle
P1
P2
P3
void SetPixel(int x, int y, Color rgba)
![Page 72: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/72.jpg)
Triangle Scan Conversion
• Properties of a good algorithm Symmetric
Straight edges
No cracks between adjacent primitives
(Antialiased edges)
FAST!
P1
P2
P3
P4
![Page 73: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/73.jpg)
• Color all pixels inside triangle
Simple Algorithm
P1
P2
P3
void ScanTriangle(Triangle T, Color rgba){for each pixel P in bbox(T){
if (Inside(T, P)) SetPixel(P.x, P.y, rgba);
}}
![Page 74: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/74.jpg)
Triangle Sweep-Line Algorithm
• Take advantage of spatial coherence Compute which pixels are inside using horizontal spans
Process horizontal spans in scan-line order
• Take advantage of edge linearity Use edge slopes to update coordinates incrementally
dxdy
![Page 75: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/75.jpg)
Triangle Sweep-Line Algorithm
void ScanTriangle(Triangle T, Color rgba){for each edge pair {
initialize xL, xR;compute dxL/dyL and dxR/dyR;for each scanline at y
for (int x = xL; x <= xR; x++) SetPixel(x, y, rgba);
xL += dxL/dyL;xR += dxR/dyR;
}}
xL xR
dxL
dyL
dxR
dyR
![Page 76: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/76.jpg)
Triangle Sweep-Line Algorithm
void ScanTriangle(Triangle T, Color rgba){for each edge pair {
initialize xL, xR;compute dxL/dyL and dxR/dyR;for each scanline at y
for (int x = xL; x <= xR; x++) SetPixel(x, y, rgba);
xL += dxL/dyL;xR += dxR/dyR;
}}
xL xR
dxL
dyL
dxR
dyRMinimize computation
in inner loops
![Page 77: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/77.jpg)
GPU Architecture
![Page 78: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/78.jpg)
GPU Architecture
![Page 79: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image](https://reader033.vdocument.in/reader033/viewer/2022060606/605c247757b71749f651cac9/html5/thumbnails/79.jpg)
GPU Architecture