CS580: Compuer Graphics Min H. Kim KAIST School of Compuing Elemens of Compuer Graphics Geomery Maerial model Ligh Rendering Virual phoography 2
Foundaions of Compuer Graphics A PINHOLE CAMERA IN 3D 3 Pinhole camera model z e = Only rays of ligh ha pass hrough his poin reach he film plane and have heir inensiy recorded on film. The image is recorded a a film plane placed a, say, z e = 4 2
Geomeric daa ypes Poin: p represens place Vecor: v represens moion/offse beween poins Coordinae vecor: c! Coordinae sysem: s basis for vecors frame for poins 5 Vecor space A vecor space V is some se of elemens v Coordinae vecor: c if...bn are linearly independen, all vecors v of V can be expressed wih coordinaes c i of a basis of V (a se of b i ). n is he dimension of he basis/space v c = c i b i = b v = b c. 3 c 2. i c 3 6 3
Linear ransformaion 3-by-3 marix Linear ransform of a vecor Linear ransform of a basis v! = b "! c b!" Mc M, M,2 M,3 M 2, M 2,2 M 2,3 M 3, M 3,2 M 3,3. v = b c = a M c. 7 Lef-of rule Poin is ransformed wih respec o he he frame ha appears immediaely o he lef of he ransformaion marix in he expression. We read f f S f is ransformed by We read f S wih respec o f = a A a SA S a f is ransformed by wih respec o 8 4
Scaling a poin over frame p = f c f Sc p is ransformed by S wih respec o f 9 Scaling a poin over frame p = a A c a SA c is ransformed by S wih respec o p a 0 5
Scaling a poin over frame Roaing a poin over frame The same reasoning o ransformaions of frames hemselves: f f R f is ransformed by wih respec o f In anoher frame: f R f = a A a RA is ransformed by R wih respec o a 2 6
Roaing a poin over frame p is ransformed by wih respec o f R p = f c f Rc 3 Roaing a poin over frame p = a A c a RA c is ransformed by R wih respec o p a 4 7
Roaing a poin over frame 5 Auxiliary Frame You wan o build he solar sysem The Moon roaes around he Earh s frame The Earh roaes around he Sun s frame The Moon The Earh The Sun 6 8
Produc of vecors & roaion Do produc: Cross produc: v w := v w cosθ. v w := v w sinθn, 3D roaion marices: around z axis, x axis, y axis cosθ sinθ 0 sinθ cosθ 0 0 0 0 0 0 cosθ sinθ 0 sinθ cosθ cosθ 0 sinθ 0 0 sinθ 0 cosθ 7 Roaion ransformaion 3-by-3 ransform marix!"!" a b c e f g i j k. 8 9
Translaion ransformaion 3-by- ranslaion!"!" + d + h + l. 9 Roaion+Trans. ransformaion 3-by-4 ransform marix (non-square marix, no-inverible)!"!" a b c e f g i j k d h l. 20 0
Linear ransformaion 3-by-3 ransform marix à 4-by-4 affine ransform o o a b c 0 e f g 0 i j k 0 0 0 0. 2 Translaion ransformaion ranslaion ransformaion o poins b o o 0 0 x 0 0 y 0 0 z 0 0 0. 22
Affine ransform marix An affine marix can be facored ino a linear par and a ranslaional par: a b c d e f g h i j k l 0 0 0 = 0 0 d 0 0 h 0 0 l 0 0 0 a b c 0 e f g 0 i j k 0 0 0 0. l 0 = i 0 l 0 0 A = TL 23 Normals Normal: a vecor ha is orhogonal o he angen plane of he surfaces a ha poin. he angen plane is a plane of vecors ha are defined by subracing (infiniesimally) nearby surface poins: n ( p p 2 ) = 0 24 2
The eye s view (a virual camera) The world frame is in red The objec frame is in green The eye frame is in blue The eye is looking down is negaive z oward he objec. 25 World, objec and eye frames World frame (world coordinaes) a basic righ-handed orhonormal frame we never aler his frame w oher frames can be described wr he world frame Objec frame (objec coordinaes) model he geomery of he objec using verex coordinaes no need o be aware of he global placemen a righ-handed orhonormal frame of objec Eye frame (camera coordinaes): laer on o 26 3
World vs. objec frame The relaionship beween he world frame and objec frame: affine 4-by-4 marix O (rigid body ransformaion: roaion + ranslaion only) o = w O The meaning of O is he relaionship beween he world frame o he objec s coordinae sysem. To move he objec frame o iself, we change he marix O. 27 The eye frame Eye frame (camera coordinaes) a righ-handed orhonormal frame e he eye looks down is negaive z axis o make a picure e = w E 28 4
Exrinsic ransformaion of he eye we explicily sore he marix p = o c = w Oc = e E Oc Objec coordinaes: c World coordinaes: Oc Eye coordinaes: E Oc Calculaing he eye coordinaes of every verexes: x e y e z e E = E O e = w E x o y o z o 29 Moving an Objec We wan he objec o roae around is own cener abou he viewer s y axis, when we move he mouse o he righ. How we could do his? 30 5
Moving an Objec Basic idea: se a frame o = w O = a A O a MA O a = w A = w AMA O. Wha is he bes frame a o do his? 3 Moving an Objec Wha if we choose o we ransform his objec wih respec o o raher han wih respec o our observaion hrough he window. 32 6
Moving an Objec Wha if we choose o we ransform his objec wih respec o o raher han wih respec o our observaion hrough he window. Wha if we ransform wih respec o o e we will roae around he origin of he eye s frame e (i appears o orbi around he eye). Then wha frame i should be? 33 Moving an Objec We acually wan wo differen operaions. o ransform (roae) he objec a is origin 2. bu he roaion axis should be he y axis of he eye. 34 7
Moving an Objec From he lef, we ranslae he world frame o he cener of he objec s frame, and hen roaing he objec s frame abou ha poin o align wih he direcions of he eye. 35 How o move an Objec Recalling he Affine ransform.: A = TR The objec s Affine ransform.: O = (O) T (O) R (we wan he objec s roaion abou he objec s origin) The eye s Affine ransform.: E = (E) T (E) R (we wan he objec s roaion abou he eye s y axis)! The desired auxiliary frame a (imagine in a inverse way): a = w (O) T (E) R A = (O) T (E) R 36 8
Moving he eye We use he same auxiliary coordinae sysem. Bu in his case, he eye would orbi around he cener of he objec. Apply an affine ransform direcly o he eye s own frame (urning one s head, firs-person moion) e = w E, E EM 37 The eye marix (camera ransform) Specifying he eye marix e = w E by: he eye poin p he view poin (where he eye looks a) q he up vecor u z = normalize(p q) x = normalize(u z) y = z x normalize(c) = c / 2 + 2 + 2 NB marix sen o he verex shader is E - O E = x y z p x 2 y 2 z 2 p 2 x 3 y 3 z 3 p 3 0 0 0 z y u p x 38 9
The view marix (glulooka) Specifying he view marix V = E he eye poin p he view poin (where he eye looks a) he up vecor u z = normalize(q p) x = normalize(u z) y = x z normalize(c) = c / 2 + 2 + 2 V = NB glulooka is no he par of modern OpenGL! q x y z p x 2 y 2 z 2 p 2 x 3 y 3 z 3 p 3 0 0 0 x e y e z e = E O x z u p y 39 x o y o z o Modelview marix Modelview marix (MVM) E O Describes he orienaion and posiion of he view and he orienaion and posiion of he objec O wih respec o he eye frame p = o c = w Oc = e e E Oc The verex shader will ake hese verex daa and perform he muliplicaion E Oc, producing he eye coordinaes used in rendering normalmarix() produces he inverse ranspose of he linear facor o ge uniform NMVM E 40 20