cli clipping i
play

Cli Clipping i Werner Purgathofer Werner Purgathofer Viewing in - PowerPoint PPT Presentation

Einfhrung in Visual Computing g p g 186.822 Cli Clipping i Werner Purgathofer Werner Purgathofer Viewing in the Rendering Pipeline g g p object capture/creation j p scene objects in object space modeling modeling vertex stage


  1. Einführung in Visual Computing g p g 186.822 Cli Clipping i Werner Purgathofer Werner Purgathofer

  2. Viewing in the Rendering Pipeline g g p object capture/creation j p scene objects in object space modeling modeling vertex stage viewing viewing („vertex shader“) projection p j transformed vertices in clip space clipping + homogenization scene in normalized device coordinates i li d d i di t viewport transformation viewport transformation rasterization pixel stage shading ( fragment shader“) („fragment shader ) raster image in pixel coordinates Werner Purgathofer 2

  3. Overview: Clipping pp g line clipping line clipping polygon clipping polygon clipping triangle clipping triangle clipping Werner Purgathofer 3

  4. Clipping pp g partly visible or completely invisible parts must not be ignored and must not be drawn b b ignored?: scrolled?: vertices vertices edges edges   must be cut off (as early as possible)  must be cut off (as early as possible) Werner Purgathofer 4

  5. Clipping Operations pp g p remove objects outside a clip window remove objects outside a clip window clip window: rectangle, polygon, curved boundaries clip window: rectangle, polygon, curved boundaries applied somewhere in the viewing pipeline pp g p p can be combined with scan conversion objects to clip: points, lines, triangles, polygons, curves, text, ... Werner Purgathofer 5

  6. 3 Principle Possibilities for Clipping p pp g analytically in world coordinates analytically in world coordinates reduces WC  DC transformations reduces WC  DC transformations analytically in clip coordinates simple comparisons during raster conversation during raster conversation = as part of the rasterization algorithm as part of the rasterization algorithm may be efficient for complex primitives y p p Werner Purgathofer 6

  7. Line Clipping (1) pp g ( ) P 9 P 4 P 2 P 2 P 10 P P ´ 8 P 8 P 8 P 1 P P P 1 8 P 6 P 6 P 3 P 5 P ´ P 5 P 7 P ´ 7 7 7 before clipping before clipping after clipping after clipping [li [line clipping against a rectangular clip window] li i i l li i d ] Werner Purgathofer 7

  8. Line Clipping (2) pp g ( ) goals goals eliminate simple cases fast eliminate simple cases fast avoid intersection calculations for endpoints (x 0 ,y 0 ), (x end ,y end ) intersect parametric representation intersect parametric representation x = x 0 + u · (x end - x 0 ) u ( 0 ) 0 end y = y 0 + u · (y end - y 0 ) with window borders: intersection  0 < u < 1  0 < i t ti < 1 Werner Purgathofer 8

  9. Cohen ‐ Sutherland Line Clipping pp g assignment of region codes to line endpoints assignment of region codes to line endpoints 1001 1000 1010 bit1: left bit1: left Window bit2: right g 0001 0000 0010 0001 0000 0010 bit3: below bit4: above 0101 0100 0110 binary region codes assigned to line endpoints according to relative binary region codes assigned to line endpoints according to relative position with respect to the clipping rectangle position with respect to the clipping rectangle Werner Purgathofer 9

  10. Cohen ‐ Sutherland Line Clipping pp g “or” of codes of both points p = 0000  line entirely visible 1001 1000 1010 Window 0001 0000 0010 0001 0000 0010 “and” of codes of both points  0000  line entirely invisible 0000  li ti l i i ibl 0101 0100 0110 all others  intersect! all others  intersect! Werner Purgathofer 10

  11. Cohen ‐ Sutherland Line Clipping pp g P 2 P’ P’ 2 l lines extending from one d f P 2 P” coordinate region to another coordinate region to another window window may pass through the clip may pass through the clip window, or they may intersect clipping boundaries without entering the window P 3 P’ 1 P’ 3 P 1 P 4 P 4 1 Werner Purgathofer 11

  12. Cohen ‐ Sutherland Line Clipping pp g remaining lines remaining lines intersection test with bounding lines of clipping window intersection test with bounding lines of clipping window left, right, bottom, top , g , , p discard an outside part repeat intersection test up to four times y = y 0 + m(xw min – x 0 ), y = y 0 + m(xw max – x 0 ) y = y + m(xw x ) y = y + m(xw x ) vertical: vertical: horizontal: x = x 0 + (yw min – y 0 )/m, x = x 0 + (yw max – y 0 )/m (yw min y 0 )/ , (yw max y 0 )/ 0 0 Werner Purgathofer 12

  13. Cohen ‐ Sutherland Line Clipping pp g P 2 P 2 P’ passes through clipping window p g pp g P” 2 P 2 window window intersects boundaries without entering clipping window entering clipping window P 3 P’ 1 P’ 3 P 1 P 4 4 y = y + m(xw y = y 0 + m(xw min – x 0 ), y = y 0 + m(xw max – x 0 ) x ) y = y + m(xw x ) vertical: vertical: horizontal: x = x 0 + (yw min – y 0 )/m, x = x 0 + (yw max – y 0 )/m (yw min y 0 )/ , (yw max y 0 )/ 0 0 Werner Purgathofer 13

  14. Polygon Clipping yg pp g modification of line clipping modification of line clipping goal: one or more closed areas display of a polygon processed display of a correctly b by a line ‐ clipping algorithm li li i l ith clipped polygon li d l Werner Purgathofer 14

  15. Sutherland ‐ Hodgman Polygon Clipping g yg pp g processing polygon boundary as a whole against each window edge processing polygon boundary as a whole against each window edge output: list of vertices output: list of vertices original clip left clip right clip bottom clip top polygon polygon clipping a polygon against successive window boundaries li i l i t i i d b d i Werner Purgathofer 15

  16. Sutherland ‐ Hodgman Polygon Clipping g yg pp g four possible edge cases p g V 2 V 1 V new new V 2 V 1 V 2 V 1 V new V 1 V 1 V 2 V 2 out  in in  in in  out out  out output: V new , V 2 no output V 2 V new successive processing of pairs of polygon vertices against the successive processing of pairs of polygon vertices against the left window boundary y Werner Purgathofer 16

  17. Sutherland ‐ Hodgman Polygon Clipping g yg pp g V := 1 st vertex V 2 := 1 st vertex for 1 edge: for 1 edge: V 1 :=V 2 V 2  result list V 2 :=next vertex no y yes V 2 visible? V visible? no yes yes no V 1 visible? V 1 visible? 1 1 V’ 1 = clip edge  V 1 V 2  result list Werner Purgathofer 17

  18. Sutherland ‐ Hodgman Polygon Clipping g yg pp g window window clipping a polygon against the left boundary of a 3 window, starting with i d t ti ith 1’ 2’ vertex 1 vertex 1. 2 primed numbers are used 1 1 3’ 3’ 4 4 to label the points in the 6 output vertex list for this li f hi 5’ 4’ 4 window boundary window boundary 5 5 Werner Purgathofer 18

  19. Polygon Clip: Combination of 4 Passes yg p the polygon is clipped against each of the 4 borders separately the polygon is clipped against each of the 4 borders separately, that would produce 3 intermediate results. p by calling the 4 tests recursively , (or by using a clipping pipeline) every result point is immediately processed on, l i i i di l d so that only one result list is produced so that only one result list is produced Werner Purgathofer 19

  20. Sutherland ‐ Hodgman Clipping Example g pp g p pipeline of boundary pipeline of boundary window window 1 st clip: clippers to avoid 2 p intermediate vertex lists left 2’ 2 1’ 2” 3 3 2 nd clip: 3’ 3’ bottom b tt 1 P Processing the polygon vertices through a boundary ‐ clipping i h l i h h b d li i pipeline After all vertices are processed through the pipeline the pipeline. After all vertices are processed through the pipeline, the vertex list for the clipped polygon is {1’, 2, 2’, 2”} vertex list for the clipped polygon is {1 , 2, 2 , 2 } Werner Purgathofer 20

  21. Sutherland ‐ Hodgman Polygon Clipping g yg pp g extraneous lines for concave polygons: extraneous lines for concave polygons: split into separate parts split into separate parts or or final check of output vertex list p clipping the concave pp g polygon with the Sutherland ‐ Hodgeman clipper prod ces three clipper produces three connected areas connected areas Werner Purgathofer 21

  22. Clipping of Triangles pp g g often b ‐ reps are “triangle soups” often b ‐ reps are triangle soups clipping a triangle  triangle(s) clipping a triangle  triangle(s) 4 possible cases: 4 possible cases: inside (inside) (inside) outside triangle quadrilateral  2 triangles Werner Purgathofer 22

  23. Clipping of Triangles pp g g corner cases need no extra handling! corner cases need no extra handling! Werner Purgathofer 23

  24. From Object Space to Screen Space j p p „view frustum“ modeling d li camera transformation transformation object space world space camera space projection viewport transformation transformation transformation transformation clip space screen space 24 Werner Purgathofer

  25. Clipping in Clip ‐ Space pp g p p clipping against x = ± 1, y = ± 1, z = ± 1 clipping against x = ± 1 y = ± 1 z = ± 1 (x y z) inside? (x,y,z) inside?  only compare one value!  only compare one value! is done before homogenization: x = ± h, y = ± h, z = ± h clips points that are behind the camera! li i h b hi d h ! reduces homogenization divisions d h i ti di i i Werner Purgathofer 25

  26. Einführung in Visual Computing g p g 186.822 A ti li Antialiasing i Werner Purgathofer Werner Purgathofer

Recommend


More recommend