Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 551 / 645: Introductory Computer Graphics

Similar presentations


Presentation on theme: "CS 551 / 645: Introductory Computer Graphics"— Presentation transcript:

1 CS 551 / 645: Introductory Computer Graphics
Mathematical Foundations The Rendering Pipeline David Luebke /23/2019

2 Administrivia Sorry about the canceled class
OpenGL text: v1.1 or v1.2? Teddy link fixed Go over Assignment 1 David Luebke /23/2019

3 XForms Intro Xforms: a toolkit for easily building Graphical User Interfaces, or GUIs See 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. Quick tour now You’ll learn the details yourself in Assignment 1 David Luebke /23/2019

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

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

6 Trigonometry Sine: “opposite over hypotenuse”
Cosine: “adjacent over hypotenuse” Tangent: “opposite over adjacent” Unit circle definitions: sin () = x cos () = y tan () = x/y Etc… (x, y) David Luebke /23/2019

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

8 Vector Spaces Two types of elements: Supports two operations:
Scalars (real numbers): a, b, g, d, … Vectors (n-tuples): u, v, w, … Supports two operations: Addition operation u + v, with: Identity 0 v + 0 = v Inverse - v + (-v) = 0 Scalar multiplication: Distributive rule: a(u + v) = a(u) + a(v) (a + b)u = au + bu David Luebke /23/2019

9 Vector Spaces A linear combination of vectors results in a new vector:
v = a1v1 + a2v2 + … + anvn If the only set of scalars such that a1v1 + a2v2 + … + anvn = 0 is a1 = a2 = … = a3 = 0 then we say the vectors are linearly independent The dimension of a space is the greatest number of linearly independent vectors possible in a vector set For a vector space of dimension n, any set of n linearly independent vectors form a basis David Luebke /23/2019

10 Vector Spaces: A Familiar Example
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”: y x u v u+v David Luebke /23/2019

11 Vector Spaces: Basis Vectors
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 Draw example on the board Note that a given vector v will have different coordinates for different bases David Luebke /23/2019

12 Vectors And Points We commonly use vectors to represent:
Points in space (i.e., location) Displacements from point to point Direction (i.e., orientation) 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 David Luebke /23/2019

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

14 Affine Spaces 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 Thus the common practice of representing points as vectors with coordinates (see FvD) Analogous to equating pointers & integers in C Be careful to avoid nonsensical operations David Luebke /23/2019

15 Affine Lines: An Aside Parametric representation of a line with a direction vector d and a point P1 on the line: P(a) = Porigin + ad Restricting 0  a produces a ray Setting d to P - Q and restricting 0  a  1 produces a line segment between P and Q David Luebke /23/2019

16 Dot Product The dot product or, more generally, inner product of two vectors is a scalar: v1 • v2 = x1x2 + y1y2 + z1z2 (in 3D) 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 v θ u David Luebke /23/2019

17 Cross Product The cross product or vector product of two vectors is a vector: The cross product of two vectors is orthogonal to both Right-hand rule dictates direction of cross product David Luebke /23/2019

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

19 Matrices By convention, matrix element Mrc is located at row r and column c: By (OpenGL) convention, vectors are columns: David Luebke /23/2019

20 Matrices Matrix-vector multiplication applies a linear transformation to a vector: Recall how to do matrix multiplication David Luebke /23/2019

21 Matrix Transformations
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 Some (not all) matrices have an inverse: David Luebke /23/2019

22 The Rendering Pipeline: A Whirlwind Tour
Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display David Luebke /23/2019

23 Model & Camera Parameters
The Display You Know Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display David Luebke /23/2019

24 The Framebuffer You Know
Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display David Luebke /23/2019

25 The Rendering Pipeline
Why do we call it a pipeline? Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display David Luebke /23/2019

26 2-D Rendering: Rasterization (Coming Soon)
Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display David Luebke /23/2019

27 The Rendering Pipeline: 3-D
Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display David Luebke /23/2019

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

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

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

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

32 Rendering: Transformations
Viewing transform Rotate & translate the world to lie directly in front of the camera Typically place camera at origin Typically looking down -Z axis World coordinates  view coordinates David Luebke /23/2019

33 Rendering: Transformations
Projection transform Apply perspective foreshortening Distant = small: the pinhole camera model View coordinates  screen coordinates David Luebke /23/2019

34 Rendering: Transformations
All these transformations involve shifting coordinate systems (i.e., basis sets) That’s what matrices do… Represent coordinates as vectors, transforms as matrices Multiply matrices = concatenate transforms! ú û ù ê ë é - = Y X q cos sin David Luebke /23/2019

35 Rendering: Transformations
Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector Denoted [x, y, z, w]T 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 Transformations are 4x4 matrices Why? To handle translation and projection David Luebke /23/2019

36 Rendering: Transformations
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 See Chapter 3 of the OpenGL book David Luebke /23/2019

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

38 Rendering: Lighting 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 Interactive graphics (e.g., hardware) does only local illumination at run time David Luebke /23/2019

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

40 Rendering: Clipping Clipping a 3-D primitive returns its intersection with the view frustum: See Foley & van Dam section 19.1 David Luebke /23/2019

41 Rendering: Clipping Clipping is tricky! In: 3 vertices Out: 6 vertices
In: 1 polygon Out: 2 polygons Clip David Luebke /23/2019

42 The Rendering Pipeline: 3-D
Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display David Luebke /23/2019

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

44 Modeling: The Scene Graph
The scene graph captures transformations and object-object relationships in a DAG Objects in black; blue arrows indicate instancing and each have a matrix Robot Head Body Mouth Eye Leg Trunk Arm David Luebke /23/2019

45 Modeling: The Scene Graph
Traverse the scene graph in depth-first order, concatenating transformations Maintain a matrix stack of transformations Robot Visited Head Body Unvisited Mouth Eye Leg Trunk Arm Matrix Stack Active Foot David Luebke /23/2019

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

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

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

49 Vectors and Matrices Vector algebra operations can be expressed in this matrix form Dot product: Cross product: Note: use right-hand rule! David Luebke /23/2019

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

51 3-D Rotations Rotations in 2-D are easy: 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 Canonical rotations: rotation about X-axis, Y-axis, Z-axis David Luebke /23/2019

52 3-D Rotations Basic idea: Objections:
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 Objections: Difficult & error prone Ambiguous: several combinations about the canonical axis give the same result For a different approach, see McMillan’s lecture 12 David Luebke /23/2019

53 The End Next: Basic OpenGL David Luebke /23/2019


Download ppt "CS 551 / 645: Introductory Computer Graphics"

Similar presentations


Ads by Google