Presentation is loading. Please wait.

Presentation is loading. Please wait.

David Luebke2/16/2016 CS 551 / 645: Introductory Computer Graphics Mathematical Foundations The Rendering Pipeline.

Similar presentations


Presentation on theme: "David Luebke2/16/2016 CS 551 / 645: Introductory Computer Graphics Mathematical Foundations The Rendering Pipeline."— Presentation transcript:

1 David Luebke2/16/2016 CS 551 / 645: Introductory Computer Graphics Mathematical Foundations The Rendering Pipeline

2 David Luebke2/16/2016 Administrivia l Sorry about the canceled class l OpenGL text: v1.1 or v1.2? l Teddy link fixed l Go over Assignment 1

3 David Luebke2/16/2016 XForms Intro l Xforms: a toolkit for easily building Graphical User Interfaces, or GUIs –See http://www.westworld.com/~dau/xformshttp://www.westworld.com/~dau/xforms –Lots of widgets: buttons, sliders, menus, etc. –Plus, an OpenGL canvas widget that gives us a viewport or context to draw into with GL or Mesa. l Quick tour now l You’ll learn the details yourself in Assignment 1

4 David Luebke2/16/2016 Mathematical Foundations l FvD appendix gives good review l I’ll give a brief, informal review of some of the mathematical tools we’ll employ –Geometry (2D, 3D) –Trigonometry –Vector and affine spaces n Points, vectors, and coordinates –Dot and cross products –Linear transforms and matrices

5 David Luebke2/16/2016 2D Geometry l Know your high-school geometry: –Total angle around a circle is 360° or 2π radians –When two lines cross: n Opposite angles are equivalent n Angles along line sum to 180° –Similar triangles: n All corresponding angles are equivalent n Corresponding pairs of sides have the same length ratio and are separated by equivalent angles n Any corresponding pairs of sides have same length ratio

6 David Luebke2/16/2016 Trigonometry l Sine: “opposite over hypotenuse” l Cosine: “adjacent over hypotenuse” l Tangent: “opposite over adjacent” l Unit circle definitions: –sin (  ) = x –cos (  ) = y –tan (  ) = x/y –Etc… (x, y)

7 David Luebke2/16/2016 3D Geometry l To model, animate, and render 3D scenes, we must specify: –Location –Displacement from arbitrary locations –Orientation l We’ll look at two types of spaces: –Vector spaces –Affine spaces l We will often be sloppy about the distinction

8 David Luebke2/16/2016 Vector Spaces l Two types of elements: –Scalars (real numbers):  … –Vectors (n-tuples): u, v, w, … l Supports two operations: –Addition operation u + v, with: Identity 0 v + 0 = v Inverse - v + (- v ) = 0 –Scalar multiplication: Distributive rule:  ( u + v ) =  ( u ) +  ( v ) (  +  ) u =  u +  u

9 David Luebke2/16/2016 Vector Spaces l A linear combination of vectors results in a new vector: v =  1 v 1 +  2 v 2 + … +  n v n l If the only set of scalars such that  1 v 1 +  2 v 2 + … +  n v n = 0 is  1 =  2 = … =  3 = 0 then we say the vectors are linearly independent l The dimension of a space is the greatest number of linearly independent vectors possible in a vector set l For a vector space of dimension n, any set of n linearly independent vectors form a basis

10 David Luebke2/16/2016 Vector Spaces: A Familiar Example l Our common notion of vectors in a 2D plane is (you guessed it) a vector space: –Vectors are “arrows” rooted at the origin –Scalar multiplication “streches” the arrow, changing its length (magnitude) but not its direction –Addition uses the “trapezoid rule”: u+v y x u v

11 David Luebke2/16/2016 Vector Spaces: Basis Vectors l Given a basis for a vector space: –Each vector in the space is a unique linear combination of the basis vectors –The coordinates of a vector are the scalars from this linear combination –Best-known example: Cartesian coordinates n Draw example on the board –Note that a given vector v will have different coordinates for different bases

