Visibility, Culling, Clipping (05) RNDr. Martin Madaras, PhD. - - PowerPoint PPT Presentation

visibility culling clipping 05
SMART_READER_LITE
LIVE PREVIEW

Visibility, Culling, Clipping (05) RNDr. Martin Madaras, PhD. - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

Principles of Computer Graphics and Image Processing

Visibility, Culling, Clipping (05)

  • RNDr. Martin Madaras, PhD.

martin.madaras@stuba.sk

slide-2
SLIDE 2

2

 Clipping

 Point Clipping  Line Clipping  Polygon Clipping

 Hidden Surface Removal

Overview

slide-3
SLIDE 3

3D rendering pipeline

3

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Rasterization (05)

Clip polygons outside of camera’s view

slide-4
SLIDE 4

4

  • Ask questions, please!!!
  • Be communicative
  • www.slido.com #PPGSO05
  • More active you are, the better for you!

How the lectures should look like #1

slide-5
SLIDE 5

2D rendering pipeline

5

2D geometry Clipping Viewport Transformation Scan Conversion 2D Image

 Clip and remove geometry outside of the

window

 Transform from screen coordinates to image

coordinates

 Fill pixels on the screen

slide-6
SLIDE 6

2D rendering pipeline

6

2D geometry Clipping Viewport Transformation Scan Conversion 2D Image

 Clip and remove geometry outside of the

window

 Transform from screen coordinates to image

coordinates

 Fill pixels on the screen

slide-7
SLIDE 7

7

 Avoid drawing parts of primitives outside window

 Window defines part of scene being viewed  Must draw geometric primitives only inside window

Screen Coordinates

Clipping

slide-8
SLIDE 8

8

 Avoid drawing parts of primitives outside window

 Window defines part of scene being viewed  Must draw geometric primitives only inside window

Clipping

slide-9
SLIDE 9

9

 Avoid drawing parts of primitives outside window

 Points, Lines, Polygons, Circles etc.

Clipping

slide-10
SLIDE 10

10

 Is point (x,y) inside clip window ?

Point Clipping

slide-11
SLIDE 11

11

 Find the part of a line inside the clip window Before Clipping

Line Clipping

slide-12
SLIDE 12

12

 Find the part of a line inside the clip window After Clipping

Line Clipping

slide-13
SLIDE 13

13

 Use simple test to classify easy cases first  Danny Cohen, Ivan Sutherland 1967

Cohen-Shutherland Line Clipping

slide-14
SLIDE 14

14

 Classify lines quickly by AND of bit codes representing

regions of two endpoints (test for 0)

Cohen-Shutherland Line Clipping

slide-15
SLIDE 15

15

 Classify lines quickly by AND of bit codes representing

regions of two endpoints (test for 0)

Cohen-Shutherland Line Clipping

slide-16
SLIDE 16

16

 Classify lines quickly by AND of bit codes representing

regions of two endpoints (test for 0)

Cohen-Shutherland Line Clipping

slide-17
SLIDE 17

17

 Compute intersections with window boundary for

remaining lines

Cohen-Shutherland Line Clipping

slide-18
SLIDE 18

18

 Intersect with boundary determined by the bits of the

non zero point

Cohen-Shutherland Line Clipping

slide-19
SLIDE 19

19

 Create new point on the boundary

Cohen-Shutherland Line Clipping

slide-20
SLIDE 20

20

 Check using the AND operation again

Cohen-Shutherland Line Clipping

slide-21
SLIDE 21

21

 Do the same for the next line

Cohen-Shutherland Line Clipping

slide-22
SLIDE 22

22

 Clip using the boundary determined by P7

Cohen-Shutherland Line Clipping

slide-23
SLIDE 23

23

 Clip using the boundary determined by P7

Cohen-Shutherland Line Clipping

slide-24
SLIDE 24

24

 Clip using the boundary determined by P8

Cohen-Shutherland Line Clipping

slide-25
SLIDE 25

