• No results found

CSE 5542 - Real Time Rendering Week 5

N/A
N/A
Protected

Academic year: 2021

Share "CSE 5542 - Real Time Rendering Week 5"

Copied!
78
0
0

Loading.... (view fulltext now)

Full text

(1)CSE 5542 - Real Time Rendering. Week 5.

(2) Slides(Some) Courtesy –  E. Angel and D. Shreiner.

(3) Much Content ….

(4) What ?. 4.

(5) Transformations.

(6) Where in OpenGL ?.

(7) In Vertex Shader.

(8) Typical Transform.

(9) Scaling.

(10) Scaling. Expand or contract along each axis (fixed point of origin). x’=sxx. y’=syx. z’=szx. p’=Sp. S = S(sx, sy, sz) =. 10. ⎡ sx ⎢ 0 ⎢ ⎢ 0 ⎢ ⎣ 0. 0. 0. sy 0. 0 sz. 0. 0. 0⎤ 0⎥ ⎥ 0⎥ ⎥ 1⎦.

(11) Linear Transform - Scaling.

(12) Scaling – This will do !. ! x 0 0 $ # & S =# 0 y 0 & # 0 0 z & " % 3x3. ! x 0 $ & S =# #" 0 y &% 2x2.

(13) As Matrices.

(14) Reflection. corresponds to negative scale factors. sx = -1 sy = 1. original. sx = -1 sy = -1. sx = 1 sy = -1. 14.

(15) Rotation.

(16) Rotation (2D). Consider rotation about the origin by q degrees. – radius stays the same, angle increases by q. x = r cos (f + q). y = r sin (f + q). x’=x cos q –y sin q. y’ = x sin q + y cos q. x = r cos f. y = r sin f. 16.

(17) Rotation about z axis. • Rotation about z axis in three dimensions leaves all points with the same z. – Equivalent to rotation in two dimensions in planes of constant z. x’=x cos q –y sin q. y’ = x sin q + y cos q. z’ =z. – or in homogeneous coordinates. p’=Rz(q)p. 17.

(18) Rotation Matrix. ⎡cos θ − sin θ ⎢ sin θ cos θ R = Rz(q) = ⎢ ⎢ 0 0 ⎢ 0 ⎣ 0. 18. 0 0⎤ 0 0⎥⎥ 1 0⎥ ⎥ 0 1⎦.

(19) Example.

(20) X- & Y-axes. Same argument as for rotation about z axis. For rotation about x axis, x is unchanged. For rotation about y axis, y is unchanged. 0 0 ⎡1 ⎢0 cos θ - sin θ ⎢ R = Rx(q) = ⎢0 sin θ cos θ ⎢ 0 0 ⎣0 ⎡ cos θ ⎢ 0 R = Ry(q) = ⎢ ⎢- sin θ ⎢ ⎣ 0 20. 0⎤ 0⎥ ⎥ 0⎥ ⎥ 1⎦. 0 sin θ 0⎤ 1 0 0⎥ ⎥ 0 cos θ 0⎥ ⎥ 0 0 1⎦.

(21) Linear Spaces.

(22) Recap: Linear Independence A set of vectors v1, v2, …, vn is linearly independent if α1v1+α2v2+.. αnvn=0 iff α1=α2=…=0. 22.

(23) Recap: Coordinate Systems • • • • . A basis v1, v2,…., vn A vector is written v=α1v1+ α2v2 +….+αnvn Scalars {α1, α2, …. Αn}- representation of v given basis Representation as a row or column array of scalars. a=[α1. 23. α2 …. αn]T=. ⎡ α1 ⎤ ⎢ α ⎥ ⎢ 2 ⎥ ⎢ . ⎥ ⎢α ⎥ ⎢ n ⎥ ⎣ ⎦.

(24) Change of Coordinate Systems. • Consider two representations of same vector with respect to two different bases:. a=[a1 a2 a3 ]. b=[b1 b2 b3]. where. v=a1v1+ a2v2 +a3v3 = [a1 a2 a3] [v1 v2 v3] T. =b u + b u +b u = [b b b ] [u u u ] T. 24. 1 1. 2 2. 3 3. 1. 2. 3. 1. 2. 3.

(25) Second in Terms of First. Each of the basis vectors, u1,u2, u3, are vectors that can be represented in terms of the first basis. u1 = g11v1+g12v2+g13v3. u = g v +g v +g v . 2. 21 1. 22 2. 23 3. u3 = g31v1+g32v2+g33v3. 25. v.

