INFOGR – Computer Graphics J. Bikker - April-July 2016 - Lecture 8: “Engine Fundamentals” Welcome!
Today’s Agenda: Rendering Overview Matrices Transforms
INFOGR – Lecture 8 – “Engine Fundamentals” Rendering Topics covered so far: Basics: Rasters Vectors Color representation Ray tracing: Light transport Camera setup Textures Shading: N dot L Distance attenuation Pure specular
INFOGR – Lecture 8 – “Engine Fundamentals” Rendering Animation, culling, tessellation, ... Rendering – Functional overview meshes Transform 1. Transform: translating / rotating / scaling meshes vertices 2. Project: Project calculating 2D screen positions vertices 3. Rasterize: determining affected pixels Rasterize 4. Shade: fragment positions calculate color per affected pixel Shade pixels Postprocessing
INFOGR – Lecture 8 – “Engine Fundamentals” Rendering Rendering – Data overview
INFOGR – Lecture 8 – “Engine Fundamentals” Rendering Rendering – Data Overview camera world 𝑈 𝑑𝑏𝑛𝑓𝑠𝑏 𝑈 𝑐𝑣𝑧 𝑈 𝑑𝑏𝑠1 𝑈 𝑞𝑚𝑏𝑜𝑓1 𝑈 𝑑𝑏𝑠2 𝑈 𝑞𝑚𝑏𝑜𝑓2 buggy car car plane plane wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel dude turret turret dude dude
INFOGR – Lecture 8 – “Engine Fundamentals” Rendering Rendering – Data Overview Objects are organized in a hierarchy: the scenegraph . In this hierarchy, objects have translations and orientations relative to their parent node. Relative translations and orientations are specified using matrices. Mesh vertices are defined in a coordinate system known as object space .
INFOGR – Lecture 8 – “Engine Fundamentals” Rendering Rendering – Data Overview vertices, transforms Transform Transform takes our meshes from camera transform object space (3D) to camera space vertices (3D). Project Project takes the vertex data from camera space (3D) to screen space vertices (2D). connectivity data Rasterize fragment positions textures, shaders, lights Shade pixels screen buffers
INFOGR – Lecture 8 – “Engine Fundamentals” Rendering Rendering – Data Overview The screen is represented by (at least) two buffers:
INFOGR – Lecture 8 – “Engine Fundamentals” Rendering Rendering – Components Scenegraph Culling Lecture 11 Vertex transform pipeline Matrices to convert from one space to another Lecture 8 Perspective Lecture 9 Rasterization Interpolation Clipping Lecture 11 Depth sorting: z-buffer Lecture 11 Shading Light / material interaction P2 Complex materials P3
Today’s Agenda: Rendering Overview Matrices Transforms
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Bases in ℝ 2 and ℝ 3 Recall: Two linearly independent vectors form a base. 𝑤 We can reach any point in using: 𝑏 = λ 1 𝑣 + λ 2 𝑤 If 𝑣 and 𝑤 are perpendicular unit vectors, the base is orthonormal . The Cartesian coordinate system is an example of this, with 𝑣 = (1,0) and 𝑤 = (0,1) . By manipulating 𝑣 and 𝑤, we can create a ‘coordinate system’ within a coordinate system. 𝑣
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Bases in ℝ 2 and ℝ 3 𝑥 This extends naturally to ℝ 3 : Three vectors, 𝑣 , 𝑤 and 𝑥 allow us to reach any point in 3D space; y 𝑏 =λ 1 𝑣 + λ 2 𝑤 + λ 3 𝑥 Again, manipulating 𝑣 , 𝑤 and 𝑥 changes where coordinates specified as (λ 1, λ 2 , λ 3 ) end up. x 𝑣 z 𝑤
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Matrices A vector is an ordered set of d scalar values (i.e., a d- tuple): 𝑤 1 𝑤 2 𝑤 = or (𝑤 1 , 𝑤 2 , 𝑤 3 ) or … 𝑤 3 A 𝑛 × 𝑜 matrix is an array of 𝑛 ∙ 𝑜 scalar values, sorted in 𝑛 rows and 𝑜 columns: 𝑁 = 𝑏 11 𝑏 12 𝑏 21 𝑏 22 The elements 𝑏 𝑗𝑘 are referred to as the coefficients of the matrix (or elements, entries). Note that here 𝑗 is the row; 𝑘 is the column.
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Terminology – Special Matrices A diagonal matrix is a matrix for which all elements a ij are zero if 𝑗 ≠ 𝑘. An identity matrix is a diagonal matrix where each element 𝑏 𝑗𝑗 = 1. The zero matrix contains only zeroes. 1.5 0 0 1 0 0 0 0 0 𝐵 = 𝐵 = 𝐵 = 0 0.99 0 0 1 0 0 0 0 0 0 3.14 0 0 1 0 0 0 x y z Before we continue, what is a matrix? Just a group of numbers; In graphics: often a representation of a coordinate system.
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Matrices - Operations Matrix addition is defined as: 𝐵 = 𝐶 + 𝐷 , with: c 𝑗𝑘 = 𝑏 𝑗𝑘 + 𝑐 𝑗𝑘 Note that addition is only defined for matrices with the same dimensions. Example: 1 0 1 + 2 2 4 = 3 2 0 4 4 5 Subtraction works the same.
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Matrices - Operations Multiplying a matrix with a scalar is defined as follows: 𝐵 = λ𝐶 , with: a 𝑗𝑘 = λ𝑐 𝑗𝑘 Example: 2 1 0 1 = 2 0 0 0 2
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Matrices - Operations Multiplying a matrix (dimensions 𝑥 𝐵 × ℎ 𝐵 ) with another matrix (dimensions 𝑥 𝐶 × ℎ 𝐶 ) : 𝑥 𝐵 𝐷 = 𝐵𝐶 , with: 𝑑 𝑗𝑘 = 𝑏 𝑗𝑙 𝑐 𝑙𝑘 3 𝑙=1 𝑑 11 = 𝑏 1𝑙 𝑐 𝑙1 = 2 ∗ 1 + 6 ∗ 2 + 1 ∗ 3 = 17 Example: 𝑙=1 3 1 4 𝑑 21 = 𝑏 2𝑙 𝑐 𝑙1 = 5 ∗ 1 + 2 ∗ 2 + 4 ∗ 3 = 21 2 6 1 17 44 = 2 5 5 2 4 21 54 𝑙=1 3 3 6 𝑑 12 = 𝑏 1𝑙 𝑐 𝑙2 = 2 ∗ 4 + 6 ∗ 5 + 1 ∗ 6 = 44 Note the dimensions of the resulting 3 𝑙=1 matrix: ℎ 𝐵 × 𝑥 𝐶 . 𝑑 22 = 𝑏 2𝑙 𝑐 𝑙2 = 5 ∗ 4 + 2 ∗ 5 + 4 ∗ 6 = 54 𝑙=1 Matrix multiplication is only defined if ℎ 𝐵 = 𝑥 𝐶 (i.e., the width of B is equal to the height of A) .
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Matrices - Operations Some properties: Matrix multiplication is distributive over Doing matrix multiplication manually: addition: 1 4 𝐵 𝐶 + 𝐷 = 𝐵𝐶 + 𝐵𝐷 2 5 𝐵 + 𝐶 𝐷 = 𝐵𝐷 + 𝐶𝐷 3 6 …and associative: 2 6 1 ? ? 5 2 4 ? ? 𝐵𝐶 𝐷 = 𝐵 𝐶𝐷 However, matrix multiplication is not Note that each cell in the resulting matrix commutative, i.e., in general: is essentially the dot product of a row and a column. 𝐵𝐶 ≠ 𝐶𝐵
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Matrices - Operations Multiplying by the zero matrix yields the Doing matrix multiplication manually: zero matrix: 1 4 0𝐵 = 𝐵0 = 0 2 5 3 6 Multiplying by the identity matrix yields the original matrix: 2 6 1 ? ? 5 2 4 ? ? 𝐽𝐵 = 𝐵𝐽 = 𝐵 𝑏 𝑑 𝑐 𝑒 𝑏 𝑑 1 0 𝑐 𝑒 0 1
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Matrices - Operations The transpose 𝐵 𝑈 of an 𝑛 × 𝑜 matrix is an 𝑜 × 𝑛 matrix that is obtained by interchanging rows and columns: 𝑏 𝑗𝑘 becomes 𝑏 𝑘𝑗 for all 𝑗, 𝑘 : 𝑏 11 𝑏 12 𝑏 13 𝑏 11 𝑏 21 𝑏 31 𝐵 𝑈 = 𝑏 21 𝑏 22 𝑏 23 𝑏 12 𝑏 22 𝑏 32 𝐵 = 𝑏 31 𝑏 32 𝑏 33 𝑏 13 𝑏 23 𝑏 33 The transpose of the product of two matrices is: 𝐵𝐶 𝑈 = 𝐶 𝑈 𝐵 𝑈
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Matrices - Operations The inverse of a matrix 𝐵 is a matrix 𝐵 -1 such that 𝐵𝐵 −1 = 𝐵 −1 A = 𝐽 Note: only square matrix possibly have an inverse.
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Matrices - Operations We can multiply a d -dimensional vector by an 𝑛 × 𝑒 matrix: Note: 𝑏 11 ⋯ 𝑏 1𝑒 𝑤 1 𝑏 11 𝑤 1 + ⋯ + 𝑏 1𝑒 𝑤 𝑒 This is the same as matrix ⋯ + ⋯ + ⋯ ⋮ ⋱ ⋮ ⋮ = concatenation; the vector is 𝑏 𝑛1 𝑤 1 + ⋯ + 𝑏 𝑛𝑒 𝑤 𝑒 𝑏 𝑛1 ⋯ 𝑏 𝑛𝑒 𝑤 𝑒 simply an 𝑛 × 1 matrix. Example: multiply a 3D vector by a 3x3 matrix: 𝑏 11 𝑏 12 𝑏 13 𝑦 𝑏 11 𝑦 + 𝑏 12 𝑧 + 𝑏 13 𝑨 𝑏 21 𝑏 22 𝑏 23 𝑏 21 𝑦 + 𝑏 22 𝑧 + 𝑏 23 𝑨 𝑧 = 𝑏 31 𝑦 + 𝑏 32 𝑧 + 𝑏 33 𝑨 𝑏 31 𝑏 32 𝑏 33 𝑨
INFOGR – Lecture 8 – “Engine Fundamentals” Matrices Matrices - Operations We can multiply a d -dimensional vector by an 𝑛 × 𝑒 matrix: Note: 𝑏 11 ⋯ 𝑏 1𝑒 𝑤 1 𝑏 11 𝑤 1 + ⋯ + 𝑏 1𝑒 𝑤 𝑒 This is the same as matrix ⋯ + ⋯ + ⋯ ⋮ ⋱ ⋮ ⋮ = concatenation; the vector is 𝑏 𝑛1 𝑤 1 + ⋯ + 𝑏 𝑛𝑒 𝑤 𝑒 𝑏 𝑛1 ⋯ 𝑏 𝑛𝑒 𝑤 𝑒 simply an 𝑛 × 1 matrix. Example: multiply a 3D vector by a 3x3 matrix: 𝑣 𝑦 𝑤 𝑦 𝑥 𝑦 𝑣 𝑦 𝑦 + 𝑤 𝑦 𝑧 + 𝑥 𝑦 𝑨 𝑦 𝑣 𝑧 𝑤 𝑧 𝑥 𝑧 𝑣 𝑧 𝑦 + 𝑤 𝑧 𝑧 + 𝑥 𝑧 𝑨 𝑧 = = 𝑦𝑣 + 𝑧 𝑤 + 𝑨𝑥 𝑣 𝑨 𝑤 𝑨 𝑥 𝑨 𝑨 𝑣 𝑨 𝑦 + 𝑤 𝑨 𝑧 + 𝑥 𝑨 𝑨 u v w
Recommend
More recommend