INFOGR Computer Graphics Jacco Bikker & Debabrata Panja - - - PowerPoint PPT Presentation

infogr computer graphics
SMART_READER_LITE
LIVE PREVIEW

INFOGR Computer Graphics Jacco Bikker & Debabrata Panja - - - PowerPoint PPT Presentation

INFOGR Computer Graphics Jacco Bikker & Debabrata Panja - April-July 2018 Lecture 13: Visibility Welcome! To world space: To camera space: Do nothing, or: 1. = 1 0 0 0


slide-1
SLIDE 1

INFOGR – Computer Graphics

Jacco Bikker & Debabrata Panja - April-July 2018

Lecture 13: “Visibility”

Welcome!

slide-2
SLIDE 2

world plane plane car 𝑈𝑞𝑚𝑏𝑜𝑓1 𝑈𝑑𝑏𝑠2 𝑈𝑞𝑚𝑏𝑜𝑓2 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 𝑼𝒙𝒑𝒔𝒎𝒆 =

1 0 0 𝑦𝑞𝑚𝑏𝑜𝑓 0 1 0 𝑧𝑞𝑚𝑏𝑜𝑓 0 0 1 𝑨𝑞𝑚𝑏𝑜𝑓 0 0 0 1 𝑼𝒒𝒎𝒃𝒐𝒇 =

To world space:

Do nothing, or: 𝑈

𝑥 = 𝑗𝑒𝑓𝑜𝑢𝑗𝑢𝑧 = 𝐽

𝑈

𝑥 = 𝑈𝑚𝑝𝑑𝑏𝑚 ∗ 𝑈𝑥_𝑞𝑏𝑠𝑓𝑜𝑢

To camera space:

1. 𝑈

𝑑 = 𝑗𝑜𝑤 𝑈 𝑑𝑏𝑛

2. Render ‘world’ with 𝐽, 𝑈

𝑑

3. Render children 1. 𝑈

𝑑 = 𝑈𝑚𝑝𝑑𝑏𝑚 ∗ 𝑈𝑑_𝑞𝑏𝑠𝑓𝑜𝑢

2. 𝑈

𝑥 = 𝑈𝑚𝑝𝑑𝑏𝑚 ∗ 𝑈𝑥_𝑞𝑏𝑠𝑓𝑜𝑢

3. Render ‘plane’ with 𝑈

𝑥, 𝑈 𝑑

4. Render children void SGNode::Render( mat4 𝑈𝑥𝑞𝑏𝑠𝑓𝑜𝑢, mat4 𝑈𝑑𝑞𝑏𝑠𝑓𝑜𝑢 ) { mat4 𝑈

𝑥 = 𝑈𝑚𝑝𝑑𝑏𝑚 * 𝑈𝑥𝑞𝑏𝑠𝑓𝑜𝑢;

mat4 𝑈

𝑑 = 𝑈𝑚𝑝𝑑𝑏𝑚 * 𝑈𝑑𝑞𝑏𝑠𝑓𝑜𝑢;

mesh.Draw( 𝑈

𝑥, 𝑈 𝑑 );

for each child: Draw( 𝑈

𝑥, 𝑈 𝑑 );

}

slide-3
SLIDE 3

Today’s Agenda:

▪ Depth Sorting ▪ Clipping ▪ Visibility

slide-4
SLIDE 4

Rendering – Functional overview

  • 1. Transform:

translating / rotating meshes

  • 2. Project:

calculating 2D screen positions

  • 3. Rasterize:

determining affected pixels

  • 4. Shade:

calculate color per affected pixel Transform Project Rasterize Shade meshes vertices vertices fragment positions pixels

Animation, culling, tessellation, ... Postprocessing

Depth Sorting

INFOGR – Lecture 13 – “Visibility” 4

slide-5
SLIDE 5
  • 3. Rasterize:

determining affected pixels Questions: ▪ What is the screen space position of the fragment? ▪ Is that position actually on-screen? ▪ Is the fragment the nearest fragment for the affected pixel? How do we efficiently determine visibility of a pixel? Transform Project Rasterize Shade meshes vertices vertices fragment positions pixels

Animation, culling, tessellation, ... Postprocessing

Depth Sorting

INFOGR – Lecture 13 – “Visibility” 5

slide-6
SLIDE 6

Too far away to draw Part of the tree is off-screen Torso closer than ground City obscured by tree Tree requires little detail Tree between ground & sun

slide-7
SLIDE 7