25

 Test the line again using AND

Cohen-Shutherland Line Clipping

slide-26
SLIDE 26

26

 Again for the last line

Cohen-Shutherland Line Clipping

slide-27
SLIDE 27

27

 P9 AND P10 no longer zero

Cohen-Shutherland Line Clipping

slide-28
SLIDE 28

28

 Final result

Cohen-Shutherland Line Clipping

slide-29
SLIDE 29

29

 Find the part of a polygon inside the clip window? Before Clipping

Polygon Clipping

slide-30
SLIDE 30

30

 Find the part of a polygon inside the clip window? After Clipping

Polygon Clipping

slide-31
SLIDE 31

31

 Clip to each window boundary one at a time

Sutherland–Hodgman Clipping

slide-32
SLIDE 32

32

 Clip to each window boundary one at a time

Sutherland–Hodgman Clipping

slide-33
SLIDE 33

33

 Clip to each window boundary one at a time

Sutherland–Hodgman Clipping

slide-34
SLIDE 34

34

 Clip to each window boundary one at a time

Sutherland–Hodgman Clipping

slide-35
SLIDE 35

35

 Clip to each window boundary one at a time

Sutherland–Hodgman Clipping

slide-36
SLIDE 36

36

 Do inside test for each point in sequence  Insert new points when crossing the boundary  Remove points outside of boundary

Clipping to a Boundary

slide-37
SLIDE 37

37

 Do inside test for each point in sequence  Insert new points when crossing the boundary  Remove points outside of boundary

Clipping to a Boundary

slide-38
SLIDE 38

38

 Do inside test for each point in sequence  Insert new points when crossing the boundary  Remove points outside of boundary

Clipping to a Boundary

slide-39
SLIDE 39

39

 Do inside test for each point in sequence  Insert new points when crossing the boundary  Remove points outside of boundary

Clipping to a Boundary

slide-40
SLIDE 40

40

 Do inside test for each point in sequence  Insert new points when crossing the boundary  Remove points outside of boundary

Clipping to a Boundary

slide-41
SLIDE 41

41

 Do inside test for each point in sequence  Insert new points when crossing the boundary  Remove points outside of boundary

Clipping to a Boundary

slide-42
SLIDE 42

42

 Do inside test for each point in sequence  Insert new points when crossing the boundary  Remove points outside of boundary

Clipping to a Boundary

slide-43
SLIDE 43

43

 Do inside test for each point in sequence  Insert new points when crossing the boundary  Remove points outside of boundary

Clipping to a Boundary

slide-44
SLIDE 44

44

 Do inside test for each point in sequence  Insert new points when crossing the boundary  Remove points outside of boundary

Clipping to a Boundary

slide-45
SLIDE 45

2D rendering pipeline

45

2D geometry Clipping Viewport Transformation Scan Conversion 2D Image

 Clip and remove geometry outside of the

window

 Transform from screen coordinates to image

coordinates

 Fill pixels on the screen

slide-46
SLIDE 46

46

 Window to viewport mapping

Viewport Transformation

slide-47
SLIDE 47

47

 Clipping

 Point Clipping  Line Clipping  Polygon Clipping

 Hidden Surface Removal

Overview

slide-48
SLIDE 48

48

wireframe model front faces silhouette visible faces, edges

Visibility

slide-49
SLIDE 49

49

 Surfaces may be back-facing  Surfaces may be occluded  Surfaces may overlap in the image plane  Surfaces may intersect

Motivation

slide-50
SLIDE 50

3D rendering pipeline

50

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

 Somewhere here we have to determine

which objects are visible and which are hidden

slide-51
SLIDE 51

51

 Clipping

 Point Clipping  Line Clipping  Polygon Clipping

 Hidden Surface Removal

Basic algorithms for HSR

slide-52
SLIDE 52

52

 Get rid of objects that are surely not visible  Frustum culling  Occlusion culling  Back-face culling

Optimizing visibility

slide-53
SLIDE 53

