/
CS112: Culling and Clipping CS112: Culling and Clipping

CS112: Culling and Clipping - PowerPoint Presentation

desha
desha . @desha
Follow
29 views
Uploaded On 2024-02-02

CS112: Culling and Clipping - PPT Presentation

Clip Coordinates vs NDC Clip space lefthanded Clip coordinate Normalized device coordinate NDC Culling discarding invisible polygons Backface culling Discarding all faces ie polygons that face backward ie whose ID: 1043859

intersection edge clipping polygon edge intersection polygon clipping clip culling convex edges ymin line view remove scanline output aet

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "CS112: Culling and Clipping" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. CS112: Culling andClipping

2. Clip Coordinates vs. NDCClip space (left-handed)ClipcoordinateNormalized devicecoordinate (NDC)

3. Culling: discarding invisible polygonsBack-face cullingDiscarding all faces (i.e., polygons) that face “backward” (i.e., whose normals point away from the eye)Culling

4. Remove parts of primitives (e.g., lines and polygons) that are not visibleMay need to generate new primitivesOpenGL performs clipping in the clip space (hence the name) against the view frustum (a cube)Clipping

5. View Frustum Culling & ClippingRed objects are fully outside (culling)Yellow objects are partially outside (clipping)Green objects are fully inside

6. Clipping line segmentsusing an axis-alignedwindowIn this example:AB: acceptCD: discard (cull)EF: clip (one endpointoutside the window)GH: clip (both endpointsoutside the window)Line Clipping in 2DGHABEFCDIJ

7. Divide the window in nine regions marked by binary codes:b1 = y > ymax ? 1 : 0b2 = y < ymin ? 1 : 0b3 = x > xmax ? 1 : 0b4 = x < xmin ? 1 : 00000 corresponds to theinterior of the windowCohen-Sutherland Clippingxminxmaxymaxymin100001000000101001100010100101010001

8. Cohen-Sutherland ClippingFind binary codes of two endpoints (C1, C2)C1= C2 = 0Accept the line, both endpoints inside the windowC1 = 0 or C2 = 0 (but not both)One endpoint outside the windowNonzero bits give the lines with which to intersectMaximum two intersection to get the clipped lineC1 & C2 != 0Both endpoints outside the same edge of the windowCull completelyC1 & C2 = 0Both endpoints outside, but different edgesFind the first intersection and find its binary codeApply recursively on this culled lineCheck in this order

9. Convex polygons clipped to a single polygonConcave polygonsClip and join to a single polygonTessalate and clip trianglesPolygon Clipping

10. Sutherland-Hodgeman algorithmRepeated clip a polygon using a clipping lineClipping Convex PolygonsPolygonClippingline

11. To clip a polygon against a line, one can examine its vertices one by one:Test first vertex, output if inside else skipThen loop through the list, testing transitionsIn-to-out: Output intersectionIn-to-in: Output vertexOut-to-in: Output intersection and vertexOut-to-out: Output nothingCan be extended to 3D easily (line-plane intersection) Sutherland-Hodgeman Algorithm

12. Bounding VolumesView Frustum CullingAxis-aligned The planes of the box is aligned with the world coordinatesObject orientedThe planes are aligned to hug the object more closelyMore rejections

13. PreprocessingHierarchically subdividing the frustumEach box has a list of polygons inside itAn empty box is the leaf nodeOctreeHierarchical bounding volumes/ Spatial Subdivision

14. Culling AlgorithmIf completely inside the view frustumAcceptIf completely outside the view frustumRejectIf intersects the view frustumGo through the children recursivelyWhat happens when a triangle spans across a box?Split the triangleInclude it in both boxesScreen space clipping takes care of itView Frustum Culling & Clipping

15. CS112: PolygonScanning

16. Polygon TypesConvexAll interior angles are less than 180 degreesConcaveInterior angles can be greater than 180 degreesCan be splited into multiple convex polygonsDegenerateIf all vertices are collinear (zero surface area)

17. Using direction of cross products of adjacent edgesIf the polygon lies within the XY plane, check the cross products’ Z coordinates: if all same sign, then convex; otherwise, concaveIdentifying Concave PolygonsXYE5E1E2E3E4E6E1 X E2 > 0E2 X E3 > 0E3 X E4 < 0E4 X E5 > 0E5 X E6 > 0

18. Triangulating a Convex PolygonV1V2V3V4V5V6While there exists more than three vertices:Take any three vertices in orderOutput the triangle associated with the middle vertexThrow away the middle vertex

19. Triangulating a Convex PolygonV1V2V3V4V5V6V1,V2,V3,V4,V5,V6(V1,V2,V3): tri 1, remove V2V1,V3,V4,V5,V6(V1,V3,V4): tri 2, remove V3V1,V4,V5,V6(V1,V4,V5): tri 3, remove V4V1,V5,V6(V1,V5,V6): tri 4

20. Polygon RasterizationBasic idea: Intersecting a scanline with polygon edges and fill between pairs of intersectionsWorks for both convex and concave polygonsFor y = ymin to ymax:Intersect the scanline with all edgesSort the intersections by increasing x: [p0, p1, p2, p3, …]Fill pairwise: (p0, p1), (p2, p3), …

21. Corner Case: Edge EndpointHappens when intersecting right at an edge endpointSolution: duplicating the endpoint[p0, p1, p1, p2], so we can still fill pairwiseIf computing the intersection of the scanline with edges e1 and e2 separately, we will get the intersection point p1 twiceSimply keep both copies

22. But what about this case:We want [p0, p1, p2, p3] (i.e., not duplicating p1)Rule: Count an intersection at an edge endpoint only if its is at yminIn the example above, count p1 for e1 but not e2 Corner Case : Edge Endpoint

23. JHorizontal edges do not need to be consideredScanline 1A – intersection of JAB – intersection of BCResult: [A, B]AB is filledScanning Polygon: ExampleABCDEFGHIScanline 1

24. JScanline 2J – intersection of IJNot of JAC – no change seenD – intersection of EDResult: [J, D]JD is filledScanning Polygon: ExampleABCDEFGHIScanline 2

25. JScanline 3I – no intersection of IJH – intersection of GHResult: [H, H’]HH’ is filledScanning Polygon: ExampleABCDEFGHIScanline 3H’

26. JScanline 4G – no intersection of GHF – no intersection of FEResult: [] (empty list)Nothing is filledScanning Polygon: ExampleABCDEFGHIScanline 4

27. Implementing the Scanline AlgorithmBrute force: intersect all the edges with all scanlineToo slow for complex scenes!Goal: compute the intersections more efficientlyFind the ymin and ymax of each edge and intersect the edge only when it crosses the scanlineOnly calculate the intersection of the edge with the first scan line it intersects

28. A separate bucket for each scanlineEach edge goes to the bucket of its ymin scanlineIn each bucket, edges are sorted by increasing x of the ymin endpointEdge Table (ET)

29. Active Edge Table (AET)A list of edges active for current scanline, sorted in increasing xy = 9y = 8

30. construct the ET # edge tableAET = [] # active edge tablefor y = ymin to ymaxmerge-sort ET[y] into AET by x valuefor each edge in AET:if edge.ymax = y: remove edge from AETfill between pairs of x in AETfor each edge in AET: edge.x = edge.x + dx/dysort AET by x valueScan-Polygon Algorithm