Old-skool depth sorting: Painter’s Algorithm ▪ Sort polygons by depth ▪ Based on polygon center ▪ Render depth-first Advantage: ▪ Doesn’t require z-buffer Problems: ▪ Cost of sorting ▪ Doesn’t handle all cases ▪ Overdraw

Depth Sorting

INFOGR – Lecture 13 – “Visibility” 7

slide-8
SLIDE 8

Depth Sorting

Overdraw: Inefficiency caused by drawing multiple times to the same pixel. INFOGR – Lecture 13 – “Visibility” 8

slide-9
SLIDE 9

Depth Sorting

Overdraw: Inefficiency caused by drawing multiple times to the same pixel. INFOGR – Lecture 13 – “Visibility” 9

slide-10
SLIDE 10

Depth Sorting

Overdraw: Inefficiency caused by drawing multiple times to the same pixel. INFOGR – Lecture 13 – “Visibility” 10

slide-11
SLIDE 11

Depth Sorting

Overdraw: Inefficiency caused by drawing multiple times to the same pixel. INFOGR – Lecture 13 – “Visibility” 11

slide-12
SLIDE 12

Depth Sorting

Correct order: BSP root INFOGR – Lecture 13 – “Visibility” 12

slide-13
SLIDE 13

Depth Sorting

Correct order: BSP root

front back

INFOGR – Lecture 13 – “Visibility” 13

slide-14
SLIDE 14

Depth Sorting

Correct order: BSP root INFOGR – Lecture 13 – “Visibility” 14

front back

slide-15
SLIDE 15

Depth Sorting

Correct order: BSP root INFOGR – Lecture 13 – “Visibility” 15

front back

slide-16
SLIDE 16

Depth Sorting

Correct order: BSP root INFOGR – Lecture 13 – “Visibility” 16

front back

slide-17
SLIDE 17

Depth Sorting

Correct order: BSP root INFOGR – Lecture 13 – “Visibility” 17

front back

slide-18
SLIDE 18

Depth Sorting

Correct order: BSP root Sorting by BSP traversal: Recursively

  • 1. Render far side of plane
  • 2. Render near side of plane

INFOGR – Lecture 13 – “Visibility” 18

front back

slide-19
SLIDE 19

Draw order using a BSP: ▪ Guaranteed to be correct (hard cases result in polygon splits) ▪ No sorting required, just a tree traversal But: ▪ Requires construction of BSP: not suitable for dynamic objects ▪ Does not eliminate overdraw

Depth Sorting

INFOGR – Lecture 13 – “Visibility” 19

slide-20
SLIDE 20

Z-buffer A z-buffer stores, per screen pixel, a depth value. The depth of each fragment is checked against this value: ▪ If the fragment is further away, it is discarded ▪ Otherwise, it is drawn, and the z-buffer is updated. The z-buffer requires: ▪ An additional buffer ▪ Initialization of the buffer to 𝑨𝑛𝑏𝑦 ▪ Interpolation of 𝑨 over the triangle ▪ A z-buffer read and compare, and possibly a write.

Depth Sorting

INFOGR – Lecture 13 – “Visibility” 20

slide-21
SLIDE 21
slide-22
SLIDE 22

Z-buffer What is the best representation for depth in a z-buffer?

  • 1. Interpolated z (convenient, intuitive);
  • 2. 1/z (or: 𝑜 + 𝑔 − 𝑔𝑜

𝑨 ) (more accurate nearby);

  • 3. (int)((2^31-1)/z);
  • 4. (uint)((2^32-1)/-z);
  • 5. (uint)((2^32-1)/(-z + 1)).

Even more details: https://developer.nvidia.com/content/depth-precision-visualized http://outerra.blogspot.nl/2012/11/maximizing-depth-buffer-range-and.html

Depth Sorting

INFOGR – Lecture 13 – “Visibility” 22

Note: we use zint =

232−1 −𝑨+1 :

this way, any z < 0 will be in the range zadjusted = −𝑨𝑝𝑠𝑗𝑕𝑗𝑜𝑏𝑚 + 1 = 1. . ∞, therefore 1/𝑨𝑏𝑒𝑘𝑣𝑡𝑢𝑓𝑒 will be in the range 0..1, and thus the integer value we will store uses the full range of 0. . 232 − 1. Here, 𝑨𝑗𝑜𝑢 = 0 represents 𝑨𝑝𝑠𝑗𝑕𝑗𝑜𝑏𝑚 = 0, and 𝑨𝑗𝑜𝑢 = 232 − 1 represents 𝑨𝑝𝑠𝑗𝑕𝑗𝑜𝑏𝑚 = −∞.