12 David Luebke2/16/2016 Vectors And Points l We commonly use vectors to represent: –Points in space (i.e., location) –Displacements from point to point –Direction (i.e., orientation) l But we want points and directions to behave differently –Ex: To translate something means to move it without changing its orientation –Translation of a point = different point –Translation of a direction = same direction

13 David Luebke2/16/2016 Affine Spaces l To be more rigorous, we need an explicit notion of position l Affine spaces add a third element to vector spaces: points (P, Q, R, …) l Points support these operations –Point-point subtraction: Q - P = v n Result is a vector pointing from P to Q –Vector-point addition: P + v = Q n Result is a new point –Note that the addition of two points is not defined P Q v

14 David Luebke2/16/2016 Affine Spaces l Points, like vectors, can be expressed in coordinates –The definition uses an affine combination –Net effect is same: expressing a point in terms of a basis l Thus the common practice of representing points as vectors with coordinates (see FvD) l Analogous to equating pointers & integers in C –Be careful to avoid nonsensical operations

15 David Luebke2/16/2016 Affine Lines: An Aside Parametric representation of a line with a direction vector d and a point P 1 on the line: P(  ) = P origin +  d Restricting 0   produces a ray Setting d to P - Q and restricting 0    1 produces a line segment between P and Q

16 David Luebke2/16/2016 Dot Product l The dot product or, more generally, inner product of two vectors is a scalar: v 1 v 2 = x 1 x 2 + y 1 y 2 + z 1 z 2 (in 3D) l Useful for many purposes –Computing the length of a vector: length( v ) = sqrt( v v) –Normalizing a vector, making it unit-length –Computing the angle between two vectors: u v = |u| |v| cos(θ) –Checking two vectors for orthogonality –Projecting one vector onto another θ u v

17 David Luebke2/16/2016 Cross Product l The cross product or vector product of two vectors is a vector: l The cross product of two vectors is orthogonal to both l Right-hand rule dictates direction of cross product

18 David Luebke2/16/2016 Linear Transformations l A linear transformation: –Maps one vector to another –Preserves linear combinations l Thus behavior of linear transformation is completely determined by what it does to a basis l Turns out any linear transform can be represented by a matrix

19 David Luebke2/16/2016 Matrices By convention, matrix element M rc is located at row r and column c: l By (OpenGL) convention, vectors are columns:

20 David Luebke2/16/2016 Matrices l Matrix-vector multiplication applies a linear transformation to a vector: l Recall how to do matrix multiplication

21 David Luebke2/16/2016 Matrix Transformations l A sequence or composition of linear transformations corresponds to the product of the corresponding matrices –Note: the matrices to the right affect vector first –Note: order of matrices matters! The identity matrix I has no effect in multiplication l Some (not all) matrices have an inverse:

22 David Luebke2/16/2016 The Rendering Pipeline: A Whirlwind Tour Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

23 David Luebke2/16/2016 The Display You Know Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

24 David Luebke2/16/2016 The Framebuffer You Know Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

25 David Luebke2/16/2016 The Rendering Pipeline Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay l Why do we call it a pipeline?

26 David Luebke2/16/2016 2-D Rendering: Rasterization (Coming Soon) Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

27 David Luebke2/16/2016 The Rendering Pipeline: 3-D Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

28 David Luebke2/16/2016 The Rendering Pipeline: 3-D Modeling Transforms Scene graph Object geometry Lighting Calculations Viewing Transform Clipping Projection Transform Result: All vertices of scene in shared 3-D “world” coordinate system All vertices of scene in shared 3-D “world” coordinate system Vertices shaded according to lighting model Vertices shaded according to lighting model Scene vertices in 3-D “view” or “camera” coordinate system Scene vertices in 3-D “view” or “camera” coordinate system Exactly those vertices & portions of polygons in view frustum Exactly those vertices & portions of polygons in view frustum 2-D screen coordinates of clipped vertices 2-D screen coordinates of clipped vertices

