Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
Introduction to Computer GraphicsSoftware Rasterization Review
Colors
Red Channel
Green Channel
Blue Channel
Alpha Channel
1.00f 0.24f 0.29f 0.30f
Add and scale are applied to channels
,, ,
Rasters
0
50
50
0xFF3D4A4C
R:24%A:100%
G:29%B:30%
Linear Combination or Blend
A
.75A+.25B.75A
.25B
.75 + .25 = 1
B
Barycentric Coordinates
A
B C .8 .1 .1+ + = 1
λ1 λ2 λ3+ + = 1and
0 ≤ λx ≤ 1.8A
.1B
.1C
Barycentric Coordinates
x = λ1x1 + λ2x2 + λ3x3y = λ1y1 + λ2y2 + λ3y3
λ1 + λ2 + λ3 = 1
Barycentric Coordinates
λ1 = (y2 - y3)(x - x3) + (x3 - x2)(y - y3)(y2 - y3)(x1 - x3) + (x3 - x2)(y1 - y3)
λ2 = (y3 - y1)(x - x3) + (x1 - x3)(y - y3)(y2 - y3)(x1 - x3) + (x3 - x2)(y1 - y3)
λ3 = 1 - λ1- λ2
A
B C
Interpolationλ1 λ2 λ3+ + = 1
and0 ≤ λx ≤ 1
• λ1 + • λ2 + • λ3 + =
2D Transformations
X
Y
X
Y
XY
yx0
1 tytx1
00 0 1 1
yx0
sy 00sx
00 0 1 1
yx
00
0 0 1 1
cosθ -sinθsinθ cosθ
3D Transformations All Points
X
Y
Z
X
Y
Z
X
Y
Z
xf = xo + txyf = yo + tyzf = zo + tz
xf = xo • sxyf = yo • syzf = zo • sz
More Complex
3D Transformations
X
Y
XY
All Points
X
Y
Z
Z
Z
01 0
0100 0 1
tytx
tz0 0 0 1
yx
z1 0
sy 00sx
00 0 sz
00
00 0 0 1
yx
z1
mm m
mmmm m m
00
00 0 0 1
yx
z1
M = vector rotate matrix
X
Y
Z
00
0 0 1
cosθ -sinθsinθ cosθ
0001000
Rotation About Z-Axis
X
Y
Z
X
Y
Z
Rotation About X-Axis
Rotation About Y-Axis
-sinθ0
0 sinθ cosθ
1 00 cosθ
0001000
0sinθ
-sinθ 0 cosθ
cosθ 00 1
0001000
3D Transformations
3D Transformations
Measure α thenRotate by α thenMeasure β thenRotate by β thenRotate by θ thenRotate by -β thenRotate by -α
X
β
αY
Z
θ
X
Z
Y
a
θ
00
0 0 1
cos-α-sin-αsin-αcos-α
0001000
-sin-β0
0 sin-βcos-β
1 00 cos-β
0001000
M =
00
0 0 1
cosθ -sinθsinθ cosθ
0001000
-sinβ0
0 sinβ cosβ
1 00 cosβ
0001000
00
0 0 1
cosα -sinαsinα cosα
0001000
3D Transformations
T RSV = TRSV
R =
V = SVS
SV RSV
TRS V = TRSV
ST R TRS=10,000 Times
Notice the ordering!
10,000 Times
Either This
And This
3D TransformationsOr This1 Time
Projection - Perspectivey’ = y
z
z
?? ?
???0 0 1
??
00 0 0 1
yx
z1
x’ = xz
y/zx/z
z1
=
No possible matrix, because we don’t have z!
yx
zw
v = y/wx/w
z/ww/w
v’ =
zProjection - Perspective
Projection - Perspectivey’ = y
z
z
x’ = xz
01 0
0100 0 1
00
00 0 1 0
yx
z1
yx
zz
=
With homogeneous divide, just copy z to w
y/zx/z
z/zz/z
v’ = yx
zz
v =
Projection - Perspective
frustum(l,r,b,t,n,f)
void perspective(float fovy, float aspect, float zNear, float zFar){ float xmin, xmax, ymin, ymax;
ymax = zNear * tanf(fovy * M_PI / 360.0f); ymin = -ymax; xmin = ymin * aspect; xmax = ymax * aspect;
frustum(xmin, xmax, ymin, ymax, zNear, zFar);}
Z-Copy and Right Hand Rule
Other adjustments due to definition of frustum
Projection - Perspective
frustum(l,r,b,t,n,f)
01/tan(v/2) 0
000 0 -(f+n)/(f-n)
00
-2nf/(f-n)0 0 -1 0
scales near plane to -1 → 1 in x,y
v = fovYa = aspectn = nearf = farcopy Z
scales and biases z to -1 → 1
1/(tan(v/2)a)
Depth Buffer
for pixels in triangle calculate λ1,λ2,λ3 if λ1>0 & λ2>0 & λ3>0 interpolate z-value if z-value < z-buffer update z-buffer interpolate color store color in raster
User positioned at (eyeX,eyeY,eyeZ)
User looks at (spotX, spotY, spotZ)
Any direction can be “up”
User looks down look vector
There exists a vector describing the direction “right”
up
lookrighteye
look = spot - eyeright = look x upup = right x look
look, right, up are normalized
Camera Matrix
Camera Matrix
rightyupy upz
rightzrightxupx 0
0
00 0 0 1
Translate(-eyex, -eyey, -eyez)Translate Camera to Origin
M = BT
B =
T =
-lookx -looky -lookz
up-lookright eye
Change of Coordinate System Matrix
Back-Face Culling
Model View Matrix
Projection Matrix
Viewport Transform
Model Coordinates
EyeCoordinates
CanonicalCoordinates
RasterCoordinates
Homogeneous Divideif (n • tcenter > 0)
cull
Back-Face CullingObjects drawn with back-face culling need to be solid
Lighting
l
P
l = L P- n
vv = V P-
V
r
lr = 2(l•n)n - l
n
-l2(l•n)n
2(l•n) = 2|l||n|cosθ
r
Lighting
Ia = ambient intensity
Id = diffuse intensity
Is = specular intensity
nl •Id = ˆ ˆLdkdIa = Laka
v •Is ≃ ˆks r̂ )( αLs
ka= material ambient coefficient
ks = material specular coefficient
kd= material diffuse coefficient
= shininessα
La= light ambient intensity
Ls= light specular intensity
Ld= light diffuse intensity
Ldr Ldg Ldb, , )light diffuse color=
kdr kdg kdb, , )= material diffuse color
(
(
v
r
l
n
l = L P-v = V P-
r = 2(l•n)n - l
LightingI = IsIa Id+ +∑ ( )
lights
Only sum diffuse color if l • n is positive
Only sum specular color if l • n and v • r are positive
Normals supplied per vertexNormals interpolated across faceColor & lighting calculated per pixel
Where to apply the lighting model?
Bui Tuong Phong
Lighting
AB
C
Texture Coordinatesλ1 λ2 λ3+ + = 1
and0 ≤ λx ≤ 1
• λ1 + • λ2 + • λ3 + =
(0.6,0.2)
(0.6,0.9)
(0.15,0.1)(0.15,0.1)
(0.6,0.2)
(0.6,0.9)
(0.5,0.6)
Bump Mapping
Normals supplied per pixelNormals obtained from bump mapColor & lighting calculated per pixel
Where to apply the lighting model?