triangle rasterization
play

Triangle Rasterization Sung-Eui Yoon ( ) ( ) C Course URL: URL - PowerPoint PPT Presentation

Introduction to Computer Graphics and OpenGL p p p Triangle Rasterization Sung-Eui Yoon ( ) ( ) C Course URL: URL http://sglab.kaist.ac.kr/~sungeui/ETRI_CG/ Class Objectives Class Objectives Understand triangle


  1. Introduction to Computer Graphics and OpenGL p p p Triangle Rasterization Sung-Eui Yoon ( 윤성의 ) ( 윤성의 ) C Course URL: URL http://sglab.kaist.ac.kr/~sungeui/ETRI_CG/

  2. Class Objectives Class Objectives ● Understand triangle rasterization using Understand triangle rasterization using edge-equations ● Understand mechanics for parameter ● Understand mechanics for parameter interpolations ● Realize benefits of incremental algorithms ● Realize benefits of incremental algorithms 2

  3. Topics for Today Topics for Today ● Quick review of coordinate systems Quick review of coordinate systems ● Motivation ● What is rasterization? Wh t i t i ti ? ● Why triangles? ● Rasterization Raste i ation ● Scan-line ● Edge equations ● Edge equations ● I nterpolation ● Beyond triangles B d t i l 3

  4. Coordinate Systems Coordinate Systems model model M Modelview matrix Modelview matrix world world V eye eye P clip clip Divide by w NDC NDC Viewport transformation window window 4

  5. Primitive Rasterization Primitive Rasterization ● Rasterization converts vertex representation to R t i ti t t t ti t pixel representation ● Coverage determination ● Computes which pixels (samples) belong to a primitive i iti ● Parameter interpolation ● Computes parameters at covered pixels from C t t t d i l f parameters associated with primitive vertices 5

  6. Coverage Determination Coverage Determination ● Coverage is a 2D sampling problem C i 2D li bl ● Possible coverage criteria: ● Distance of the primitive Di f h i i i to sample point (often used with lines) (often used with lines) ● Percent coverage of a pixel (used to be popular) ● Sample is inside the primitive (assuming it is closed) 6

  7. Why Triangles? Why Triangles? ● Triangles are simple Triangles are simple ● Simple representation for a surface element (3 points or 3 edge equations) (3 points or 3 edge equations) ● Triangles are linear (makes computations easier)  v 2     T ( (v ,v ,v ) , , ) 0 0 1 1 2 2 e  e T (e ,e ,e ) 0 1 0 1 2  v v 1 e  v 2 0 7

  8. Why Triangles? Why Triangles? ● Triangles are convex T i l ● What does it mean to be a convex? An object is convex if and only if any line segment connecting two points on ts boundary is contained connecting two points on ts boundary is contained entirely within the object or one of its boundaries 8

  9. Why Triangles? Why Triangles? ● Triangles are convex T i l ● Why is convexity important? Wh i it i t t? ● Regardless of a triangle’s orientation on the screen a given scan line will contain only a screen a given scan line will contain only a single segment or span of that triangle ● Simplify rasterization processes p y p 9

  10. Why Triangles? Why Triangles? ● Arbitrary polygons can be decomposed into ● Arbitrary polygons can be decomposed into triangles ● Decomposing a convex n-sided polygon is trivial ● Suppose the polygon has ordered vertices { v ● Suppose the polygon has ordered vertices { v 0 , v 1 , ... v n } v v } ● I t can be decomposed into triangles { (v 0 ,v 1 ,v 2 ), { v 0 ,v 2 ,v 3 ), (v 0 ,v i ,v i+ 1 ), ... (v 0 ,v n-1 ,v n )} { 0 , 2 , 3 ), ( 0 , i , i+ 1 ), ( 0 , n 1 , n )} ● Decomposing a non-convex polygon is non-trivial ● Sometimes have to introduce new vertices 10

  11. Why Triangles? Why Triangles? ● Triangles can approximate any 2-dimensional T i l i t 2 di i l shape (or 3D surface) ● Polygons are a locally linear (planar) approximation ● Polygons are a locally linear (planar) approximation ● I mprove the quality of fit by increasing the number edges or faces number edges or faces 11

  12. Scanline Triangle Rasterizer Scanline Triangle Rasterizer ● Walk along edges and process one scanline Walk along edges and process one scanline at a time; also called edge walk method ● Rasterize spans between edges ● Rasterize spans between edges 12

  13. Scanline Triangle Rasterizer Scanline Triangle Rasterizer ● Walk along edges and process one scanline Walk along edges and process one scanline at a time ● Rasterize spans between edges ● Rasterize spans between edges 13

  14. Scanline Triangle Rasterizer Scanline Triangle Rasterizer ● Walk along edges and process one scanline Walk along edges and process one scanline at a time ● Rasterize spans between edges ● Rasterize spans between edges 14

  15. Scanline Triangle Rasterizer Scanline Triangle Rasterizer ● Walk along edges and process one scanline Walk along edges and process one scanline at a time ● Rasterize spans between edges ● Rasterize spans between edges 15

  16. Scanline Triangle Rasterizer Scanline Triangle Rasterizer ● Walk along edges and process one scanline Walk along edges and process one scanline at a time ● Rasterize spans between edges ● Rasterize spans between edges 16

  17. Scanline Triangle Rasterizer Scanline Triangle Rasterizer ● Walk along edges and process one scanline Walk along edges and process one scanline at a time ● Rasterize spans between edges ● Rasterize spans between edges 17

  18. Fractional Offsets Fractional Offsets offset from edge to pixel center to pixel center ● Straightforward to interpolate values (e.g. colors) along the edges, but must be careful when l h d b b f l h offsetting from the edge to the pixel’s center 18

  19. Scanline Rasterizing Scenes Scanline Rasterizing Scenes ● Sort all edges by start scanline into the I nactive Edge Table ● Sort all edges by start scanline into the I nactive Edge Table (I ET) ● Move edges intersected by current scanline Move edges intersected by current scanline from I ET to Active Edge Table (AET) processed ● Compute spans between active edges p p g active inactive ● Sort spans by starting x current ● Rasterize visible span segments ● Rasterize visible span segments scanline scanline ● Remove edges from AET when they no longer intersect the current scanline o ge te sect t e cu e t sca e 19

  20. Scanline Rasterization Scanline Rasterization ● Advantages: Advantages: ● Can be made quite fast ● Low memory usage for small scenes ● Low memory usage for small scenes ● Do not need full 2D z-buffer (can use 1D z- buffer on the scanline) buffer on the scanline) ● Disadvantages: ● Does not scale well to large scenes Does not scale well to large scenes ● Have to worry about fractional offsets ● Lots of special cases p 20

  21. Rasterizing with Edge Equations Rasterizing with Edge Equations ● Compute edge equations from vertices p g q ● Compute interpolation equations from vertex parameters ● Traverse pixels evaluating the edge equations ● Traverse pixels evaluating the edge equations ● Draw pixels for which all edge equations are positive ● I nterpolate parameters at pixels I nterpolate parameters at pixels 21

  22. Edge Equation Coefficients Edge Equation Coefficients ● The cross product between 2 homogeneous The cross product between 2 homogeneous points generates the line between them     e e v v v v 0 1   t t [x y 1 ] [x y 1 ]  v 0 0 1 1 1 e e     [(y y ) (x x ) (x y x y )]  v 0 1 1 0 0 1 1 0 0 A B C    E(x,y) Ax By C ● A pixel at (x,y) is “inside” an edge if E(x,y)> 0 22

  23. Numerical Precision Numerical Precision ● Subtraction of two nearly equal floating point S bt ti f t l l fl ti i t numbers results in catastophic cancellation which leaves only a few significant bits leaves only a few significant bits      3 3 0 1 .234 1 0 1 .233 1 0 1 .000 1 0 ● When x y  x y computing C = x y ● When x 0 y 1  x 1 y 0 computing C = x 0 y 1  x 1 y 0 can x y can result in loss of precision ● Reformulate C coefficent: ● Reformulate C coefficent:    A(x x ) B(y y )    0 1 0 1 C C 2 23

  24. Shared Edges Shared Edges ● Suppose two triangles share an edge. S t t i l h d triangle 1 Which covers the pixel when the edge passes through the sample (E(x,y) passes through the sample (E(x,y)= 0)? 0)? ● Both triangle 2 ● Pixel color becomes dependent on order of Pixel color becomes dependent on order of triangle rendering ● Creates problems when rendering transparent objects - “double hitting” ● Neither ● Missing pixels create holes in otherwise solid surface ● We need a consistent tie-breaker! 24

  25. Shared Edges Shared Edges ● A common tie-breaker: A common tie breaker: (A,B) triangle 1    A 0 if A 0    bool t bool t   B 0 ot herwise triangle 2 ● Coverage determination becomes if( E(x,y) > 0 | | (E(x,y)= = 0 && t)) f pixel is covered 25

  26. Shared Vertices Shared Vertices ● Use “inclusion direction” as a tie breaker ● Any direction can be used ● Snap vertices to subpixel grid and displace so that no vertex can be at the pixel center 26

  27. Other benefits of snapping to subpixel grid subpixel grid ● Simplicity ● Simplicity ● can use fixed-point arithmetic can be used (integer operations) (integer operations) ● Robustness ● With sufficient bits edge equations and areas ● With sufficient bits, edge equations and areas can be computed exactly ● Quality Quality ● Smoother animation than if we snapped to the pixel grid 27

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend