CS380: Introduction to Computer Graphics Linear Transformation...
Transcript of CS380: Introduction to Computer Graphics Linear Transformation...
![Page 1: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/1.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
CS380: Introduction to Computer GraphicsLinear Transformation
Chapter 2
Min H. KimKAIST School of Computing
![Page 2: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/2.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
GLSL PIPELINERECAP
2
![Page 3: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/3.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
GLSL Pipeline: Vertex Shader
• Vertices are stored in a vertex buffer.• When a draw call is issued, each of the vertices passes
through the vertex shader• On input to the vertex shader, each vertex (black) has
associated attributes.• On output, each vertex (cyan) has a value for gl_Position and
for its varying variables. 3
![Page 4: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/4.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
GLSL Pipeline: Rasterization
• The data in gl_Position is used to place the three vertices of the triangle on a virtual screen.
• The rasterizer figures out which pixels (orange) are inside the triangle and interpolates the varying variables from the vertices to each of these pixels.
4
![Page 5: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/5.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
GLSL Pipeline: Fragment Shader
• Each pixel (orange) is passed through the fragment shader, which computes the final color of the pixel (pink).
• The pixel is then placed in the frame buffer for display.
5
![Page 6: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/6.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
GLSL Pipeline: Fragment Shader
• By changing the fragment shader, we can simulate light reflecting of different kinds of materials.
6
![Page 7: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/7.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Texture Mapping
• A simple geometric object described by a small number of triangles.
• An auxiliary image called a texture.• Parts of the texture are glued onto each triangle
giving a more complicated appearance. 7
![Page 8: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/8.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
LINEAR TRANSFORMATIONChapter 2
8
![Page 9: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/9.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Point vs. Vector• Represent Points using coordinates• To perform geometric transformations to these
points• Vectors: 3D motion via linear transformations• Coordinate vector: the position of the point
9
xyz
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
![Page 10: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/10.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Points Vector Coordinatesystem
Coordinate vector
Point vs. Coordinate Vector
1. Point (geometric object): notated as (tilde above the letter), non-numerical object.
2. Vector (motion): notated as (arrow above the letter), non-numerical object.
3. Coordinate system: denoted as (bold: column vector, t makes it transpose), non-numerical object basis for vector; frame for point
4. Coordinate vector: noted as (bold letter), numericalobject
10
!p
!v
c
!f t
![Page 11: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/11.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Vector Space• A vector space is some set of elements • NB: Vector (motion) is NOT just a set of three
numbers!!!• If a set of vectors is not linearly dependent, we call
linearly independent.• If are linearly independent, all vectors
of can be expressed with coordinates of a basis of (a set of ).
• is the dimension of the basis/space11
V !v
!b1...!b2
V ciV
!v = ci!bi
i∑
n
!v
!bi
![Page 12: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/12.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Vector Space• Free motion in space, 3 dimensional vector• In vector algebra notation:
• a vector • row basis vectors• column coordinate vector
12
c
!v = ci!bi
i∑ =
!b1!b2!b3
⎡⎣⎢
⎤⎦⎥
c1c2c3
⎡
⎣
⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥
!v
!bt
!v =!btc
![Page 13: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/13.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Linear Transformation• Linear transformation follows these two
properties:
• Vector transformation (such that the basis is linearly independent):
13
L(!v+ !u)=L(!v)+L(!u)L(α !v)=αL(!v).
!v⇒ L(!v)=L ci
!bi
i∑⎛
⎝⎜
⎞
⎠⎟= ciL(
!bi )
i∑
![Page 14: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/14.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
3-by-3 Transformation• Rewrite the linear transform
• is actually a linear combination of the original basis vectors.
14
!b1!b2!b3
⎡⎣⎢
⎤⎦⎥
c1c2c3
⎡
⎣
⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥
⇒ L(!b1) L(
!b2) L(
!b3)
⎡⎣⎢
⎤⎦⎥
c1c2c3
⎡
⎣
⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥
L(b1)
L(b1!"!)= b1
!"!b2!"!
b3!"!⎡
⎣⎢⎤⎦⎥
M1,1
M2,1
M3,1
⎡
⎣
⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥
![Page 15: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/15.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
3-by-3 Transformation• 3-by-3 matrix:
• Putting all together:
• A matrix to transform one vector to another:
15
L(b1!"!) L(b2
!"!) L(b3
!"!)⎡
⎣⎢⎤⎦⎥= b1!"!
b2!"!
b3!"!⎡
⎣⎢⎤⎦⎥
M1,1 M1,2 M1,3
M2,1 M2,2 M2,3
M3,1 M3,2 M3,3
⎡
⎣
⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥
.
b1
b2
b3⎡
⎣⎤⎦
c1c2c3
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥⇒ b1
b2
b3⎡
⎣⎤⎦
M1,1 M1,2 M1,3
M 2,1 M 2,2 M 2,3
M 3,1 M 3,2 M 3,3
⎡
⎣
⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥
c1c2c3
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥.
v= b tc⇒ b tMc
![Page 16: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/16.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Linear transform of a vector• A vector undergoes a linear transformation
• The matrix M depends on the chosen linear transformation.
16
v= b tc⇒ b tMc
v!⇒ L(v
!)
![Page 17: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/17.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Inverse transform• Identity matrix
• In 3D graphics, while moving objects around in space, it will seldom make sense to use an non-invertible transform.
17
I =1 0 00 1 00 0 1
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥.
MM −1 = M −1M = I .
![Page 18: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/18.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Linear transform of a basis• A basis undergoes a linear transformation
• Valid to multiply a matrix times a coordinate vector
• change a basis of a vector to
18
b t
⇒ b tM
v= b tc = a tM −1c . a
t= b tM ,
b t
a t
![Page 19: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/19.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Dot product• Input: two vectors• Output: a real number• dot product = the squared length
• The angle between the two vectors:
19
v⋅w
v 2:= v⋅v
cosθ = v
⋅w
vw .
θ ∈[0...π ]
![Page 20: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/20.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
3D orthogonal basis• Orthogonal vectors:• A right-handed orthogonal coordinate system.
The z axis comes out of the screen (OpenGL). • A left-handed orthogonal coordinate system.
The z axis goes into the screen (DirectX).
20
v⋅w= 0
right-handed
left-handed
![Page 21: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/21.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Cross product• Input: two vectors• Output: a vector
• where is a unit vector that is orthogonal to the plane spanned by and
• forms a right-handed basis
21
[v,w,n]
n
v
w
v×w:= vwsinθn,
![Page 22: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/22.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Cross product• In a right-handed orthogonal basis
• We can compute a cross-product as
22
(b tc)× (b
td) =
c2d3 − c3d2c3d1 − c1d3c1d2 − c2d1
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
b t
![Page 23: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/23.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
2D Rotation• Let be a 2D right-handed orthonormal
(orthogonal and unit vectors) basis
• Rotated vector
23
v= b1
b2⎡
⎣⎤⎦
xy
⎡
⎣⎢⎢
⎤
⎦⎥⎥.
b t
x ' = xcosθ − ysinθy ' = xsinθ + ycosθ .
x 'y '
⎡
⎣⎢⎢
⎤
⎦⎥⎥= cosθ −sinθ
sinθ cosθ⎡
⎣⎢
⎤
⎦⎥
xy
⎡
⎣⎢⎢
⎤
⎦⎥⎥.
![Page 24: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/24.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
3D Rotation • Every rotation fixes an axis of rotation and
rotates by some angle about that axis.• Rotation around the z axis:
24
b1
b2
b3⎡
⎣⎤⎦
xyz
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
⇒ b1
b2
b3⎡
⎣⎤⎦
cosθ −sinθ 0sinθ cosθ 00 0 1
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
xyz
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
![Page 25: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/25.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
3D Rotation• Rotation around the x axis
• Rotation around the y axis
25
1 0 00 cosθ −sinθ0 sinθ cosθ
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
cosθ 0 sinθ0 1 0
−sinθ 0 cosθ
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
![Page 26: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/26.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
xyz-Euler angle rotation• Axis of rotation
• xyz-Euler angle rotation matrix
where26
kx2v + c kxkyv − kzs kxkzv + kys
kykxv + kzs ky2v + c kykzv − kxs
kzkxv − kys kzkyv + kxs kz2v + c
⎡
⎣
⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥
k= kx ,ky ,kz⎡⎣ ⎤⎦
t
c := cosθ , s := sinθ , v := 1− c.
![Page 27: CS380: Introduction to Computer Graphics Linear Transformation …vclab.kaist.ac.kr/cs380/slide03-Linear.pdf · 2021. 3. 10. · LINEAR TRANSFORMATION Chapter 2 8. Min H. Kim (KAIST)](https://reader036.fdocuments.net/reader036/viewer/2022071419/6117e9b3a3043845984950de/html5/thumbnails/27.jpg)
Min H. Kim (KAIST) Foundations of 3D Computer Graphics, S. Gortler, MIT Press, 2012
Scales• Scaling operations
27
b1
b2
b3⎡
⎣⎤⎦
xyz
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
⇒ b1
b2
b3⎡
⎣⎤⎦
α 0 00 β 00 0 γ
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
xyz
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