computer graphics seminar
play

Computer Graphics Seminar MTAT.03.305 Fall 2019 Raimond Tunnel - PowerPoint PPT Presentation

Computer Graphics Seminar MTAT.03.305 Fall 2019 Raimond Tunnel Computer Graphics Graphical illusion via the computer Displaying something meaningful (incl art) Math Computers are good at... computing. To do computer graphics, we


  1. Computer Graphics Seminar MTAT.03.305 Fall 2019 Raimond Tunnel

  2. Computer Graphics ● Graphical illusion via the computer ● Displaying something meaningful (incl art)

  3. Math ● Computers are good at... computing. ● To do computer graphics, we need math for the computer to compute. ● Geometry, algebra, calculus.

  4. Math ● For creating and manipulating 3D objects we use: ● Analytic geometry – math about coordinate systems ● Linear algebra – math about vectors and spaces

  5. Skills for Computer Graphics ● Mathematical understanding ( d ) ⋅ ( y ) = ( cx + dy ) ax + by a b x c ● Geometrical (spatial) thinking GLuint vaoHandle; ● Programming glGenVertexArrays(1, &vaoHandle); glBindVertexArray(vaoHandle); ● Visual creativity & aesthetics

  6. The Standard Graphics Pipeline Define geometry and transformations Data Vertex shader Vertex transformations Apply geometry and transformations Culling & Clipping Rasterization Fragment shading Visibility tests & Blending

  7. Point ● Simplest geometry primitive ● In homogeneous coordinates: (x, y, z, 1) (x, y, z, w), w ≠ 0 ● Represents a point (x/w, y/w, z/w) ● Usually you can put w = 1 for points ● Actual division will be done by GPU later

  8. Line (segment) ● Consists of: (x 1 , y 1 , z 1 , 1) ● 2 endpoints ● Infinite number of points between ● Defined by the endpoints (x 2 , y 2 , z 2 , 1) ● Interpolated and rasterized in the GPU

  9. Line (segment) ● Consists of: (x 1 , y 1 , z 1 , 1) ● 2 endpoints ● Infinite number of points between ● Defined by the endpoints (x 2 , y 2 , z 2 , 1) ● Interpolated and rasterized in the GPU

  10. Line (segment) ● Consists of: (x 1 , y 1 , z 1 , 1) ● 2 endpoints ● Infinite number of points between ● Defined by the endpoints (x 2 , y 2 , z 2 , 1) ● Interpolated and rasterized in the GPU

  11. Triangle ● Consists of: (x 3 , y 3 , z 3 , 1) ● 3 points called vertices (x 2 , y 2 , z 2 , 1) ● 3 lines called edges ● 1 face (x 1 , y 1 , z 1 , 1) ● Defined by 3 vertices ● Face interpolated and rasterized in the GPU ● Counter-clockwise order defines the front face

  12. Triangle ● Consists of: (x 3 , y 3 , z 3 , 1) ● 3 points called vertices (x 2 , y 2 , z 2 , 1) ● 3 lines called edges Front face ● 1 face (x 1 , y 1 , z 1 , 1) ● Defined by 3 vertices ● Face interpolated and rasterized in the GPU ● Counter-clockwise order defines the front face

  13. Why triangles? ● They are in many ways the simplest polygons ● 3 different points always form a plane ● Easy to rasterize (fill the face with pixels) ● Every other polygon can be converted to triangles

  14. Why triangles? ● They are in many ways the simplest polygons ● 3 different points always form a plane ● Easy to rasterize (fill the face with pixels) ● Every other polygon can be converted to triangles ● OpenGL used to support other polygons too ● Must have been: – Simple – No edges intersect each other – Convex – All points between any two inner points are inner points

  15. Examples of polygons C I D H J G B K F L A D A B C E A B A F C C B D E

  16. OpenGL < 3.1 primitives OpenGL Programming Guide 7 th edition, p49

  17. After OpenGL 3.1 OpenGL Programming Guide 8 th edition, p89-90

  18. In the beginning there were points ● We can now define our geometric objects!

  19. In the beginning there were points ● We can now define our geometric objects! ● We want to move our objects! World's (0, 0, 0)

  20. Transformations ● Homogeneous coordinates allow easy: ● Linear transformations – Scaling, reflection – Rotation – Shearing ● Affine transformations – Translation (moving / shifting) ● Projection transformations – Perspective – Orthographic

  21. Transformations ● Homogeneous coordinates allow easy: ● Linear transformations – Scaling, reflection Actually these we could do without – Rotation homogeneous coordinates... – Shearing ● Affine transformations – Translation (moving / shifting) ● Projection transformations – Perspective – Orthographic T h i s t o o . . .

  22. Transformations ● Every transformation is a function ● As you remember from algebra, all linear functions can be represented as matrices = ( 1 ) f ( v )= ( z ) ⋅ ( z ) 2 ⋅ x 2 0 0 x 3 v ∈ R y 0 1 0 y v = ( z ) 0 0 x y Column-major format

  23. Transformations ● Every transformation is a function ● As you remember from algebra, all linear functions can be represented as matrices = ( 1 ) f ( v )= ( z ) ⋅ ( z ) 2 ⋅ x 2 0 0 x 3 v ∈ R y 0 1 0 y v = ( z ) 0 0 x y Linear function, which increases the first coordinate two times. Column-major format

  24. Transformations ● Every transformation is a function ● As you remember from algebra, all linear functions can be represented as matrices = ( 1 ) f ( v )= ( z ) ⋅ ( z ) 2 ⋅ x 2 0 0 x 3 v ∈ R y 0 1 0 y v = ( z ) 0 0 x y Linear function, which Same function increases the first as a matrix coordinate two times. Column-major format

  25. Transformations ● GPU-s are built for doing transformations with matrices on points (vertices). M ⋅ v 0 Control ALU ALU ALU ALU ... Cache M ⋅ v 1 Control ALU ALU ALU ALU ... Cache Control ALU ALU ALU ALU ... M ⋅ v 2 Cache Control ALU ALU ALU ALU ... Cache Vertex shader Control ALU ALU ALU ALU code ... Cache Control ALU ALU ALU ALU ... Cache Control ALU ALU ALU ALU ... Cache Control ALU ALU ALU ALU ... Cache DRAM

  26. Transformations ● GPU-s are built for doing transformations with matrices on points (vertices). ● Linear transformations satisfy: f ( a 1 x 1 + ... + a n x n )= a 1 f ( x 1 )+ ... + a n f ( x n ) We do not use homogeneous coordinates at the moment, but they will be back...

  27. Linear Transformation Scale

  28. Scaling ● Multiplies the coordinates by a scalar factor. ( 1 ) ⋅ ( 1.5 ) = ( 1.5 ) ( 1 ) ⋅ ( y ) 2 0 1.5 3 2 0 x 0 0

  29. Scaling ● Multiplies the coordinates by a scalar factor. ● Scales the standard basis vectors / axes. ( 1 ) ⋅ ( 1 ) = ( 1 ) = e 1 ( 1 ) ⋅ ( 0 ) = ( 0 ) = e 0 2 0 0 0 2 0 1 2 0 0

  30. Scaling ● In general we could scale each axis ( a z ) a x – x-axis scale factor a x 0 0 0 a y 0 a y – y-axis scale factor 0 0 a z – z-axis scale factor ● If some factor is negative, this matrix will reflect the points from that axis. Thus we get reflection. What happens to out triangles when an odd number of factors are negative?

  31. Linear Transformation Shear

  32. Shearing ● Not much used by itself, but remember it for translations later. ● Squares become parallelograms. ( 1 ) ⋅ ( y ) ● Tilts only one axis. 1 0 x 1 ( 1 ) ⋅ ( 2 ) = ( 2 ) 1 0 0 0 1 ( 1 ) ⋅ ( 2 ) = ( 3 ) 1 0 1 1 1

  33. Shearing ● Shear-y , we tilt parallel to y-axis by angle φ counter-clockwise ( 1 ) ⋅ ( y ) = ( ⋅ x ) 1 0 x x tan (ϕ) y + tan (ϕ) ● Shear-x , we tilt parallel to x - axis by angle φ clockwise ( 1 ) ⋅ ( y ) = ( ) tan (ϕ) 1 x x + tan (ϕ) ⋅ y 0 y

  34. Linear Transformation Rotation

  35. Rotation ● Shearing moved only one axis ● Also changed the size of the basis vector ● Can we do better? Did you notice that the columns of the transformation matrix show the coordinates of the new basis vectors?

  36. Rotation e' 0 =(∣ a ∣ , ∣ b ∣)=( cos (α) , sin (α)) cos (α)= ∣ a ∣ ∣ e' 0 ∣=∣ a ∣ 1 =∣ a ∣ e' 1 =(∣ a' ∣ , ∣ b' ∣)=(− sin (α) , cos (α))

  37. Rotation ● So if we rotate by α in counter-clockwise order in 2D, the transformation matrix is: e' 1 e' 0 ( cos (α) ) cos (α) − sin (α) sin (α) ● In 3D we can do rotations in each plane (xy, xz, yz), so there can be 3 different matrices.

  38. Rotation ● To do a rotation around an arbitrary axis, we can: ● Rotate that axis to be the x-axis ( 1 ) ● Rotate around the new x-axis 1 0 0 0 0 cos (α) − sin (α) 0 ● Invert the first rotations sin (α) cos (α) 0 0 0 0 0 (move the old x-axis back) ● OpenGL provides a command for rotating around a given axis. ● Generally quaternions are used for rotations. Quaternions are elements of a number system that extend the complex numbers...

  39. Do we have everything now? ● We can scale, shear and rotate our geometry around the origin... What if we have an object not centered in the origin?

  40. Affine Transformation Translation

  41. Translation ● Imagine that a 1D world is located at y=1 line in 2D space. ● Notice that all the points are in the form: ( x , 1)

  42. Translation ● Imagine that a 1D world is located at y=1 line in 2D space. Objects The 1D world ● Notice that all the points are in the form: ( x , 1)

  43. Translation ● Do a shear-x(45°) operation on the 2D world! ● Everything in the 1D world has moved magically one x-coordinate to the right... tan(45°) = 1

  44. Translation tan(63.4°) = 2 ● What if we do shear-x(63.4°)? ● Everything has now moved 2 x-coordinates to the right from the original position ● We can do translation (movement)!

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend