review
play

Review Line rasterization Scan Conversion Basic Incremental - PDF document

Utah School of Computing Spring 2013 Review Line rasterization Scan Conversion Basic Incremental Algorithm Digital Differential Analyzer Lecture Set 4 Rather than solve line equation at each pixel, use evaluation of line


  1. Utah School of Computing Spring 2013 Review • Line rasterization Scan Conversion – Basic Incremental Algorithm – Digital Differential Analyzer Lecture Set 4 • Rather than solve line equation at each pixel, use evaluation of line from previous pixel and CS5600 Computer Graphics slope to approximate line equation – Bresenham • Use integer arithmetic and midpoint Spring 2013 discriminator to test between two possible pixels (over vs. over-and-up) Rasterizing Polygons Rasterizing Polygons • In interactive graphics, polygons rule the world • Triangle is the minimal unit of a polygon • Two main reasons: – All polygons can be broken up into triangles • Convex, concave, complex – Lowest common denominator for surfaces – Triangles are guaranteed to be: • Can represent any surface with arbitrary accuracy • Planar • Splines, mathematical functions, volumetric isosurfaces… • Convex – Mathematical simplicity lends itself to simple, – What exactly does it mean to be convex? regular rendering algorithms • Like those we’re about to discuss… • Such algorithms embed well in hardware Convex Shapes Triangularization • Convex polygons easily • A two-dimensional shape is convex if and only if triangulated every line segment connecting two points on the boundary is entirely contained. • Concave polygons present a challenge Computer Graphics CS5600

  2. Utah School of Computing Spring 2013 Scan Conversion Rasterizing Triangles • Interactive graphics hardware sometimes uses edge walking or edge equation techniques for rasterizing triangles • Interactive graphics hardware more commonly uses barycentric coordinates • In scanline rendering surfaces are projected on the for rasterizing triangles screen and space filling ‘rasterizing’ algorithms are used to fill in the color. • Color values from light are approximated. Triangle Rasterization Issues Triangle Rasterization Issues • Exactly which pixels should be lit? • Sliver • A: Those pixels inside the triangle edges • What about pixels exactly on the edge? – Draw them: order of triangles matters (it shouldn’t) – Don’t draw them: gaps possible between triangles • We need a consistent (if arbitrary) rule – Example: draw pixels on left and bottom edge, but not on right or top edge Triangle Rasterization Issues Triangle Rasterization Issues • Shared Edge Ordering • Moving Slivers Computer Graphics CS5600

  3. Utah School of Computing Spring 2013 Computer Graphics CS5600

  4. Utah School of Computing Spring 2013 Edge Equations • An edge equation is simply the equation of the line defining that edge – Q: What is the implicit equation of a line? – A: Ax + By + C = 0 – Q: Given a point ( x , y ), what does plugging x & y into this equation tell us? How do we know if it’s ‘inside’? – A: Whether the point is: • On the line: Ax + By + C = 0 • “Above” the line: Ax + By + C > 0 • “Below” the line: Ax + By + C < 0 Edge Equations Edge Equations • And a triangle can be defined as the • Edge equations thus define two half-spaces : intersection of three positive half-spaces: A 2 x A 3 x + B 3 y + C 3 < 0 + B 2 A 3 x + B 3 y + C 3 > 0 A 2 y x + + C 2 B 2 < y 0 + C 2 > 0 A 1 x + B 1 y + C 1 > 0 A 1 x + B 1 y + C 1 < 0 Edge Equations • So…simply turn on those pixels for which all edge equations evaluate to > 0: - - + + + - Computer Graphics CS5600

  5. Utah School of Computing Spring 2013 Sweep-line Sweep-line: Notes • Basic idea: • Order three triangle vertices in x and y – Draw edges vertically – Find middle point in y dimension and compute if it is to the left or right of polygon. Also could be flat top or flat bottom • Interpolate colors up/down edges triangle – Fill in horizontal spans for each scanline • We know where left and right edges are. • At each scanline, interpolate edge colors across span – Proceed from top scanline downwards (and other way too) – Fill each span – Until bottom/top vertex is reached • Advantage: can be made very fast • Disadvantages: – Lots of finicky special cases Sweep line: Disadvantages • Fractional offsets: • Be careful when interpolating color values! • Beware of gaps between adjacent edges • Beware of duplicating shared edges Computer Graphics CS5600

  6. Utah School of Computing Spring 2013 Polygon Scan Conversion Intersection Points Other points in the span Computer Graphics CS5600

  7. Utah School of Computing Spring 2013 Determining Inside vs. Outside Vertices and Parity • Use the odd-parity rule – Set parity even initially – Invert parity at each intersection point – Draw pixels when parity is odd, do not draw when it is even Scan line • How do we count vertices, i.e., do we invert parity when a vertex falls exactly on a scan line? ????? • How do we count the intersecting vertex in the parity computation? Vertices and Parity Vertices and Parity • We need to either count it 0 times, or 2 times to keep parity correct. • If we count a vertex as one intersection, the second • What about: polygon gets drawn correctly, but the first does not. • If we count a vertex as zero or two intersections, the first polygon gets drawn correctly, but the second Scan line does not. • How do we handle this? • We need to count this – Count only vertices that are the y min vertex for that line vertex once ????? Horizontal Edges Vertices and Parity • How do we deal with horizontal edges? ??? • Both cases now work correctly Don’t count their vertices in the parity calculation! Computer Graphics CS5600

  8. Utah School of Computing Spring 2013 Shared Polygon Edges Top Spans of Polygons Draw  Last polygon wins • Effect of only counting y min : • What if two polygons share an edge? – Top spans of polygons are not drawn – If two polygons share this edge, Orange last Blue last it is not a problem. • Solution: – Span is closed on left and open on right ( x min  x < x max ) – Scan lines closed on bottom and – What about if this is the only polygon with that edge? open on top ( y min  y < y max ) General Pixel Ownership Rule General Polygon Rasterization • Half-plane rule: • Consider the following polygon: A boundary pixel (whose center falls exactly on an edge) is not D considered part of a primitive if the half plane formed by the B edge and containing the primitive lies to the left or below the edge. C Applies to arbitrary polygons A as well as to rectangles.... E F Shared edge • Consequences: • How do we know whether a given pixel on the – Spans are missing the right-most pixel scanline is inside or outside the polygon? – Each polygon is missing its top-most span Polygon Rasterization Polygon Rasterization • Inside-Outside Points • Inside-Outside Points Computer Graphics CS5600

  9. Utah School of Computing Spring 2013 General Polygon Rasterization General Polygon Rasterization • Basic idea: use a parity test • Count your vertices carefully for each scanline edgeCnt = 0; G F for each pixel on scanline (l to r) if (oldpixel->newpixel crosses edge) edgeCnt ++; I H // draw the pixel if edgeCnt odd E if (edgeCnt % 2) C setPixel(pixel); J D A B Faster Polygon Rasterization • How can we optimize the code? for each scanline edgeCnt = 0; for each pixel on scanline (l to r) if (oldpixel->newpixel crosses edge) edgeCnt ++; // draw the pixel if edgeCnt odd if (edgeCnt % 2) setPixel(pixel); • Big cost: testing pixels against each edge • Solution: active edge table (AET) Active Edge Table Active Edge Table Preprocess: Sort on Y • Idea: Edge Table – Edges intersecting a given scanline are likely to intersect the next scanline Y max ,x at y min ,slope – The order of edge intersections doesn’t change much from scanline to scanline Computer Graphics CS5600

  10. Utah School of Computing Spring 2013 Active Edge Table Active Edge Table Preprocess: Sort on Y Preprocess: Sort on Y Edge Table Edge Table Y max ,x at y min ,slope Y max ,x at y min ,slope AB: AB: 3 7 -5/2 CB: Active Edge Table Active Edge Table Preprocess: Sort on Y Preprocess: Sort on Y Edge Table Edge Table Y max ,x at y min ,slope Y max ,x at y min ,slope AB: 3 7 -5/2 AB: 3 7 -5/2 CB: 5 7 6/4 CB: 5 7 6/4 CD: CD: 11 13 0 DE: Active Edge Table Active Edge Table Preprocess: Sort on Y Preprocess: Sort on Y Edge Table Edge Table Y max ,x at y min ,slope Y max ,x at y min ,slope AB: 3 7 -5/2 AB: 3 7 -5/2 CB: 5 7 6/4 CB: 5 7 6/4 CD: 11 13 0 CD: 11 13 0 DE: 11 7 6/4 DE: 11 7 6/4 EF: EF: 9 7 -5/2 FA: Computer Graphics CS5600

Recommend


More recommend