53

 6 planes

 Inside = visible volume

 Is a point is inside?  Object

bounding box

 Speed up

Frustum culling

slide-54
SLIDE 54

54

 Some objects are fully occluded by others  Spatial relations between objects  Portals, occlusion culling  Realtime rendering

Occlusion culling

slide-55
SLIDE 55

55

 Which object faces are visible?  Remember normal vector (face orientation)

Back-face culling

slide-56
SLIDE 56

56

 Some parts of the scene

are not visible from some

  • ther parts of the scene

Portal culling

slide-57
SLIDE 57

57

Optimizing visibility

slide-58
SLIDE 58

58

 Back-face culling  Depth sort  Z-Buffer

Basic algorithms for HSR

slide-59
SLIDE 59

59

 How do we test back-facing polygons ?  Dot product the normal and view direction

Back-face culling

𝑂•V > 0

slide-60
SLIDE 60

60

 Normal

 Cross product of surface tangent vectors  Length normalized to 1

Surface Normals

slide-61
SLIDE 61

61

 Dot product the normal and view direction  Fragment normals can be interpolated from vertex normals

Vertex / Fragment Normals

slide-62
SLIDE 62

3D rendering pipeline

62

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

 Back-face culling  Remove all polygons that are back-facing

slide-63
SLIDE 63

63

 “Painter’s algorithm”  Sort surfaces by maximum depth  Draw surfaces in back to front order

Depth sort

slide-64
SLIDE 64

64

 Sort faces in a back-to-front order, render  New pixels over-write

  • ld pixels

Painter’s algorithm

slide-65
SLIDE 65

65

 Intersecting faces  Cyclically overlapping faces  Redundant rendering

Painter’s algorithm problems

slide-66
SLIDE 66

3D rendering pipeline

66

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

 Sorting is often O(n log n)  Usually software only  Mostly using BSP-trees

Depth sort

slide-67
SLIDE 67

67

 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

Other algorithms

slide-68
SLIDE 68

68

 Also known as depth buffering  Stores closest depth of objects for every pixel

 Draw only pixels with less depth  Depths are interpolated between vertices

Z-Buffer

slide-69
SLIDE 69

69

 works in screen space  z-buffer w×h

 for each 0≤x≤w,0≤y≤h: z-buffer[x,y] ←

zmin for each face: rasterize it into pixels {x,y,z} for each face’s pixel (x,y,z): if z > z-buffer[x,y] then : z-buffer[x,y] ← z and screen[x,y] ← face color

Z-Buffer

slide-70
SLIDE 70

70

 GPU support  precision issues might occur  z-buffer test before per-pixel-lighting or pixel shading

saves a lot of redundant work

 memory demands (width×height×precision)

 can be reduced by scanline (width×1×precision)

Z-buffer pros and cons

slide-71
SLIDE 71

71

Z-Buffer

slide-72
SLIDE 72

3D rendering pipeline

72

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

 Sorting not needed  Excellent for hardware  Requires additional memory to store

the depth values

 Subject to aliasing  Z-Buffer

slide-73
SLIDE 73

73

 Can be solved in different ways

 Painter’s algorithm / Depth sort

 Binary space partitioning (BSP)  Warnock algorithm (Quadtree)

 Z-buffering  Raycasting / Raytracing

Visibility

slide-74
SLIDE 74

74

 Viewing-frustum culling  Back-face culling  Contribution culling (LoD)  Occlusion culling

 Potentially visible set (PVS)  Portal rendering

Culling

slide-75
SLIDE 75

75

T extures and Mappings

Next Week

slide-76
SLIDE 76

76

Acknowledgements

 Thanks to all the people, whose work is shown here and whose

slides were used as a material for creation of these slides:

Matej Novotný, GSVM lectures at FMFI UK Peter Drahoš, PPGSO lectures at FIIT STU

slide-77
SLIDE 77

77

www.slido.com #PPGSO05 martin.madaras@stuba.sk

Questions ?!