Jens Krüger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization 3D Rendering Praktikum: Shader Gallery The Rendering Pipeline
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group … what an „end user“ sees. The Rendering Pipeline …
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group The Rendering Pipeline … … in pictures
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Rendering pipeline Geometry subsystem Raster subsystem Objects in 3D world Color image 2D primitives
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Pixel Stage Vertex Stage User / DriverOverview Transform & Lighting Rasterizer Texturing Blending/Ops Texture 3 Texture 2 Texture 1 Texture 0
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Rendering pipeline Geometry subsystem Raster subsystem Objects in 3D world Color image 2D primitives 2D Object coordinates World coordinates Eye coordinates Modelling transform Viewing transform Normalizing transform Normalized (Clip-)coord. clipping affine Model-View-Transformation
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Transformations - - A transformation is like a function of a point - - Modeling: - - Define objects in „convenient“ coordinate systems - - Multiply-instantiated geometry - - Hierarchically defined linked figures - - Viewing: - - Window systems - - Virtual camera - - Perspective transformations
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Point representation - - Represent as row or column vector - - Affects the kind of matrices we can multiply with
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Transformation representation - - Represent 2D transformations by a 2x2 matrix - - If the point is a column vector - - If the point is a row vector
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Linear transformations - - Scaling - - Reflection s x = s y uniform scaling S
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Linear transformations - - Shearing - - Rotation around origin by a 1 R(90°)
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Affine transformations - - Affine transformations: parallelism is preserved, length & angles not - - All linear transformations can be written as matrix multiplication - - What about translation ? - - We want to write T Homogeneous coordinates!
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group General Camera Setup - - Look at: - - Position - - Orientation - - Frustum: - - Camera parameters - - Viewport: - - 2D coordinate system Look at FrustumFrustum ViewportViewport
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Camera look at - - Move camera C to origin Translate by –C - - Build orthonormal frame „right“R=DxU „zenith“U=RxD - - Adjust orientation Rotation [R,U,D] [X,Y,-Z] Right View direction Up
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Frustum (Perspective Projection) T t B b -f -n -z y
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Last Transformations - - After all the projections we have: - - Perspective division: - - Viewport transformation:
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Pixel Stage Vertex Stage User / DriverOverview Transform & Lighting Rasterizer Texturing Blending/Ops Texture 3 Texture 2 Texture 1 Texture 0
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Bresenham (Line Drawing)
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Getting to Bresenham … /********************************* * Input: * xP: x-value of the startpoint * yP: y-value of the startpoint * xQ: x-value of the endpoint * yQ: y-value of the endpoint *********************************/ function drawLine(int xP, int yP, int xQ, int yQ) { x = xP; y = yP; d = 0; m = (yQ - yP) / (xQ - xP) while(true) { // put the pixel on the screen putPixel(x, y); if(x == xQ) break; x++; d += m; if(d > 0.5) { y++; d--; } /********************************* * Input: * xP: x-value of the startpoint * yP: y-value of the startpoint * xQ: x-value of the endpoint * yQ: y-value of the endpoint *********************************/ function drawLine(int xP, int yP, int xQ, int yQ) { x = xP; y = yP; d = 0; m = (yQ - yP) / (xQ - xP) while(true) { // put the pixel on the screen putPixel(x, y); if(x == xQ) break; x++; d += m; if(d > 0.5) { y++; d--; } Problem: still floating point arithmetic Obersvation: m is rational d is rational
computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Bresenham … function drawLine(int xP, int yP, int xQ, int yQ) { x = xP; y = yP; D = 0; H = xQ - xP; c = 2 * H; M = 2 * (yQ - yP); while(true) { putPixel(x, y); if(x == xQ) break; x++; D += M; if(D > H) { y++; D -= c; } function drawLine(int xP, int yP, int xQ, int yQ) { x = xP; y = yP; D = 0; H = xQ - xP; c = 2 * H; M = 2 * (yQ - yP); while(true) { putPixel(x, y); if(x == xQ) break; x++; D += M; if(D > H) { y++; D -= c; } Introduce the following integer variables: