computer graphics seminar
play

Computer Graphics Seminar MTAT.03.305 Spring 2020 Raimond Tunnel - PowerPoint PPT Presentation

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


  1. Computer Graphics Seminar MTAT.03.305 Spring 2020 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 ( d ) ⋅ ( y ) = ( cx + dy ) ax + by a b x ● Mathematical understanding 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 Apply geometry and transformations transformations Vertex shader 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: ● 2 endpoints (x 1 , y 1 , z 1 , 1) ● Infinite number of points between ● Defined by the endpoints ● Interpolated and rasterized in the GPU

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

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

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

  12. Triangle ● Consists of: ● 3 points called vertices ● 3 lines called edges ● 1 face Front face ● 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 I C H J D G K B F L A D B C E A B A F C A 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 ● Linear transformations ● Scaling, reflection ● Rotation ● Shearing ● Affine transformations Homogeneous coordinates are ● Translation (moving / shifting) needed here. ● Projection transformations And for the perspective ● Perspective projection ● Orthographic

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

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

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

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

  25. 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 will not use homogeneous coordinates at the moment, but they will be back...

  26. Linear Transformation Scale

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

  28. 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

  29. 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?

  30. Linear Transformation Shear

  31. Shearing ● Remember it for translations later. ( 1 ) ⋅ ( y ) 1 0 x ● Tilts only one axis. 1 ● Squares become parallelograms. ( 1 ) ⋅ ( 2 ) = ( 2 ) 1 0 0 0 1 ( 1 ) ⋅ ( 2 ) = ( 3 ) 1 0 1 1 1

  32. 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 + tan (ϕ) ⋅ y x 0 y

  33. Linear Transformation Rotation

  34. 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?

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

  36. 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.

  37. Rotation ● To do a rotation around an arbitrary axis, we can: ● Rotate that axis to be the x-axis ( 1 ) 1 0 0 0 ● Rotate around the new x-axis 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...

  38. 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?

  39. Affine Transformation Translation

  40. 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)

  41. 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)

  42. Translation tan(45°) = 1 ● Do a shear-x(45°) operation on the 2D world! ● Everything has now moved 1 unit in x to the right from the original position.

  43. Translation tan(45°) = 1 tan(63.4°) = 2 ● What if we do shear-x(63.4°)? ● We can do translation (movement)!

  44. Translation ● When we represent our points in one dimension higher space, where the extra coordinate is 1, we get to the homogeneous space. ( 1 ) 1 ) = ( 1 ) ⋅ ( x + x t 1 x t x 1 ) ( 1 ) = ( 1 ) ⋅ ( 1 ) x + x t 1 0 0 x t 0 x y + y t 0 1 0 y t y ( 1 ) = ( ⋅ ( 1 ) z 1 0 x t x + x t z + z t 0 0 1 z t x y + y t 0 1 y t y 0 0 0 0 0

  45. Transformations ● This together gives us a very good toolset to transform our geometry as we wish. Translation column Linear transformations ( 1 ) = ( ) ⋅ ( 1 ) a b c x t ax + by + cz + x t x dx + ey + fz + y t d e f y t y Augmented trasnformation z gx + hy + iz + z t g h i z t matrix! 0 0 0 1 Used for perspective projection...

  46. Multiple transformations ● Everything starts from the origin! ● To apply multiple transformations, just multiply matrices.

  47. Multiple transformations Our initial geometry defined by vertices: (-1, -1), (1, -1), (1, 1), (-1, 1)

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