visibility determination
play

Visibility Determination AKA, hidden surface elimination - PowerPoint PPT Presentation

Visibility Determination AKA, hidden surface elimination Visibility Algorithms Roger Crawfis CIS 781 This set of slides reference slides used at Ohio State for instruction by Prof. Machiraju and Prof. Han-Wei Shen. Hidden Lines Hidden


  1. Visibility Determination • AKA, hidden surface elimination Visibility Algorithms Roger Crawfis CIS 781 This set of slides reference slides used at Ohio State for instruction by Prof. Machiraju and Prof. Han-Wei Shen. Hidden Lines Hidden Lines Removed

  2. Topics Hidden Surfaces Removed � Backface Culling � Hidden Object Removal: Painters Algorithm � Z-buffer � Spanning Scanline � Warnock � Atherton-Weiler � List Priority, NNA � BSP Tree � Taxonomy Where Are We ? Back-face Culling � Canonical view volume (3D image space) � Clipping done � division by w � z > 0 � Problems ? y y clipped line clipped line x x 1 � Conservative algorithm 1 near far z z 0 1 � Real job of visibility never solved image plane near far

  3. Back-face Culling Back-face Culling • If a surface’s normal is pointing in the same general • Only handles faces oriented direction as our eye, then this is a back face away from the viewer: • The test is quite simple: if N * V > 0 then we reject the surface – Closed objects – Near clipping plane does not intersect the objects • Gives complete solution for a single convex • If test is in eye- space, then if polyhedron. N z > 0 reject. • Still need to sort, but we have reduced the number of primitives to sort. Painters Algorithm Point sorting vs Polygon Sorting � Sort objects in depth order � Draw all from Back-to-Front (far-to-near) • What does it mean to sort two line � Simply overwrite the existing pixels. segments? � Is it so simple? – Zmin? at z = 22, at z = 18, at z = 10, – Zmax? – Slope? – Length? X z Y

  4. 3D Cycles Form of the Input � How do we deal with cycles? Object types: what kind of objects does it handle? � How do we deal with intersections? � convex vs. non-convex � How do we sort objects that overlap in Z? � polygons vs. everything else - smooth curves, non- continuous surfaces, volumetric data Z Form of the output Object Space Algorithms � Volume testing – Weiler-Atherton, etc. Precision: image/object space? � input: convex polygons + infinite eye pt � output: visible portions of wireframe edges � Object Space � Image Space � Geometry in, geometry out � Geometry in, image out � Independent of image resolution � Visibility only at pixel centers � Followed by scan conversion

  5. Image-space algorithms Conservative Visibility Algorithms � Traditional Scan Conversion and Z-buffering � Viewport clipping � Hierarchical Scan Conversion and Z-buffering � Back-face culling � input: any plane-sweepable/plane-boundable � Warnock's screen-space subdivision objects � preprocessing: none � output: a discrete image of the exact visible set Z-buffer: Scanline Z-buffer I. for each polygon do � Z-buffer is a 2D array that stores a depth value for each pixel. for each pixel (x,y) in the polygon’s projection do z := -(D+A*x+B*y)/C; � InitScreen : DrawZpixel(x, y, z, polygon’s color); for i := 0 to N do for j := 1 to N do II. for each scan-line y do Screen[i][j] := BACKGROUND_COLOR ; Zbuffer[i][j] := ∞ ; for each “in range” polygon projection do for each pair (x 1 , x 2 ) of X-intersections do � DrawZpixel (x, y, z, color) for x := x 1 to x 2 do if (z <= Zbuffer[x][y]) then z := -(D+A*x+B*y)/C; DrawZpixel(x, y, z, polygon’s color); Screen[x][y] := color; Zbuffer[x][y] := z; If we know z x,y at (x,y) then: z x+1,y = z x,y - A/C

  6. Incremental Scanline Incremental Scanline (contd.) + + + = Ax By Cz D 0 � All that was about increment for pixels on each scanline. − + + ( Ax By D ) = ≠ z , C 0 � How about across scanlines for a given pixel ? C On a scan line Y = j , a constant � Assumption: next scanline is within polygon Thus depth of pixel at ( x 1 = x + ∆ x , j ) − + + − + + ( Ax Bj D ) ( Ax Bj D ) − + + + + ( Ax By D ) ( Ax By D ) − = + z z 1 − = + z z 1 1 C C 1 C C − A ( x x ) − A ( y y ) − = z z 1 − = z z 1 1 C 1 C A B = − ∆ , since ∆ x = 1, z z ( ) x = − ∆ , since ∆ y = 1, z z ( ) y 1 C 1 C A B = − z z = − z z 1 C 1 C Z-buffer - Example Non-Planar Polygons ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ P 3 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ − ( y y ) Z-buffer = + − z z ( z z ) 1 s ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ a 1 4 1 − ( y y ) 1 4 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ − ( y y ) ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ = + − z z ( z z ) 1 s b 1 2 1 − ( y y ) ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 1 2 P 4 P 2 − ( x x ) = + − z z ( z z ) a p p a b a − ( x x ) y s z a z p z b a b Screen P 1 Bilinear Interpolation of Depth Values

  7. [0,7,5] [6,7,5] [0,6,7] 5 5 5 5 5 5 5 7 5 5 5 5 5 5 5 5 5 5 5 6 7 5 6 7 5 5 5 5 4 5 6 7 5 5 5 3 4 5 6 7 5 5 2 3 4 5 6 7 5 [0,1,5] [0,1,2] [5,1,7] 5 5 5 5 5 5 5 ∞ 5 5 5 5 5 5 5 ∞ 5 5 5 5 5 5 ∞ ∞ 5 5 5 5 5 5 ∞ ∞ 5 5 5 5 5 ∞ ∞ ∞ 5 5 5 5 5 ∞ ∞ ∞ 5 5 5 5 ∞ ∞ ∞ ∞ 5 5 5 5 ∞ ∞ ∞ ∞ 5 5 5 ∞ ∞ ∞ ∞ ∞ 4 5 5 7 ∞ ∞ ∞ ∞ 5 5 ∞ ∞ ∞ ∞ ∞ ∞ 3 4 5 6 7 ∞ ∞ ∞ 5 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 2 3 4 5 6 7 ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ Non Trivial Example ? Example Rectangle: P1(10,5,10), P2(10,25,10), P3(25,25,10), P4(25,5,10) Triangle: P5(15,15,15), P6(25,25,5), P7(30,10,5) Frame Buffer: Background 0, Rectangle 1, Triangle 2 Z-buffer: 32x32x4 bit planes

  8. Z-Buffer Advantages Z-Buffer Disadvantages � Does not do transparency easily � Simple and easy to implement � Aliasing occurs! Since not all depth questions can be resolved � Amenable to scan-line algorithms � Anti-aliasing solutions non-trivial � Can easily resolve visibility cycles � Shadows are not easy � Handles intersecting polygons � Higher order illumination is hard in general Spanning Scan-Line Spanning Scan Line Algorithm Can we do better than scan-line Z-buffer ? • Use no z-buffer � Scan-line z-buffer does not exploit • Each scan line is subdivided into several "spans" � Scan-line coherency across multiple scan-lines • Determine which polygon the current span belongs to � Or span-coherence ! • Shade the span using the current polygon’s color � Depth coherency • Exploit "span coherence" : • For each span, only one visibility � How do you deal with this – scan-conversion algorithm and a little test needs to be done more data structure – Assuming no intersecting polygons.

  9. Spanning Scan Line Algorithm Spanning Scan Line Algorithm • A scan line is subdivided into a sequence of spans • Each span can be "inside" or "outside" polygon areas – "outside“: no pixels need to be drawn (background color) – "inside“: can be inside one or multiple polygons • If a span is inside one polygon, the pixels in the span will be drawn with the color of that polygon • If a span is inside more than one polygon, then we need to compare the z values of those polygons at the scan line edge intersection point to determine the color of the pixel When there are multiple Determine a span is inside or polygons outside (single polygon) • When a scan line intersects an edge of a • Each polygon will have its own in/out flag polygon • There can be more than one polygon having – for a 1 st time, the span becomes "inside" of the the in/out flags to be "in" at a given instance polygon from that intersection point on – for a 2 nd time, the span becomes "outside“ of the • We want to keep track of how many polygons polygon from that point on the scan line is currently in • Use a "in/out" flag for each polygon to keep • If there is more than one polygon "in", we track of the current state need to perform z value comparison to • Initially, the in/out flag is set to be "outside" determine the color of the scan line span (value = 0 for example). Invert the tag for “inside”.

  10. Many Polygons ! Z value comparison ET x y max ∆ x poly-ID • When the scan line intersects an edge, leaving the top-most polygon, we use the color of the remaining polygon if there is now only 1 polygon "in". poly-ID A,B,C,D color in/out flag PT • If there is still more than one polygon with an "in" flag, we need to perform z comparison, but only when the � Use a PT entry for each polygon scan line leaves a non-obscured polygon. � When polygon is considered, Flag is true � Multiple polygons can have their flags set to true � Use IPL as active In-Polygon List ! Spanning Scan-Line: Example Example 1 Y AET IPL BG a I x 0 , ba , bc, x N BG, BG+S, BG IV II x 0 , ba , bc, 32, 13, x N BG, BG+S, BG, BG+T, BG S T III x 0 , ba ba , 32, ca, 13, x x N BG, BG+S, BG+S+T, BG+T, BG III x 0 , , 32, ca, 13, BG, BG+S, BG+S+T, BG+T, BG N 2 III IV x 0 , ba , ac, 12, 13, x N BG, BG+S, BG, BG+T, BG c 1 BG a II 3 IV S I T b 2 III c X 0 X N II 3 I Think of ScanPlanes to understand ! b

Recommend


More recommend