slide-23
SLIDE 23

Z-buffer optimization In the ideal case, the nearest fragment for a pixel is drawn first: ▪ This causes all subsequent fragments for the pixel to be discarded; ▪ This minimizes the number of writes to the frame buffer and z-buffer. The ideal case can be approached by using Painter’s to ‘pre-sort’.

Depth Sorting

INFOGR – Lecture 13 – “Visibility” 23

slide-24
SLIDE 24

‘Z-fighting’: Occurs when two polygons have almost identical z-values. Floating point inaccuracies during interpolation will cause unpleasant patterns in the image.

Depth Sorting

INFOGR – Lecture 13 – “Visibility” 24

slide-25
SLIDE 25

Stuff that is too far to draw Part of the tree is off-screen √ Torso closer than ground √ City obscured by tree Tree requires little detail Tree between ground & sun

slide-26
SLIDE 26

Today’s Agenda:

▪ Depth Sorting ▪ Clipping ▪ Visibility

slide-27
SLIDE 27

Clipping Many triangles are partially off-screen. This is handled by clipping them. Sutherland-Hodgeman clipping: Clip triangle against 1 plane at a time; Emit n-gon (0, 3 or 4 vertices).

Clipping

INFOGR – Lecture 13 – “Visibility” 27

slide-28
SLIDE 28

Sutherland-Hodgeman Input: list of vertices Algorithm: Per edge with vertices v0 and v1: ▪ If v0 and v1 are ‘in’, emit v1 ▪ If v0 is ‘in’, but v1 is ‘out’, emit C ▪ If v0 is ‘out’, but v1 is ‘in’, emit C and v1 where C is the intersection point of the edge and the plane. Output: list of vertices, defining a convex n-gon.

Clipping

1 2 in

  • ut

Vertex 0 Vertex 1 Vertex 1 Intersection 1 Vertex 2 Intersection 2 Vertex 0 INFOGR – Lecture 13 – “Visibility” 28

slide-29
SLIDE 29

Sutherland-Hodgeman Calculating the intersections with plane 𝑏𝑦 + 𝑐𝑧 + 𝑑𝑨 + 𝑒 = 0: 𝑒𝑗𝑡𝑢𝑤 = 𝑤 ∙ 𝑏 𝑐 𝑑 + 𝑒 𝑔 = |𝑒𝑗𝑡𝑢𝑤0| |𝑒𝑗𝑡𝑢𝑤0| + |𝑒𝑗𝑡𝑢𝑤1| 𝐽 = 𝑤0 + 𝑔(𝑤1 − 𝑤0)

Clipping

v0 v1

I

After clipping, the input n-gon may have at most 1 extra vertex. We may have to triangulate it: 0,1,2,3,4 ➔ 0, 1, 2 + 0, 2, 3 + 0, 3, 4. INFOGR – Lecture 13 – “Visibility” 29

slide-30
SLIDE 30

Guard bands To reduce the number of polygons that need clipping, some hardware uses guard bands : an invisible band of pixels outside the screen. ▪ Polygons outside the screen are discarded, even if they touch the guard band; ▪ Polygons partially inside, partially in the guard band are drawn without clipping; ▪ Polygons partially inside the screen, partially outside the guard band are clipped.

Clipping

INFOGR – Lecture 13 – “Visibility” 30

slide-31
SLIDE 31

Sutherland-Hodgeman Clipping can be done against arbitrary planes.

Clipping

INFOGR – Lecture 13 – “Visibility” 31

slide-32
SLIDE 32

Today’s Agenda:

▪ Depth Sorting ▪ Clipping ▪ Visibility

slide-33
SLIDE 33

Stuff that is too far to draw √ Part of the tree is off-screen √ Torso closer than ground √ City obscured by tree Tree requires little detail Tree between ground & sun

slide-34
SLIDE 34
slide-35
SLIDE 35
slide-36
SLIDE 36

Visibility

Only rendering what’s visible: “Performance should be determined by visible geometry, not overall world size.” ▪ Do not render geometry

  • utside the view frustum

▪ Better: do not process geometry outside frustum ▪ Do not render occluded geometry ▪ Do not render anything more detailed than strictly necessary INFOGR – Lecture 13 – “Visibility” 36

slide-37
SLIDE 37

Visibility

