We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14
Rasterization algorithms
CS 248 - Introduction to Computer Graphics
Autumn Quarter, 2008 Marc Levoy Lecture notes for Thursday, October 9 (second half of class) Table of contents: Overview of 3D rendering pipeline Line drawing Assumptions 1. Brute force algorithm 2. DDA algorithm 3. Bresenham algorithm 4. What do real workstations use? 5. Polygon scan conversion Assumptions 1. Algorithm 2. Which pixels to ll? 3. An ecient algorithm for triangles 4. Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 1 of 14 Thursday 26 December 2013 11:05 AM Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 2 of 14 Thursday 26 December 2013 11:05 AM Except for assumptions 1 through 4 immediately below, the following section on line drawing was skipped in class. It is included here for completeness. You will not be held responsible for it on exams. Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 3 of 14 Thursday 26 December 2013 11:05 AM Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 4 of 14 Thursday 26 December 2013 11:05 AM Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 5 of 14 Thursday 26 December 2013 11:05 AM Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 6 of 14 Thursday 26 December 2013 11:05 AM Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 7 of 14 Thursday 26 December 2013 11:05 AM The algorithm that follows, which is taken from section 3.6 in the textbook, handles self-intersecting (e.g. bow-tie) or degenerate polygons naturally, even polygons with holes. As mentioned in handout #7, you will need to handle the rst two types in project #2, but not the third. By the way, handling these cases by decomposing them into triangles is not allowed, at least for the project. Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 8 of 14 Thursday 26 December 2013 11:05 AM Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 9 of 14 Thursday 26 December 2013 11:05 AM Note that steps 3.2 (remove edges) and 3.2.5 (sort the active edge table) should be performed before step 3.3 (ll the scanline), despite the physical order in which they appear in the list above. Re-sorting the active edge table seems to happen frequently, but it typically isn't expensive. In particular, if you have introduced a new edge in step 3.1, then you will need to move it to its correct position in the table. However, this is only done at events, in fact only once per edge of the polygon. Even if you have not introduced an edge, you must look through the table for edges that may be out of order because they have crossed after the x increments of the previous step 3.5; these edges will need to be swapped in the table. This check must be done on every scanline, not just at events, but in the vast majority of cases no swapping will be necessary, so the cost of this check is low. As I mentioned in class, manipulations to the edge tables typically represent a small fraction of the cost of a rasterizer. Most of the time is spent in step 3.3, lling pixels. By the way, the suggested code for updating the X-coordinate in step 3.5 is an integer-only solution, lifted from Bresenhham's algorithm. If you're willing to use oating-point arithmetic, then the increment becomes just the (oating-point) slope, with no if-test necessary. Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 10 of 14 Thursday 26 December 2013 11:05 AM In general, a polygon rasterizer should ll only and all sample positions that fall inside polygon edges. In previous versions of project #2, we also required students to rasterize their polygons such that they meshed perfectly, i.e. with no holes or doubly-drawn pixels. To satisfy this requirement, care must be taken when sample positions coincide with polygon edges or vertices, as discussed above. This year, we do not require this. Thus, the only rule you must obey in your project this year is that all sample positions that are strictly inside a primitive, i.e. not coincident with a vertex or edge, should be lled, and all sample positions that are strictly outside a primitive should not be lled. This means that in the sliver polygon above, you should not ll any samples in the second column, immediately above the word "gap". Whether you ll the sample at the leftmost vertex is up to you. After anti-aliasing, assuming you use enough Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 11 of 14 Thursday 26 December 2013 11:05 AM supersamples, the left tip of the polygon should look approximately the same whether you do or not. In particular, it should like like a knife-edge thinner than a pixel. This apparent thinness arises from the pixel under the vertex having a color that is a blend of the polygon's color and the background color. Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 12 of 14 Thursday 26 December 2013 11:05 AM The algorithm described in section II is very general, and it's useful from a didactic standpoint to see how a general plane-sweep algorithm works, but what do real graphics cards use? The answer is proprietary, and it may vary among manufacturers, but at the least they always decompose polygons into triangles. Shown above is one Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 13 of 14 Thursday 26 December 2013 11:05 AM algorithm for fast rasterization of triangles. A dierent algorithm is: "Triangle scan conversion using 2d homogeneous coordinates", by Marc Olano and Trey Greer, in Proc. ACM SIGGRAPH/Eurographics Workshop on Graphics Hardware, 1997. Since I didn't cover these algorithms in class, I'm not holding you responsible for them. [email protected] Copyright 2008 Marc Levoy Last update: October 14, 2008 06:36:51 PM Rasterization algorithms http://graphics.stanford.edu/courses/cs248-08/scan/scan... 14 of 14 Thursday 26 December 2013 11:05 AM