Principles of Computer Graphics and Image Processing Visibility, Culling, Clipping (05) RNDr. Martin Madaras, PhD. martin.madaras@stuba.sk
Overview Clipping Point Clipping Line Clipping Polygon Clipping Hidden Surface Removal 2
3D rendering pipeline 3D polygons Modeling 1 Transformation Lighting Viewing Transformation Projection Rasterization (05) Transformation Clip polygons outside of camera’s view Clipping Scan Conversion 2D Image 3
How the lectures should look like #1 Ask questions, please!!! - Be communicative - www.slido.com #PPGSO05 - More active you are, the better for you! - 4
2D rendering pipeline 2D geometry Clip and remove geometry outside of the Clipping window Viewport Transform from screen coordinates to image Transformation coordinates Fill pixels on the screen Scan Conversion 2D Image 5
2D rendering pipeline 2D geometry Clip and remove geometry outside of the Clipping window Viewport Transform from screen coordinates to image Transformation coordinates Fill pixels on the screen Scan Conversion 2D Image 6
Clipping Avoid drawing parts of primitives outside window Window defines part of scene being viewed Must draw geometric primitives only inside window Screen Coordinates 7
Clipping Avoid drawing parts of primitives outside window Window defines part of scene being viewed Must draw geometric primitives only inside window 8
Clipping Avoid drawing parts of primitives outside window Points, Lines, Polygons, Circles etc. 9
Point Clipping Is point (x,y) inside clip window ? 10
Line Clipping Find the part of a line inside the clip window Before Clipping 11
Line Clipping Find the part of a line inside the clip window After Clipping 12
Cohen-Shutherland Line Clipping Use simple test to classify easy cases first Danny Cohen, Ivan Sutherland 1967 13
Cohen-Shutherland Line Clipping Classify lines quickly by AND of bit codes representing regions of two endpoints (test for 0) 14
Cohen-Shutherland Line Clipping Classify lines quickly by AND of bit codes representing regions of two endpoints (test for 0) 15
Cohen-Shutherland Line Clipping Classify lines quickly by AND of bit codes representing regions of two endpoints (test for 0) 16
Cohen-Shutherland Line Clipping Compute intersections with window boundary for remaining lines 17
Cohen-Shutherland Line Clipping Intersect with boundary determined by the bits of the non zero point 18
Cohen-Shutherland Line Clipping Create new point on the boundary 19
Cohen-Shutherland Line Clipping Check using the AND operation again 20
Cohen-Shutherland Line Clipping Do the same for the next line 21
Cohen-Shutherland Line Clipping Clip using the boundary determined by P7 22
Cohen-Shutherland Line Clipping Clip using the boundary determined by P7 23
Cohen-Shutherland Line Clipping Clip using the boundary determined by P8 24
Cohen-Shutherland Line Clipping Test the line again using AND 25
Cohen-Shutherland Line Clipping Again for the last line 26
Cohen-Shutherland Line Clipping P9 AND P10 no longer zero 27
Cohen-Shutherland Line Clipping Final result 28
Polygon Clipping Find the part of a polygon inside the clip window? Before Clipping 29
Polygon Clipping Find the part of a polygon inside the clip window? After Clipping 30
Sutherland – Hodgman Clipping Clip to each window boundary one at a time 31
Sutherland – Hodgman Clipping Clip to each window boundary one at a time 32
Sutherland – Hodgman Clipping Clip to each window boundary one at a time 33
Sutherland – Hodgman Clipping Clip to each window boundary one at a time 34
Sutherland – Hodgman Clipping Clip to each window boundary one at a time 35
Clipping to a Boundary Do inside test for each point in sequence Insert new points when crossing the boundary Remove points outside of boundary 36
Clipping to a Boundary Do inside test for each point in sequence Insert new points when crossing the boundary Remove points outside of boundary 37
Clipping to a Boundary Do inside test for each point in sequence Insert new points when crossing the boundary Remove points outside of boundary 38
Clipping to a Boundary Do inside test for each point in sequence Insert new points when crossing the boundary Remove points outside of boundary 39
Clipping to a Boundary Do inside test for each point in sequence Insert new points when crossing the boundary Remove points outside of boundary 40
Clipping to a Boundary Do inside test for each point in sequence Insert new points when crossing the boundary Remove points outside of boundary 41
Clipping to a Boundary Do inside test for each point in sequence Insert new points when crossing the boundary Remove points outside of boundary 42
Clipping to a Boundary Do inside test for each point in sequence Insert new points when crossing the boundary Remove points outside of boundary 43
Clipping to a Boundary Do inside test for each point in sequence Insert new points when crossing the boundary Remove points outside of boundary 44
2D rendering pipeline 2D geometry Clip and remove geometry outside of the Clipping window Viewport Transform from screen coordinates to image Transformation coordinates Fill pixels on the screen Scan Conversion 2D Image 45
Viewport Transformation Window to viewport mapping 46
Overview Clipping Point Clipping Line Clipping Polygon Clipping Hidden Surface Removal 47
Visibility wireframe model front faces silhouette visible faces, edges 48
Motivation Surfaces may be back-facing Surfaces may be occluded Surfaces may overlap in the image plane Surfaces may intersect 49
3D rendering pipeline 3D polygons Modeling 1 Transformation Lighting Somewhere here we have to determine Viewing which objects are visible and which are Transformation hidden Projection Transformation Clipping Scan Conversion 2D Image 50
Basic algorithms for HSR Clipping Point Clipping Line Clipping Polygon Clipping Hidden Surface Removal 51
Optimizing visibility Get rid of objects that are surely not visible Frustum culling Occlusion culling Back-face culling 52
Frustum culling 6 planes Inside = visible volume Is a point is inside? Object bounding box Speed up 53
Occlusion culling Some objects are fully occluded by others Spatial relations between objects Portals, occlusion culling Realtime rendering 54
Back-face culling Which object faces are visible? Remember normal vector (face orientation) 55
Portal culling Some parts of the scene are not visible from some other parts of the scene 56
Optimizing visibility 57
Basic algorithms for HSR Back-face culling Depth sort Z-Buffer 58
Back-face culling How do we test back-facing polygons ? Dot product the normal and view direction 𝑂 •V > 0 59
Surface Normals Normal Cross product of surface tangent vectors Length normalized to 1 60
Vertex / Fragment Normals Dot product the normal and view direction Fragment normals can be interpolated from vertex normals 61
3D rendering pipeline 3D polygons Modeling 1 Transformation Back-face culling Lighting Remove all polygons that are back-facing Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image 62
Depth sort “Painter’s algorithm” Sort surfaces by maximum depth Draw surfaces in back to front order 63
Painter’s algorithm Sort faces in a back-to-front order, render New pixels over-write old pixels 64
Painter’s algorithm problems Intersecting faces Cyclically overlapping faces Redundant rendering 65
3D rendering pipeline 3D polygons Sorting is often O(n log n) Modeling 1 Transformation Usually software only Lighting Mostly using BSP-trees Viewing Transformation Projection Transformation Clipping Depth sort Scan Conversion 2D Image 66
Other algorithms Warnock algorithm subdivide screen into a quadtree until whole cell empty or whole cell inside polygons Reversed painter’s algorithm paint front-to-back and paint only empty areas Z-buffer remember z-value for each pixel and only paint when new z is higher 67
Z-Buffer Also known as depth buffering Stores closest depth of objects for every pixel Draw only pixels with less depth Depths are interpolated between vertices 68
Recommend
More recommend