CS559: Computer Graphics Lecture 9: Rasterization Li Zhang Spring 2008.
-
Upload
rosaline-bailey -
Category
Documents
-
view
213 -
download
1
Transcript of CS559: Computer Graphics Lecture 9: Rasterization Li Zhang Spring 2008.
CS559: Computer Graphics
Lecture 9: RasterizationLi Zhang
Spring 2008
Today• Finish Projection• Rasterization• Antialising• Hidden Surface Removal
• Reading: – Shirley ch 7,4,8
3D Geometry Pipeline
Model Space(Object Space) World Space Eye Space
(View Space)Rotation
TranslationResizing
Rotation Translation
Projective,Scale
Translation
1
)/(
)/(
10/100
0100
0010
0001
d
yzd
xzd
z
y
x
d
Clipping and the viewing frustumThe center of projection and the portion of the projection plane that map to the final image form an infinite pyramid. The sides of the pyramid are clipping planes.Frequently, additional clipping planes are inserted to restrict the range of depths. These clipping planes are called the near and far or the hither and yon clipping planes.
All of the clipping planes bound the viewing frustum.
1
)/(
)/(
10/100
0100
0010
0001
d
yzd
xzd
z
y
x
d
View Volume Transformation• We want a matrix that will take points in our
perspective view volume and transform them into the orthographic view volume– This matrix will go in our pipeline before an
orthographic projection matrix
(l,b,n)(r,t,n) (l,b,n)
(r,t,n) (r,t,f)(r,t,f)
Mapping Lines
• We want to map all the lines through the center of projection to parallel lines– This converts the perspective case to
the orthographic case, we can use all our existing methods
• The relative intersection points of lines with the near clip plane should not change
• The matrix that does this looks like the matrix for our simple perspective case
nf
-zy
How to get this mapping?
0/100
00
0010
0001
n
BAM
1
)(
1
BAn
y
x
n
y
x
M
1
))(/(
)/(
)/(
1
BAffn
yfn
xfn
f
y
x
Mn ffBn
fA
1
1
)/(
)/(
10/100
0100
0010
0001
n
yzn
xzn
z
y
x
n
nf
-zy
Properties of this mapping
0/100
/)(00
0010
0001
n
fnfnM
111
'
'
'
z
fnnf
z
nyz
nx
z
y
x
Mz
y
x
If z = n, M(x,y,z,1) = [x,y,z,1] near plane is unchanged
If x/z = c1, y/z = c2, then x’=n*c1, y’=n*c2 bending converging rays to parallel rays
If z1 < z2, z1’ < z2’ z ordering is preserved
nf
-zy
1
)/(
)/(
10/100
0100
0010
0001
n
yzn
xzn
z
y
x
n
In pyramid In cube
General Perspective
0100
00
000
000
0100
00
0010
0001
nffn
n
n
n
fnfnOrthoViewViewM
To Canonical view volume
• Perspective projection transforms a pyramid volume to an orthographic view volume
(l,b,n)(r,t,n) (l,b,n)
(r,t,n) (r,t,f)(r,t,f)
(1,-1,1)
(-1,1,-1)
Canonical view volume [-1,1]^3
Scale, translateOrthoViewViewM
1000
2100
2010
2001
fn
bt
lr
1000
0200
0020
0002
fn
bt
lr
Orthographic View to Canonical Matrix
11000
2100
2010
2001
1000
0200
0020
0002
1orthoView
orthoView
orthoView
canonical
canonical
canonical
z
y
x
fn
bt
lr
fn
bt
lr
z
y
x
11000
200
020
002
orthoView
orthoView
orthoView
z
y
x
fnfnfn
btbtbt
lrlrlr
orthoViewcanonicalorthoViewcanonical xMx
Complete Perspective Projection • After applying the perspective matrix, we map
the orthographic view volume to the canonical view volume:
0100
00
000
000
1000
200
02
0
002
nffn
n
n
fn
fn
fn
bt
bt
bt
lr
lr
lr
orthoViewviewCanonicalorthoViewcanonicalview MMM
3D Geometry Pipeline
Model Space(Object Space)
World Space Eye Space(View Space)
Rotation Translation
Resizing
: Projective, Scale, Translation
Canonical View Space Screen Space (2D)
RotationTranslation
Image Space (pixels)Raster Space
canonicalview M
viewworld M
3D Geometry Pipeline
Model Space(Object Space)
World Space Eye Space(View Space)
Rotation Translation
Resizing
Canonical View Space Screen Space (2D)
RotationTranslation
Image Space (pixels)Raster Space
canonicalviewviewworld MM
viewworld M
3D Geometry Pipeline
Model Space(Object Space)
World Space Eye Space(View Space)
Rotation Translation
Resizing
Canonical View Space Screen Space (2D)
RotationTranslation
Image Space (pixels)Raster Space
viewworldcanonicalview MM
viewworld M
Order matters!!!
Canonical Window Transform
(-1,-1)
(1,1)
ny-1
(xmin,ymin)=(-0.5,-0.5)nx-1
(xmax, ymax)=(nx-0.5,ny-0.5)
11000
0100
2020
2002
1
minmaxminmax
minmaxminmax
canonical
canonical
canonical
pixel
pixel
pixel
z
y
x
yyyy
xxxx
z
y
x
pixelcanonical M
3D Geometry Pipeline
Model Space(Object Space)
World Space Eye Space(View Space)
Rotation Translation
Resizing
Canonical View Space Screen Space (2D)
RotationTranslation
Image Space (pixels)Raster Space
viewworld M
pixelcanonical M
canonicalview M
Polygons are basic shape primitives
• Any 3D shape can be approximated by a polygon using a locally linear (planar) approximation. To improve the quality of fit, we need only increase the number of edges
Line Drawing
(x1, y1)
(x0, y0)
0101
00
,
)(
yyyxxx
yxxx
yy
Line Drawing
(x1, y1)
(x0, y0)
for x = x0 to x1 do y=y0+(∆y/∆x)(x-x0) draw(x,round(y))
for x = x0 to x1 do y=y0+(∆y/∆x)(x-x0) draw(x,round(y))
0101
00
,
)(
yyyxxx
yxxx
yy
Line Drawing
(x1, y1)
(x0, y0)
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1
0101
00
,
)(
yyyxxx
yxxx
yy
Implicit Line Drawing
(x1, y1)
(x0, y0)
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1
line theabove0),( yxfline thebelow0),( yxf
f(x+1,y+0.5)<0f(x+1,y+0.5)<0
0101
00
,
)(
yyyxxx
yxxx
yy
)()(),( 00 xxyyyxyxf line on the0),( yxf
Implicit Line Drawing
(x1, y1)
(x0, y0)
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1
0101
00
,
)(
yyyxxx
yxxx
yy
)()(),( 00 xxyyyxyxf
yyxfyxf ),(),1(
xyyxfyxf ),()1,1(
f(x+1,y+0.5)<0f(x+1,y+0.5)<0
Incremental Evaluation
Implicit Line Drawing
(x1, y1)
(x0, y0)
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else
0101
00
,
)(
yyyxxx
yxxx
yy
)()(),( 00 xxyyyxyxf
yyxfyxf ),(),1(
xyyxfyxf ),()1,1(
d<0d<0
d=f(x+1,y+0.5)d=f(x+1,y+0.5)
D=d-∆y+∆xD=d-∆y+∆x
D=d-∆yD=d-∆y
Incremental Evaluation
Implicit Line Drawing
(x1, y1)
(x0, y0)
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else
0101
00
,
)(
yyyxxx
yxxx
yy
)()(),( 00 xxyyyxyxf
yyxfyxf ),(),1(
xyyxfyxf ),()1,1(
d<0d<0
d=2f(x+1,y+0.5)d=2f(x+1,y+0.5)
D=d-2∆y+2∆xD=d-2∆y+2∆x
D=d-2∆yD=d-2∆y
Incremental Evaluation
Integer operation
Implicit Line Drawing
(x1, y1)
(x0, y0)
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else
0101
00
,
)(
yyyxxx
yxxx
yy
)()(),( 00 xxyyyxyxf
yyxfyxf ),(),1(
xyyxfyxf ),()1,1(
d<0d<0
d=2f(x+1,y+0.5)d=2f(x+1,y+0.5)
D=d-2∆y+2∆xD=d-2∆y+2∆x
D=d-2∆yD=d-2∆y
Implicit Line Drawing
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else
0101
00
,
)(
yyyxxx
yxxx
yy
)()(),( 00 xxyyyxyxf
yyxfyxf ),(),1(
xyyxfyxf ),()1,1(
d<0d<0
d=2f(x+1,y+0.5)d=2f(x+1,y+0.5)
D=d-2∆y+2∆xD=d-2∆y+2∆x
D=d-2∆yD=d-2∆y
Implicit Line Drawing
(x1, y1)
(x0, y0)
0101
00
,
)(
yyyxxx
yxxx
yy
)()(),( 00 xxyyyxyxf
yyxfyxf ),(),1(
xyyxfyxf ),()1,1(
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1
Implicit Line Drawing
0101
00
,
)(
yyyxxx
yxxx
yy
)()(),( 00 xxyyyxyxf
yyxfyxf ),(),1(
xyyxfyxf ),()1,1(
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1
Implicit Line Drawing
(x1, y1)
(x0, y0)
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else
y = y0for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else
0101
00
,
)(
yyyxxx
yxxx
yy
)()(),( 00 xxyyyxyxf
yyxfyxf ),(),1(
xyyxfyxf ),()1,1(
d<0d<0
d=2f(x+1,y+0.5)d=2f(x+1,y+0.5)
D=d-2∆y+2∆xD=d-2∆y+2∆x
D=d-2∆yD=d-2∆y
If ∆y>∆x, switch x and y
Drawing Triangle
Drawing Triangle
for all y do for all x do if (in triangle) then draw(x,y) with color c
for all y do for all x do if (in triangle) then draw(x,y) with color c
3333
2222
1111
),,(:
),,(:
),,(:
cyxA
cyxA
cyxA
1321
3
33
2
22
1
11
ttt
y
xt
y
xt
y
xt
y
x
P
P
3232 2
1)( PAPAAPAarea
)(
)(
321
213 AAAarea
APAareat
)(
)(
321
132 AAAarea
APAareat
A3
A1
A2
P
)(
)(
321
321 AAAarea
APAareat )sin(
2
1)( 323232 PAAPAPAAPAarea
Drawing Triangle
for all y do for all x do compute t1,t2,t3
if t1,t2,t3 in [0,1] then draw(x,y) with color t1c1+t2c2+t3c3
for all y do for all x do compute t1,t2,t3
if t1,t2,t3 in [0,1] then draw(x,y) with color t1c1+t2c2+t3c3
3333
2222
1111
),,(:
),,(:
),,(:
cyxA
cyxA
cyxA
1321
3
33
2
22
1
11
ttt
y
xt
y
xt
y
xt
y
x
P
P
3232 2
1)( PAPAAPAarea
)(
)(
321
213 AAAarea
APAareat
)(
)(
321
132 AAAarea
APAareat
A3
A1
A2
P
)(
)(
321
321 AAAarea
APAareat )sin(
2
1)( 323232 PAAPAPAAPAarea
Common Edge
for all y do for all x do compute t1,t2,t3
if t1,t2,t3 in [0,1] then draw(x,y) with color t1c1+t2c2+t3c3
for all y do for all x do compute t1,t2,t3
if t1,t2,t3 in [0,1] then draw(x,y) with color t1c1+t2c2+t3c3
3333
2222
1111
),,(:
),,(:
),,(:
cyxA
cyxA
cyxA
1321
3
33
2
22
1
11
ttt
y
xt
y
xt
y
xt
y
x
P
P
3232 2
1)( PAPAAPAarea
)(
)(
321
213 AAAarea
APAareat
)(
)(
321
132 AAAarea
APAareat
)(
)(
321
321 AAAarea
APAareat )sin(
2
1)( 323232 PAAPAPAAPAarea