(26) Recap: Matrix Form . The coefficients define a 3 x 3 matrix. ⎡ γ11 γ12 γ13 ⎤. ⎢ γ ⎥ M = ⎢ 21 γ 22 γ 23 ⎥. ⎢⎣ γ 31 γ 32 γ 33 ⎥⎦. and the bases can be related by. a=MTb. 26.

(27) Translation. • Move (translate, displace) a point to a new location. P’. d. P. • Displacement determined by a vector d. – Three degrees of freedom. – P’=P+d. 27.

(28) Translating in 3D. object. 28. translation: every point displaced. by same vector.

(29) Translation.

(30) With 2D/3D Vectors. ! x' $ ! x $ ! α $ & # & # & # # y ' & = # y &+# β & # z' & # z & # χ & " % " % " %.

(31) In Matrix Form.

(32) As Matrices.

(33) As Code.

(34) Homogenous Coordinates.

(35) Homogenous Coordinates.

(36) Allows Linearity.

(37) Homogeneous Coordinates. Homogeneous coordinates for [x y z]:. p =[x’ y’ z’ w] T =[wx wy wz w] T. Three dimensional point (for w≠0) by. x←x’/w, y←y’/w, z←z’/w. If w=0, the representation is that of a vector. Replaces points in 3D by lines through origin in 4D dimensions. For w=1, the representation of a point is [x y z 1]. 37.

(38) In Computer Graphics. Homogeneous coordinates key . – All standard transformations: rotation, translation, scaling.. – Implemented matrix multiplications with 4 x 4 matrices. – Hardware pipeline works with 4D representations. – Orthographic viewing: w=0 – vectors & w=1 – points. – For perspective we need a perspective division. 38.

(39) Recap: Frames. • A coordinate system is insufficient for points. • Origin & basis vectors form a frame. v2. P0. v3. 39. v1.

(40) Recap : Unified Representation. • Frame determined by (P0, v1, v2, v3). • For this frame, every vector can be written as . v=a1v1+ a2v2 +….+anvn. • Every point can be written as. P = P0 + b1v1+ b2v2 +….+bnvn. 40.

(41) Recap : Unified Representation. Since 0•P = 0 and 1•P =P. v=a1v1+ a2v2 +a3v3 = [a1 a2 a3 0 ] [v1 v2 v3 P0] T. P = P0 + b1v1+ b2v2 +b3v3= [b1 b2 b3 1 ] [v1 v2 v3 P0] T. Thus we obtain the four-dimensional homogeneous coordinate representation. v = [a1 a2 a3 0 ] T. p = [b1 b2 b3 1 ] T. 41.

(42) Change of Frames. • We can apply a similar process in homogeneous coordinates to the representations of both points and vectors. Consider two frames:. (P0, v1, v2, v3). (Q0, u1, u2, u3). v2. P0. u2. u1. Q0. v1. u3. v3. • Any point or vector can be represented in either frame. • We can represent Q0, u1, u2, u3 in terms of P0, v1, v2, v3 . 42.

(43) One Frame in Terms of Other. Extending what we did with change of bases. u1 = γ11v1+γ12v2+γ13v3. u2 = γ21v1+γ22v2+γ23v3. u3 = γ31v1+γ32v2+γ33v3. Q0 = γ41v1+γ42v2+γ43v3 +γ44P0. defining a 4 x 4 matrix. ⎡ γ11 ⎢ γ M = ⎢ 21 ⎢ γ 31 ⎢ ⎣ γ 41. 43. γ12 γ 22 γ 32 γ 42. γ13 γ 23 γ 33 γ 43. 0⎤ ⎥ 0⎥ 0⎥ ⎥ 1⎦.

(44) Working with Representations. Within the two frames any point or vector has a representation of the same form. a=[a1 a2 a3 a4 ] in the first frame. b=[b1 b2 b3 b4 ] in the second frame. where a4 = b4 = 1 for points and a4 = b4 = 0 for vectors and. Tb. a=M. The matrix M is 4 x 4 and specifies an affine transformation in homogeneous coordinates. 44.

(45) Affine Transformations • Every linear transformation is equivalent to a change in frames • Every affine transformation preserves lines • However, an affine transformation has only 12 degrees of freedom because 4 of the elements in the matrix are fixed and are a subset of all possible 4 x 4 linear transformations 45.

(46) General Structure. ! # # ". SR 0 0 0. $ T & 1 &%.

(47) Inverses. • Can compute inverses use simple geometric observations. – Translation: T-1(dx, dy, dz) = T(-dx, -dy, -dz) . – Rotation: R -1(q) = R(-q). • Holds for any rotation matrix. • Note that since cos(-q) = cos(q) and sin(-q)=-sin(q). R -1(q) = R T(q). – Scaling: S-1(sx, sy, sz) = S(1/sx, 1/sy, 1/sz) . 47. .

(48) Concatenation. • We can form arbitrary affine transformation matrices by multiplying together rotation, translation, and scaling matrices. • Since same transformation is applied to many vertices, the cost of forming a matrix M=ABCD is not significant compared to the cost of computing Mp for many vertices p. 48.

(49) In-situ Transformations.

(50) In Place Scaling.

(51) As Opposed To.

(52) As Matrices and code.

(53)

(54) Fixed Point Other Than Origin. Move fixed point to origin. Rotate. Move fixed point back. M = T(pf) R(θ) T(-pf). 54.

(55) Order of Transformations. • Note that matrix on the right is the first applied. • Mathematically, the following are equivalent. p’ = ABCp = A(B(Cp)). • In terms of column matrices. p’T = pTCTBTAT. 55.

(56) In Shaders. uniform mat4 ViewT,ViewR, ModelT, ModelR, ModelS, Project;. in vec4 Vertex;. void main(). {. gl_Position = Project. * ModelS * ModelR * ModelT. * ViewR * ViewT. * Vertex;. }.

(57) General Rotation About Origin. A rotation by θ about an arbitrary axis. can be decomposed into the concatenation. of rotations about the x, y, and z axes. R(θ) = Rz(θz) Ry(θy) Rx(θx) . θx θy θz are called the Euler angles y. Note that rotations do not commute. We can use rotations in another order but. with different angles. 57. z. q. v. x.

(58)

(59) Shear. • Helpful to add one more basic transformation. • Equivalent to pulling faces in opposite directions. 59.

(60) Shear Matrix. Consider simple shear along x axis. x’ = x + y cot θ. y’ = y. z’ = z. ⎡1 cot θ ⎢0 1 H(q) =⎢. 0 ⎢0 ⎢ 0 ⎣0 60. 0 0⎤ 0 0⎥ ⎥ 1 0⎥ ⎥ 0 1⎦.

(61) Viewing Transform.

(62) World & Camera Frames. • Changes in frame are then defined by 4 x 4 matrices. • In OpenGL, base frame is the world frame . • Represent entities in the camera frame by changing world representation using model-view matrix. • Initially these frames are the same (M=I). 62.

(63)

(64) Steps.

(65) Moving the Camera If objects are on both sides of z=0, move camera frame. M=. 65. ⎡1 ⎢0 ⎢ ⎢0 ⎢ ⎣0. 0 0 1 0. 0 ⎤ 0 ⎥⎥ 0 1 − d ⎥ ⎥ 0 0 1 ⎦.

(66)

(67) Perspective. P is defined as long as l ≠ r, t ≠ b, and n ≠ f..

(68) Details.

(69) To Note. z values will end up at 1.0 !. Lose information about depth. No scaling result to the [–1.0, 1.0] range.

(70) Two Cases. Symmetric, centered frustum, where z-axis is centered in the cone. Asymmetric frustum- view thru a window and near it, but not toward its middle.

(71) Symmetric Case. • Project points in frustum onto near plane. • Line from (0, 0, 0) makes ratio of z to x same, and same for z to y for all points. • xproj = x · znear, yproj = y · znear. • Scale window size to [–1.0, 1.0].

(72) Symmetric Case.

(73) Asymmetric.

(74)

(75) Parallel Viewing. P is defined as long as l ≠ r, t ≠ b, and n ≠ f..

(76) Details.

(77) Symmetric.

(78) Asymmetric.

(79)

References

Related documents

Landscape Design Manufacturing volumetric components Foundations 1st – 6th floor Roof HVAC

To define the affine transformation, the coefficients for the transformation from engineering grid to projected coordinate reference system are required. The set of parameters

parallel lines may not stay parallel affine transformation + 3 parameters.. Transformations

One good reason to study worker displacement is that its consequences can yield insights into the wage determination process. Human capital theory predicts that, to the extent

Accelerated investments in future growth reflected in EBITDA & margins.. -4 percentage points), relocation of data center & +27 FTE  Financial result further improved

For example, suppose we want to scale an object up to a new size, shear the object to a new shape, and finally rotate the object. Let S be the scale matrix, H be the shear matrix and

The Distributed Voice Mail feature allows users with mailboxes on that server to receive and pickup voice mail messages without having to depend on a WAN connection to the