29 David Luebke2/16/2016 The Rendering Pipeline: 3-D Scene graph Object geometry Lighting Calculations Clipping Result: All vertices of scene in shared 3-D “world” coordinate system All vertices of scene in shared 3-D “world” coordinate system Vertices shaded according to lighting model Vertices shaded according to lighting model Scene vertices in 3-D “view” or “camera” coordinate system Scene vertices in 3-D “view” or “camera” coordinate system Exactly those vertices & portions of polygons in view frustum Exactly those vertices & portions of polygons in view frustum 2-D screen coordinates of clipped vertices 2-D screen coordinates of clipped vertices Modeling Transforms Viewing Transform Projection Transform

30 David Luebke2/16/2016 Rendering: Transformations l So far, discussion has been in screen space l But model is stored in model space (a.k.a. object space or world space) l Three sets of geometric transformations: –Modeling transforms –Viewing transforms –Projection transforms

31 David Luebke2/16/2016 Rendering: Transformations l Modeling transforms –Size, place, scale, and rotate objects parts of the model w.r.t. each other –Object coordinates  world coordinates Z X Y X Z Y

32 David Luebke2/16/2016 Rendering: Transformations l Viewing transform –Rotate & translate the world to lie directly in front of the camera n Typically place camera at origin n Typically looking down -Z axis –World coordinates  view coordinates

33 David Luebke2/16/2016 Rendering: Transformations l Projection transform –Apply perspective foreshortening n Distant = small: the pinhole camera model –View coordinates  screen coordinates

34 David Luebke2/16/2016 Rendering: Transformations l All these transformations involve shifting coordinate systems (i.e., basis sets) l That’s what matrices do… l Represent coordinates as vectors, transforms as matrices l Multiply matrices = concatenate transforms!                     Y X Y X   cossin cos

35 David Luebke2/16/2016 Rendering: Transformations l Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector –Denoted [x, y, z, w] T n Note that w = 1 in model coordinates –To get 3-D coordinates, divide by w: [x’, y’, z’] T = [x/w, y/w, z/w] T l Transformations are 4x4 matrices l Why? To handle translation and projection

36 David Luebke2/16/2016 Rendering: Transformations l OpenGL caveats: –All modeling transforms and the viewing transform are concatenated into the modelview matrix –A stack of modelview matrices is kept –The projection transform is stored separately in the projection matrix l See Chapter 3 of the OpenGL book

37 David Luebke2/16/2016 The Rendering Pipeline: 3-D Modeling Transforms Scene graph Object geometry Lighting Calculations Viewing Transform Clipping Projection Transform Result: All vertices of scene in shared 3-D “world” coordinate system All vertices of scene in shared 3-D “world” coordinate system Vertices shaded according to lighting model Vertices shaded according to lighting model Scene vertices in 3-D “view” or “camera” coordinate system Scene vertices in 3-D “view” or “camera” coordinate system Exactly those vertices & portions of polygons in view frustum Exactly those vertices & portions of polygons in view frustum 2-D screen coordinates of clipped vertices 2-D screen coordinates of clipped vertices

38 David Luebke2/16/2016 Rendering: Lighting l Illuminating a scene: coloring pixels according to some approximation of lighting –Global illumination: solves for lighting of the whole scene at once –Local illumination: local approximation, typically lighting each polygon separately l Interactive graphics (e.g., hardware) does only local illumination at run time

39 David Luebke2/16/2016 The Rendering Pipeline: 3-D Modeling Transforms Scene graph Object geometry Lighting Calculations Viewing Transform Clipping Projection Transform Result: All vertices of scene in shared 3-D “world” coordinate system All vertices of scene in shared 3-D “world” coordinate system Vertices shaded according to lighting model Vertices shaded according to lighting model Scene vertices in 3-D “view” or “camera” coordinate system Scene vertices in 3-D “view” or “camera” coordinate system Exactly those vertices & portions of polygons in view frustum Exactly those vertices & portions of polygons in view frustum 2-D screen coordinates of clipped vertices 2-D screen coordinates of clipped vertices