Culling Observation: 50% of the faces of a cube are not visible. On average, this is true for all meshes. Culling ‘backfaces’: Triangle: 𝑏𝑦 + 𝑐𝑧 + 𝑑𝑨 + 𝑒 = 0 Camera: 𝑦, 𝑧, 𝑨 Visible: fill in camera position in plane equation. 𝑏𝑦 + 𝑐𝑧 + 𝑑𝑨 + 𝑒 > 0: visible. Cost

  • st: 1

1 dot dot pr product pe per r tri triangle. INFOGR – Lecture 13 – “Visibility” 37

slide-38
SLIDE 38

Visibility

Culling Observation: If the bounding sphere of a mesh is outside the view frustum, the mesh is not visible. But also: If the bounding sphere of a mesh intersects the view frustum, the mesh may be not visible. View frustum culling is typically a conservative test: we sacrifice accuracy for efficiency. Cost

  • st: 1

1 dot dot pr product pe per r mes esh. INFOGR – Lecture 13 – “Visibility” 38

slide-39
SLIDE 39

Visibility

Culling Observation: If the bounding sphere over a group of bounding spheres is outside the view frustum, a group of meshes is invisible. We can store a bounding volume hierarchy in the scene graph: ▪ Leaf nodes store the bounds of the meshes they represent; ▪ Interior nodes store the bounds over their child nodes. Cost

  • st: 1

1 dot dot pr product pe per r sce cene gr grap aph subtree. INFOGR – Lecture 13 – “Visibility” 39

slide-40
SLIDE 40

Visibility

INFOGR – Lecture 13 – “Visibility” 40 Culling Observation: If a grid cell is outside the view frustum, the contents of that grid cell are not visible. Cost

  • st: 0

0 for

  • r ou
  • ut-of
  • f-range gri

grid cel cells.

slide-41
SLIDE 41

Occlusion Culling Not rendering things that are guaranteed to be behind something else. Hierarchical z-buffer: a set of MIP-maps of the z-buffer. Use: with a small amount of tests, we can check the bounds of a mesh against this buffer. INFOGR – Lecture 13 – “Visibility” 41

Visibility

slide-42
SLIDE 42

Occlusion Culling Not rendering things that are guaranteed to be behind something else. Coverage buffer: A low-resolution version of (a simplified version of) the scene, rendered on the CPU, which we can use for visibility tests. INFOGR – Lecture 13 – “Visibility” 42

Visibility

Flipcode IOTD, 2000: https://www.flipcode.com/archives/10-18-2000.shtml

slide-43
SLIDE 43

Occlusion Culling Not rendering things that are guaranteed to be behind something else. Coverage buffer: A low-resolution version of (a simplified version of) the scene, rendered on the CPU, which we can use for visibility tests. INFOGR – Lecture 13 – “Visibility” 43

Visibility

Masked Software Occlusion Culling, Intel, 2016

slide-44
SLIDE 44

INFOGR – Lecture 13 – “Visibility” 44

Visibility

Occlusion Culling Not rendering things that are guaranteed to be behind something else. Potential Visibility Set: a table that tells us which areas are mutually visible.

slide-45
SLIDE 45

Visibility

Indoor visibility: Portals Observation: if a window is invisible, the room it links to is invisible. INFOGR – Lecture 13 – “Visibility” 45

slide-46
SLIDE 46

Welcome!

slide-47
SLIDE 47

Welcome!

slide-48
SLIDE 48

Welcome!

slide-49
SLIDE 49

Welcome!

slide-50
SLIDE 50

Welcome!

slide-51
SLIDE 51

Welcome!

slide-52
SLIDE 52

Welcome!

slide-53
SLIDE 53

Welcome!

slide-54
SLIDE 54

Welcome!

slide-55
SLIDE 55

Welcome!

slide-56
SLIDE 56

Welcome!

slide-57
SLIDE 57

Visibility determination Coarse: ▪ Grid-based (typically outdoor) ▪ Portals (typically indoor) Finer: ▪ Frustum culling ▪ Occlusion culling Finest: ▪ Backface culling ▪ Clipping ▪ Z-buffer

Visibility

INFOGR – Lecture 13 – “Visibility” 57

slide-58
SLIDE 58

Today’s Agenda:

▪ Depth Sorting ▪ Clipping ▪ Visibility

slide-59
SLIDE 59

INFOGR – Computer Graphics

Jacco Bikker & Debabrata Panja - April-July 2018

END OF lecture 13: “Visibility”

Next lecture: “Postprocessing”