Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CS 551 / 645: Introductory Computer Graphics David Luebke [email protected] http://www.cs.virginia.edu/~cs551 David Luebke 7/5/2017 Administrivia DROP deadline tomorrow – I’ll try to have tests graded by tomorrow afternoon – I’ll try to have Assignment 3 graded by then too David Luebke 7/5/2017 Recap: Transformation Matrices Modeling transforms: object world – Translation – Rotation – Scale Viewing transforms: world camera – Translation – Rotation Projection transforms: camera screen – Perspective or orthographic projeciton matrix – Viewport transformation David Luebke 7/5/2017 3-D Clipping Sometime before actually drawing on the screen, we have to clip (Why?) – Safety: avoid writing pixels that aren’t there – Efficiency: save computation cost of rasterizing primitives outside the field of view Can we transform to screen coordinates first, then clip in 2-D? – Correctness: shouldn’t draw objects behind viewer (what will an object with negative z coordinates do in our perspective matrix?) (draw it…) David Luebke 7/5/2017 Perspective Projection Recall the matrix: x 1 y 0 z 0 z d 0 0 0 1 0 0 1 0 1d 0 x 0 y 0 z 0 1 Or, in 3-D coordinates: x , z d David Luebke y , d zd 7/5/2017 Clipping Under Perspective Problem: after multiplying by a perspective matrix and performing the homogeneous divide, a point at (-8, -2, -10) looks the same as a point at (8, 2, 10). Solution A: clip before multiplying the point by the projection matrix – I.e., clip in camera coordinates Solution B: clip before the homogeneous divide – I.e., clip in homogeneous coordinates David Luebke 7/5/2017 Clipping Under Perspective We will talk first about solution A: Clipped world coordinates Clip against view volume 3-D world coordinate primitives David Luebke Canonical screen coordinates Apply projection matrix and homogeneous divide Transform into viewport for 2-D display 2-D device coordinates 7/5/2017 Perspective Projection Given that we’re projecting to a rectangular viewport, to what volume of space should we clip? – Under perspective projection? David Luebke 7/5/2017 Perspective Projection Answer: a frustum or truncated pyramid – In viewing coordinates: x or y z David Luebke 7/5/2017 Perspective Projection The viewing frustum consists of six planes The Sutherland-Cohen algorithm (clipping polygons to a region one plane at a time) generalizes to 3-D – Clip polygons against six planes of view frustum – So what’s the problem? David Luebke 7/5/2017 Perspective Projection The viewing frustum consists of six planes The Sutherland-Cohen algorithm (clipping polygons to a region one plane at a time) generalizes to 3-D – Clip polygons against six planes of view frustum – So what’s the problem? The problem: clipping a line segment to an arbitrary plane is relatively expensive – Dot products and such David Luebke 7/5/2017 Perspective Projection In fact, for simplicity we prefer to use the canonical view frustum: x or y 1 Front or hither plane Back or yon plane -1 z Why is this going to be simpler? -1 David Luebke 7/5/2017 Perspective Projection In fact, for simplicity we prefer to use the canonical view frustum: x or y 1 Front or hither plane Back or yon plane -1 z Why is the yon plane at z = -1, not z = 1? -1 David Luebke 7/5/2017 Clipping Under Perspective So we have to refine our pipeline model: Apply normalizing transformation 3-D world coordinate primitives Clip against canonical view volume projection matrix; homogeneous divide Transform into viewport for 2-D display 2-D device coordinates – Note that this model forces us to separate projection from modeling & viewing transforms David Luebke 7/5/2017 Clipping Homogeneous Coords Another option is to clip the homogeneous coordinates directly. – This allows us to clip after perspective projection: – What are the advantages? Apply projection matrix 3-D world coordinate primitives David Luebke Clip against view volume Homogeneous divide Transform into viewport for 2-D display 2-D device coordinates 7/5/2017 Clipping Homogeneous Coords Other advantages: – Can transform the canonical view volume for perspective projections to the canonical view volume for parallel projections Clip in the latter (only works in homogeneous coords) Allows an optimized (hardware) implementation – Some primitives will have w 1 David Luebke For example, polygons that result from tesselating splines Without clipping in homogeneous coords, must perform divide twice on such primitives 7/5/2017 Clipping: The Real World In the Real World, a common shortcut is: Clip against hither and yon planes David Luebke Projection matrix; homogeneous divide Transform into screen coordinates Clip in 2-D screen coordinates 7/5/2017