Post on 14-Jun-2020
transcript
18/03/13
1
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
CS380:IntroductiontoComputerGraphicsLinearTransformation
Chapter2
MinH.KimKAISTSchoolofComputing
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
GLSLPIPELINE
RECAP
2
18/03/13
2
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
GLSLPipeline:VertexShader
• Verticesarestoredinavertexbuffer.• Whenadrawcallisissued,eachoftheverticespasses
throughthevertexshader• Oninputtothevertexshader,eachvertex(black)has
associatedattributes.• Onoutput,eachvertex(cyan)hasavalueforgl_Positionand
foritsvaryingvariables.3
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
GLSLPipeline:Rasterization
• Thedataingl_Positionisusedtoplacethethreeverticesofthetriangleonavirtualscreen.
• Therasterizerfiguresoutwhichpixels(orange)areinsidethetriangleandinterpolatesthevaryingvariablesfromtheverticestoeachofthesepixels.
4
18/03/13
3
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
GLSLPipeline:FragmentShader
• Eachpixel(orange)ispassedthroughthefragmentshader,whichcomputesthefinalcolorofthepixel(pink).
• Thepixelisthenplacedintheframebufferfordisplay.
5
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
GLSLPipeline:FragmentShader
• Bychangingthefragmentshader,wecansimulatelightreflectingofdifferentkindsofmaterials.
6
18/03/13
4
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
TextureMapping
• Asimplegeometricobjectdescribedbyasmallnumberoftriangles.
• Anauxiliaryimagecalledatexture.• Partsofthetexturearegluedontoeachtriangle
givingamorecomplicatedappearance.7
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
LINEARTRANSFORMATIONChapter2
8
18/03/13
5
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Pointvs.Vector• RepresentPointsusingcoordinates• Toperformgeometrictransformationstothese
points• Vectors:3Dmotionvialineartransformations• Coordinatevector:thepositionofthepoint
9
xyz
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Points Vector Coordinatesystem
Coordinatevector
Pointvs.CoordinateVector
1. Point(geometricobject):notatedas(tildeabovetheletter),non-numericalobject.
2. Vector(motion):notatedas(arrowabovetheletter),non-numericalobject.
3. Coordinatesystem:denotedas(bold:columnvector,tmakesittranspose),non-numericalobjectbasisforvector;frameforpoint
4. Coordinatevector:notedas(boldletter),numericalobject
10
p
v
c
f t
18/03/13
6
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
VectorSpace• Avectorspaceissomesetofelements• NB:Vector(motion)isNOTjustasetofthree
numbers!!!• Ifasetofvectorsisnotlinearlydependent,wecall
linearlyindependent.• Ifarelinearlyindependent,allvectors
ofcanbeexpressedwithcoordinatesofabasisof(asetof).
• isthedimensionofthebasis/space11
V v
b1...bn
V v
ciV bi
v= cibi
i∑ .
n
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
VectorSpace• Freemotioninspace,3dimensionalvector• Invectoralgebranotation:
• avector• rowbasisvectors• columncoordinatevector
12
c
v= cibi
i∑ = b1
b2
b3⎡
⎣⎤⎦
c1c2c3
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥.
v
b t
v= b tc.
18/03/13
7
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
LinearTransformation• Lineartransformationfollowsthesetwo
properties:
• Vectortransformation(suchthatthebasisislinearlyindependent):
13
L(v+ u) = L(v
)+ L(u
)
L(α v) =αL(v
) .
v!⇒ L(v
!) = L cib
!i
i∑⎛⎝⎜
⎞⎠⎟= ciL(b
!i )
i∑ .
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
3-by-3Transformation• Rewritethelineartransform
• isactuallyalinearcombinationoftheoriginalbasisvectors.
14
b1
b2
b3⎡
⎣⎤⎦
c1c2c3
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥⇒ L(b1
) L(b2
) L(b3
)⎡
⎣⎤⎦
c1c2c3
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥.
L(b1)
L(b1) = b1
b2
b3⎡
⎣⎤⎦
M1,1
M 2,1
M 3,1
⎡
⎣
⎢⎢⎢⎢
⎤
⎦
⎥⎥⎥⎥
18/03/13
8
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
3-by-3Transformation• 3-by-3matrix:
• Puttingalltogether:
• Amatrixtotransformonevectortoanother:
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
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Lineartransformofavector• Avectorundergoesalineartransformation
• ThematrixMdependsonthechosenlineartransformation.
16
v= b tc⇒ b tMc
v!⇒ L(v
!)
18/03/13
9
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Inversetransform• Identitymatrix
• In3Dgraphics,whilemovingobjectsaroundinspace,itwillseldommakesensetouseannon-invertibletransform.
17
I =1 0 00 1 00 0 1
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥.
MM −1 = M −1M = I .
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Lineartransformofabasis• Abasisundergoesalineartransformation
• Validtomultiplyamatrixtimesacoordinatevector
• changeabasisofavectorto
18
b t
⇒ b tM
v= b tc = a tM −1c . a
t= b tM ,
b t
a t
18/03/13
10
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Dotproduct• Input:twovectors• Output:arealnumber• dotproduct=thesquaredlength
• Theanglebetweenthetwovectors:
19
v⋅w
v 2:= v⋅v
cosθ = v
⋅w
vw .
θ ∈[0...π ]
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
3Dorthogonalbasis• Orthogonalvectors:• Aright-handedorthogonalcoordinatesystem.
Thezaxiscomesoutofthescreen(OpenGL).• Aleft-handedorthogonalcoordinatesystem.
Thezaxisgoesintothescreen(DirectX).
20
v⋅w= 0
right-handed
left-handed
18/03/13
11
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Crossproduct• Input:twovectors• Output:avector
• whereisaunitvectorthatisorthogonaltotheplanespannedbyand
• formsaright-handedbasis
21
[v,w,n]
n
v
w
v×w:= vwsinθn,
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Crossproduct• Inaright-handedorthogonalbasis
• Wecancomputeacross-productas
22
(b tc)× (b
td) =
c2d3 − c3d2c3d1 − c1d3c1d2 − c2d1
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
b t
18/03/13
12
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
2DRotation• Letbea2Dright-handedorthonormal
(orthogonalandunitvectors)basis
• Rotatedvector
23
v= b1
b2⎡
⎣⎤⎦
xy
⎡
⎣⎢⎢
⎤
⎦⎥⎥.
b t
x ' = xcosθ − ysinθy ' = xsinθ + ycosθ .
x 'y '
⎡
⎣⎢⎢
⎤
⎦⎥⎥= cosθ −sinθ
sinθ cosθ⎡
⎣⎢
⎤
⎦⎥
xy
⎡
⎣⎢⎢
⎤
⎦⎥⎥.
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
3DRotation• Everyrotationfixesanaxisofrotationand
rotatesbysomeangleaboutthataxis.• Rotationaroundthezaxis:
24
b1
b2
b3⎡
⎣⎤⎦
xyz
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
⇒ b1
b2
b3⎡
⎣⎤⎦
cosθ −sinθ 0sinθ cosθ 00 0 1
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
xyz
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
18/03/13
13
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
3DRotation• Rotationaroundthexaxis
• Rotationaroundtheyaxis
25
1 0 00 cosθ −sinθ0 sinθ cosθ
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
cosθ 0 sinθ0 1 0
−sinθ 0 cosθ
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
xyz-Euleranglerotation• Axisofrotation
• xyz-Euleranglerotationmatrix
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.
18/03/13
14
MinH.Kim(KAIST) Foundationsof3DComputerGraphics,S.Gortler,MITPress,2012
Scales• Scalingoperations
27
b1
b2
b3⎡
⎣⎤⎦
xyz
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
⇒ b1
b2
b3⎡
⎣⎤⎦
α 0 00 β 00 0 γ
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥
xyz
⎡
⎣
⎢⎢⎢
⎤
⎦
⎥⎥⎥