3D Graphics Pipeline 4 The rasterization step scan converts the object into pixels
Implicit Lines 5 Implicit equation in two dimensions: Points with f(x,y) = 0 are on the line Points with f(x,y) != 0 are not on the line
Implicit Lines 6 The implicit form of the slope ‐ intercept equation:
7 The slope ‐ intercept form can not represent some lines, such as x = 0. A more general implicit form is more useful: y = mx + b or The implicit line through two points (x 0,y 0 ) and (x 1,y 1 ):
Example 8 What is the implicit equation of this line?
Example 9 Solution 1: ‐ 2X+4Y=0 Solution 2: 2X ‐ 4Y=0 What’s the lesson here? k f(x,y) = 0 is the same line, for any value of k
Example 10 The value of f(x,y) = ‐ 2x +4y tells us which side of the line a point (x,y) is on
The Rasterization Problem 11 Primitives map to discrete display space
Solution 12 Selection of discrete representation values
Scan converting lines 13 Characterizing the problem: 2 cases Move vertical scanline from x 0 to x n Move horizontal scanline from bottom to top dot: center of pixel
14 Exactly one pixel per column: Fewer: disconnected More: too thick Only discuss m≤1 case The strategy Pick pixels closest to endpoints Select in between pixels “closest”to ideal line Objective: To minimize the required calculations.
20 Decision function: Q(x,y)=y-mx-b above line L: +; on: 0; below: - F(x,y)=ax+by+c=0 (implicit equation of the line) if F(x i +1, y i +1/2)<0, M lies above the line, chose E if F(x i +1, y i +1/2)>0, M lies below the line, chose NE
21 Calculating the decision function Initial condition: (x0,y0): the point on the line
22 Problem: Complete computation of d along the line Solution: incremental calculation of d i
28 Scan Line Algorithm Compute the bounding pixels Fill the spans
29 Scan Line Algorithm Find the intersections of current scan line with all edges of the polygon. Sort the intersections by increasing x coordinate. Fill in pixels that lie between pairs of intersections that lie interior to the polygon using the odd/even parity rule. Parity: even, change parity once encounter an edge Special parity: no change of the parity (draw 1 pixel)
Filling polygons: scan line algorithm 30 http://www.cs.rit.edu/~icss571/filling/example.html
Edge table 31 Initializing the all_edges table: determine how the polygon's vertices are related Each adjacent set of vertices defines an edge. For each edge, we need to keep: The minimum y value of the 2 vertices: y min The maximum y value of the 2 vertices: y max The x value associated with the minimum y value: x val 1/The slope of the edge:1/m (?)
Global edge table 32 Initializing the Global Edge Table (GET): keep track of the edges that are still needed to complete the polygon. place the edges with m≠0 (?) be inserted with edges grouped by increasing minimum y values and further by x values
Active Edge Table 33 Initializing Parity even since no edges have been crossed yet. Initializing the Scan-Line is equal to the lowest y value for all of the global edges.(10) Initializing the Active Edge Table (AET) keep track of the ordered edges that are intersected by the current scan-line.
34 Scanline = 10: at x=10, parity = odd. draw pixels left to x=22, parity = even. at x=28, draw a pixel (the special parity case)
Filling the polygon 35 Scanline=11: update x = x +1/m sort by x val at x=10, parity = odd. draw pixels left to x=23, parity = even. at x=27, parity = odd. draw pixels left to x=28, parity = even.
36 Scanline+=1, until y max is equal to the next scan-line Scanline = 15: at x=10, parity = odd. draw pixels left to x=22, parity = even. at x=27, parity = odd. draw pixels left to x=28, parity = even.
37 Scanline++ (16) remove the edges if ymax=scanline from the active edge table (for the edges at indices 0, 2, and 3) update the x values for all remaining edges in the active edge table
38 Now add the edges from the global edge table to the active edge table since y min =scanline. reorder
39 Scanline=17: update = x +1/m, sort by x va at x=12, parity = odd. draw pixels left to x=20, parity = even. l
40 Scanline ++, until scanline=19 at x=15, parity = odd. draw pixels left to x=18, parity = even.
41 scanline++ remove the edges if y max =scanline from the active edge table (for the edges at indices 0, 1) add the edges from the global edge table to the active edge table if y min =scanline. Iterate until both tables are empty.
42 Demo Algorithm 1. Initiate the GET, scanline, AET 2. Draw the pixels based on AET and the parity 3. Scanline++ 4. Remove the edges from AET is scanline=ymax,terminate if both AET and GET are empty 5. Update X values 6. Add edges to AET if GET is not empty 7. Reorder AET 8. Goto step 2.
Problem 43 Antialiasing by Area Averaging Color multiple pixels for each x depending on coverage by ideal line
44 Aliasing problems can be serious for polygons Jaggedness of edges Small polygons neglected Need compositing so color of one polygon does not totally determine color of pixel All three polygons should contribute to color
Any suggestions 54 to handle the non-trival cases Find the intersecting points
Algorithm 55 1. Compute the outcodes for the two vertices 2. Test for trivial acceptance or rejection 3. Select a vertex for which outcode is not zero 1. There will always be one 4. Select the first nonzero bit in the outcode to define the boundary against which the line segment will be clipped 5. Compute the intersection and replace the vertex with the intersection point 6. Compute the outcode for the new point and iterate
Advantages/Extension 62 Easily extended to 3 dimensions by adding two bits to the outcode for the z axis. Calculations then reduce to intersection of line with plane Very efficient when most segments can either be trivially accepted or trivially rejected http://www.cs.princeton.edu/%7Emin/cs426/jar/clip.html
86 Lots of fragments might map to the same pixel location How to track their z ‐ values? Solution: z ‐ buffer (2D buffer, same size as image)
Z ‐ buffer Algorithm 87 Let CB be color buffer, ZB be z ‐ buffer Initialize z ‐ buffer contents to 1.0 (far away) For each triangle T Rasterize T to generate fragments For each fragment F with screen position (x,y,z) and color value C If ( z < ZB[x,y] ) then Update color: CB[x,y] = C Update depth: ZB[x,y] = z
Z ‐ buffer Algorithm Properties 88 What makes this method nice? simple (faciliates hardware implementation) handles intersections handles cycles draw opaque polygons in any order