40 David Luebke2/16/2016 Rendering: Clipping l Clipping a 3-D primitive returns its intersection with the view frustum: l See Foley & van Dam section 19.1

41 David Luebke2/16/2016 Rendering: Clipping l Clipping is tricky! In: 3 vertices Out: 6 vertices Clip In: 1 polygon Out: 2 polygons

42 David Luebke2/16/2016 The Rendering Pipeline: 3-D Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

43 David Luebke2/16/2016 Modeling: The Basics l Common interactive 3-D primitives: points, lines, polygons (i.e., triangles) l Organized into objects –Collection of primitives, other objects –Associated matrix for transformations l Instancing: using same geometry for multiple objects –4 wheels on a car, 2 arms on a robot

44 David Luebke2/16/2016 Modeling: The Scene Graph l The scene graph captures transformations and object-object relationships in a DAG l Objects in black; blue arrows indicate instancing and each have a matrix Robot BodyHead ArmTrunkLegEyeMouth

45 David Luebke2/16/2016 Modeling: The Scene Graph l Traverse the scene graph in depth-first order, concatenating transformations l Maintain a matrix stack of transformations ArmTrunk Leg EyeMouth HeadBody Robot Foot Matrix Stack Visited Unvisited Active

46 David Luebke2/16/2016 Modeling: The Camera l Finally: need a model of the virtual camera –Can be very sophisticated n Field of view, depth of field, distortion, chromatic aberration… –Interactive graphics (OpenGL): n Pinhole camera model u Field of view u Aspect ratio u Near & far clipping planes n Camera pose: position & orientation

47 David Luebke2/16/2016 Modeling: The Camera l These parameters are encapsulated in a projection matrix –Homogeneous coordinates  4x4 matrix! –See OpenGL Appendix F for the matrix l The projection matrix premultiplies the viewing matrix, which premultiplies the modeling matrices –Actually, OpenGL lumps viewing and modeling transforms into modelview matrix

48 David Luebke2/16/2016 Rigid-Body Transforms l Goal: object coordinates  world coordinates l Idea: use only transformations that preserve the shape of the object –Rigid-body or Euclidean transforms –Includes rotation, translation, and scale l To reiterate: we will represent points as column vectors:

49 David Luebke2/16/2016 Vectors and Matrices l Vector algebra operations can be expressed in this matrix form –Dot product: –Cross product: n Note: use right-hand rule!

50 David Luebke2/16/2016 Translations l For convenience we usually describe objects in relation to their own coordinate system –Solar system example l We can translate or move points to a new position by adding offsets to their coordinates: –Note that this translates all points uniformly

51 David Luebke2/16/2016 3-D Rotations l Rotations in 2-D are easy: l 3-D is more complicated –Need to specify an axis of rotation –Common pedagogy: express rotation about this axis as the composition of canonical rotations n Canonical rotations: rotation about X-axis, Y-axis, Z-axis

52 David Luebke2/16/2016 3-D Rotations l Basic idea: –Using rotations about X, Y, Z axes, rotate model until desired axis of rotation coincides with Z-axis –Perform rotation in the X-Y plane (i.e., about Z-axis) –Reverse the initial rotations to get back into the initial frame of reference l Objections: –Difficult & error prone –Ambiguous: several combinations about the canonical axis give the same result –For a different approach, see McMillan’s lecture 12

53 David Luebke2/16/2016 The End l Next: Basic OpenGL


Download ppt "David Luebke2/16/2016 CS 551 / 645: Introductory Computer Graphics Mathematical Foundations The Rendering Pipeline."

Similar presentations


Ads by Google