Scan Conversion of Polygons Dr. Scott Schaefer
Drawing Rectangles Which pixels should be filled? /8
Drawing Rectangles Is this correct? /8
Drawing Rectangles What if two rectangles overlap? 4/8
Drawing Rectangles Is this correct? /8
Drawing Rectangles Is this correct? Overlap!!! /8
Drawing Rectangles Solution: Exclude pixels on top and right /8
Drawing Rectangles Artifacts are possible 8/8
General Polygons Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges Don t fill top/right Edges may NOT match with line drawing algo 9/8
General Polygons Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges Use coherence to speed up Don t fill top/right Edges may NOT match with line drawing algo /8
General Polygons Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges Use coherence to speed up Edges intersection one scan line are mostly same as those intersecting previous scan line /8
General Polygons Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges Use coherence to speed up The x-value of an intersection with one scan line is close to the intersection with the previous one /8
General Polygons Data Structures Edge: Edge maxy currentx xincr ( xi, yi ) ( xi, yi ) maxy: currentx: xincr: max( y i, y i ) xi, yi min( y xi, otherwise x y i i x y i i i, y i ) /8
General Polygons Data Structures Edge: Edge maxy currentx xincr ( xi, yi ) ( xi, yi ) maxy: currentx: xincr: max( y i, y i ) xi, yi min( y xi, otherwise x y i i x y i i i, y i ) Horizontal edges will not be used!!! 4/8
Scan Lines General Polygons Data Structures Active Edge Table: 4 Store a linked-list per scanline. Insert edges into table at scan-line associated with lowest end-point. Edges /8
General Polygons Data Structures Active Edge List: Edges List of all edges intersecting current scan-line sorted by their x-values /8
General Polygons Algorithm line = While (line < height ) Add edges to Active Edge List from Active Edge Table starting at line Remove edges that end at line Fill pixels Increment x-values on edges in Active Edge List Increment line /8
General Polygons Example Active Edge Table 4 Active Edge List 4 C B D G F E A 4 8/8
General Polygons Example Active Edge Table 4 Active Edge List 4 C B D G F E A 4 9/8
General Polygons Example Active Edge Table 4 BC Active Edge List 4 C B D G F E A 4 /8
General Polygons Example Active Edge Table 4 BC CD Active Edge List 4 C B D G F E A 4 /8
General Polygons Example Active Edge Table 4 BC CD ED Active Edge List 4 C B D G F E A 4 /8
General Polygons Example Active Edge Table 4 BC CD ED Active Edge List 4 C B D G F E A 4 /8
General Polygons Example Active Edge Table 4 BC CD FG ED Active Edge List 4 C B D G F E A 4 4/8
General Polygons Example Active Edge Table 4 BC CD FG ED AG Active Edge List 4 C B D G F E A 4 /8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List AG 4 C B D G F E A 4 /8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List AG FG ED 4 C B D G F E A 4 /8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List AG FG ED 4 C B D G F E A 4 8/8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List AG 4 FG ED 4 C B D G F E A 4 9/8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List AG 4 FG ED 4 C B D G F E A 4 /8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List AG FG ED 4 C B D G F E A 4 /8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List ED 4 C B D G F E A 4 /8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List ED 4 C B D G F E A 4 /8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List ED 4 C B D G F E A 4 4/8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List ED 4 C B D G F E A 4 /8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List ED CD 4 C B D G F E A 4 /8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List ED CD 4 C B D G F E A 4 /8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List CD 4 C B D G F E A 4 8/8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List CD 4 C B D G F E A 4 9/8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List BC CD 4 C B D G F E A 4 4/8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List BC CD 4 C B D G F E A 4 4/8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List BC CD 4 C B D G F E A 4 4/8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List BC CD 4 C B D G F E A 4 4/8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List BC CD 4 C B D G F E A 4 44/8
General Polygons Example maxy currentx xincr Active Edge Table 4 BC CD FG ED AG Active Edge List BC CD 4 C B D G F E A 4 4/8
General Polygons Problems Sliver polygons may not be drawn correctly No simple solution Long, thin triangles cause problems Want triangles with good aspect ratio (close to equilateral) 4/8
Boundary Fill Start with drawn outline of a polygon and an interior point Recursively recolor outward from that point If neighbor different, then recolor and recur Everything within the boundary is changed to that color 4/8
Boundary Fill How to define a neighbor? 4-connected 8-connected 48/8
Boundary Fill Example 49/8
Boundary Fill Example /8
Boundary Fill Example /8
Boundary Fill Example /8
Boundary Fill Example /8
Boundary Fill Example 4/8
Flood Fill Start with a point Define color under that point as the interior color Recursively recolor outward from that point If neighbor is interior color, then recolor and recur Contiguous regions of the same color are recolored /8
Flood Fill Example /8
Flood Fill Example /8
Flood Fill Example 8/8
Flood Fill Example 9/8
Flood Fill Example /8
Flood Fill Example /8
Flood Fill Example /8
Flood Fill Example /8
Flood Fill Example 4/8
Flood Fill Example /8
Flood Fill Example /8
Flood Fill Example /8
Flood Fill Example 8/8
OpenGL: Drawing Polygons Lots of different primitives supported GPU only draws triangles OpenGL triangulates all polygons Problems with concave polygons! How data is passed to GPU makes a significant difference in speed GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUADS GL_QUAD_STRIP GL_POLYGON 9/8
Performance Nvidia Nvidia 88 GT GTX ATI Radeon HD 48 ATI Radeon HD 48 New Drivers Immediate Mode.... Display Lists 8.. 4. 49. Vertex Arrays.... Vertex Buffer Objects.. 4.. Frames per second displaying a 4, triangle model. CPU was an Intel Core or Core i 94. /8
Tile-Based Rasterization Screen /8
Tile-Based Rasterization /8
Tile-Based Rasterization /8
Tile-Based Rasterization 4/8
Tile-Based Rasterization Each thread draws polygon into local frame buffer Copies local frame buffer into global frame buffer when complete /8
Even More Parallelization /8
Even More Parallelization /8
Even More Parallelization 8/8
Point in Triangle ( x i, yi ) ( x, y) ( x i, yi ) x y i i x y x y i i x y 9/8
Even More Parallelization 8/8
Even More Parallelization Only need to check until first polygon hit 8/8