Lecture 5 - The Perfect BVH Welcome! , = (, ) , - - PowerPoint PPT Presentation

β–Ά
lecture 5 the perfect bvh
SMART_READER_LITE
LIVE PREVIEW

Lecture 5 - The Perfect BVH Welcome! , = (, ) , - - PowerPoint PPT Presentation

INFOMAGR Advanced Graphics Jacco Bikker - November 2019 - February 2020 Lecture 5 - The Perfect BVH Welcome! , = (, ) , + , , ,


slide-1
SLIDE 1

𝑱 π’š, π’šβ€² = 𝒉(π’š, π’šβ€²) 𝝑 π’š, π’šβ€² + ΰΆ±

𝑻

𝝇 π’š, π’šβ€², π’šβ€²β€² 𝑱 π’šβ€², π’šβ€²β€² π’†π’šβ€²β€²

INFOMAGR – Advanced Graphics

Jacco Bikker - November 2019 - February 2020

Lecture 5 - β€œThe Perfect BVH”

Welcome!

slide-2
SLIDE 2

Today’s Agenda:

β–ͺ Building Better BVHs β–ͺ Refitting β–ͺ Fast BVH Construction β–ͺ The Top-level BVH

slide-3
SLIDE 3

Better BVHs

Advanced Graphics – The Perfect BVH 3

slide-4
SLIDE 4

Better BVHs

Advanced Graphics – The Perfect BVH 4

slide-5
SLIDE 5

Better BVHs

Advanced Graphics – The Perfect BVH 5

What Are We Trying To Solve?

A BVH is used to reduce the number of ray/primitive intersections. But: it introduces new intersections. The ideal BVH minimizes: β–ͺ # of ray / primitive intersections β–ͺ # of ray / node intersections.

slide-6
SLIDE 6

Better BVHs

Advanced Graphics – The Perfect BVH 6

slide-7
SLIDE 7

Better BVHs

Advanced Graphics – The Perfect BVH 7

BVH versus kD-tree

The BVH better encapsulates geometry. βž” This reduces the chance of a ray hitting a node. βž” This is all about probabilities! What is the probability of a ray hitting a random triangle? What is the probability of a ray hitting a random node? This probability is proportional to surface ar area.

slide-8
SLIDE 8

Better BVHs

Advanced Graphics – The Perfect BVH 8

Route 1: 10% up-time, $1000 fine Route 2: 100% up-time, $100 fine

slide-9
SLIDE 9

Better BVHs

Advanced Graphics – The Perfect BVH 9

Optimal Split Plane Position

The ideal split minimizes the expected cost of a ray intersecting the resulting nodes. This expected cost is based on: β–ͺ Number of primitives that will have to be intersected β–ͺ Probability of this happening The cost of a split is thus: π΅π‘šπ‘“π‘”π‘’ βˆ— π‘‚π‘šπ‘“π‘”π‘’ + π΅π‘ π‘—π‘•β„Žπ‘’ βˆ— π‘‚π‘ π‘—π‘•β„Žπ‘’

slide-10
SLIDE 10

Better BVHs

Advanced Graphics – The Perfect BVH 10

Optimal Split Plane Position

The ideal split minimizes the expected cost of a ray intersecting the resulting nodes. This expected cost is based on: β–ͺ Number of primitives that will have to be intersected β–ͺ Probability of this happening The cost of a split is thus: π΅π‘šπ‘“π‘”π‘’ βˆ— π‘‚π‘šπ‘“π‘”π‘’ + π΅π‘ π‘—π‘•β„Žπ‘’ βˆ— π‘‚π‘ π‘—π‘•β„Žπ‘’

slide-11
SLIDE 11

Better BVHs

Advanced Graphics – The Perfect BVH 11

Optimal Split Plane Position

Or, more concisely: π΅π‘šπ‘“π‘”π‘’ βˆ— π΅π‘šπ‘“π‘”π‘’

1

βˆ— π‘‚π‘šπ‘“π‘”π‘’

1

+ π΅π‘ π‘—π‘•β„Žπ‘’

1

βˆ— π‘‚π‘ π‘—π‘•β„Žπ‘’

1

+ π΅π‘ π‘—π‘•β„Žπ‘’ βˆ— π΅π‘šπ‘“π‘”π‘’

2

βˆ— π‘‚π‘šπ‘“π‘”π‘’

2

+ π΅π‘ π‘—π‘•β„Žπ‘’

2

βˆ— π‘‚π‘ π‘—π‘•β„Žπ‘’

2

slide-12
SLIDE 12

Better BVHs

Advanced Graphics – The Perfect BVH 12

Optimal Split Plane Position

Which positions do we consider? Object subdivision may happen over x, y or z axis. The cost function is constant between primitive centroids. βž” For N primitives: 3(𝑂 βˆ’ 1) possible locations βž” For a 2-level tree: (3(𝑂 βˆ’ 1))2 configurations

slide-13
SLIDE 13

Better BVHs

Advanced Graphics – The Perfect BVH 13

SAH and Termination

A split is β€˜not worth it’ if it doesn’t yield a cost lower than the cost of the parent node, i.e.: π΅π‘šπ‘“π‘”π‘’ βˆ— π‘‚π‘šπ‘“π‘”π‘’ + π΅π‘ π‘—π‘•β„Žπ‘’ βˆ— π‘‚π‘ π‘—π‘•β„Žπ‘’ β‰₯ 𝐡 βˆ— 𝑂 This provides us with a natural and

  • ptimal termination criterion.

(and it solves the problem

  • f the Bad Artist)
slide-14
SLIDE 14

Better BVHs

Advanced Graphics – The Perfect BVH 14

Optimal Split Plane Position

Evaluating (3(𝑂 βˆ’ 1))2 configurations? Solution: apply the surface area heuristic (SAH) in a greedy manner*.

*: Heuristics for Ray Tracing using Space Subdivision, MacDonald & Booth, 1990.

slide-15
SLIDE 15

Better BVHs

Advanced Graphics – The Perfect BVH 15

Optimal Split Plane Position

Comparing naΓ―ve versus SAH: β–ͺ SAH will cut #intersections in half; β–ͺ expect ~2x better performance. SAH & kD-trees: β–ͺ Same scheme applies.

slide-16
SLIDE 16

Better BVHs

Advanced Graphics – The Perfect BVH 16

Median Split

slide-17
SLIDE 17

Better BVHs

Advanced Graphics – The Perfect BVH 17

Surface Area Heuristic

slide-18
SLIDE 18

Better BVHs

Advanced Graphics – The Perfect BVH 18

slide-19
SLIDE 19

Better BVHs

Advanced Graphics – The Perfect BVH 19

slide-20
SLIDE 20

Better BVHs

Advanced Graphics – The Perfect BVH 20

slide-21
SLIDE 21

Today’s Agenda:

β–ͺ Building Better BVHs β–ͺ Refitting β–ͺ Fast BVH Construction β–ͺ The Top-level BVH

slide-22
SLIDE 22

Refitting

Advanced Graphics – The Perfect BVH 22

Summary of BVH Characteristics

A BVH provides significant freedom compared to e.g. a kD-tree: β–ͺ No need for a 1-to-1 relation between bounding boxes and primitives β–ͺ Bounding boxes may overlap β–ͺ Bounding boxes can be altered, as long as they fit in their parent box β–ͺ A BVH can be very bad but still valid Some consequences / opportunities: β–ͺ We can rebuild part of a BVH β–ͺ We can combine two BVHs into one β–ͺ We can refit a BVH

slide-23
SLIDE 23

Refitting

Advanced Graphics – The Perfect BVH 23

Refitting

Q: What happens to the BVH of a tree model, if we make it bend in the wind? A: Likely, only bounds will change; the topology of the BVH will be the same (or at least similar) in each frame. Refitting: Updating the bounding boxes stored in a BVH to match changed primitive coordinates.

slide-24
SLIDE 24

Refitting

Advanced Graphics – The Perfect BVH 24

Refitting

Updating the bounding boxes stored in a BVH to match changed primitive coordinates. Algorithm:

  • 1. For each leaf, calculate the bounds
  • ver the primitives it represents
  • 2. Update parent bounds
slide-25
SLIDE 25

Refitting

Advanced Graphics – The Perfect BVH 25

Refitting - Suitability

slide-26
SLIDE 26

Refitting

Advanced Graphics – The Perfect BVH 26

Refitting – Practical

Order of nodes in the node array: We will never find the parent of node X at a position greater than X. Therefore:

for( int i = N-1; i >= 0; i-- ) nodeArray[i].AdjustBounds();

N-1 BVH node array Root node Level 1

slide-27
SLIDE 27

Today’s Agenda:

β–ͺ Building Better BVHs β–ͺ Refitting β–ͺ Fast BVH Construction β–ͺ The Top-level BVH

slide-28
SLIDE 28

Binning

Advanced Graphics – The Perfect BVH 28

Rapid BVH Construction

Refitting allows us to update hundreds of thousands of primitives in real-

  • time. But what if topology changes significantly?

Rebuilding a BVH requires 3π‘‚π‘šπ‘π‘•π‘‚ split plane evaluations. Options:

  • 1. Do not use SAH (significantly lower quality BVH)
  • 2. Do not evaluate all 3 axes (minor degradation of BVH quality)
  • 3. Make split plane selection independent of 𝑂
slide-29
SLIDE 29

Binning

Advanced Graphics – The Perfect BVH 29

slide-30
SLIDE 30

Binning

Advanced Graphics – The Perfect BVH 30

Binned BVH Construction* Binned construction: Evaluate SAH at N discrete intervals.

*: On fast Construction of SAH-based Bounding Volume Hierarchies, Wald, 2007

slide-31
SLIDE 31

Binning

Advanced Graphics – The Perfect BVH 31

Binned BVH Construction

Detailed algorithm: 1. Calculate spatial bounds 2. Calculate object centroid bounds 3. Calculate intervals (efficiently and accurately!) 4. Populate bins 5. Sweep: evaluate cost, keep track of counts 6. Use best position

slide-32
SLIDE 32

Binning

Advanced Graphics – The Perfect BVH 32

Binned BVH Construction

Performance evaluation: 472ms 7.88M triangles (12 cores @ 2Ghz)*.

*: Parallel BVH Construction using Progressive Hierarchical Refinement, Henrich et al., 2016.

slide-33
SLIDE 33

Binning

Advanced Graphics – The Perfect BVH 33

slide-34
SLIDE 34

Today’s Agenda:

β–ͺ Building Better BVHs β–ͺ Refitting β–ͺ Fast BVH Construction β–ͺ The Top-level BVH

slide-35
SLIDE 35

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 35

slide-36
SLIDE 36

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 36

slide-37
SLIDE 37

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 37

slide-38
SLIDE 38

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 38

Combining BVHs

slide-39
SLIDE 39

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 39

Combining BVHs

Two BVHs can be combined into a single BVH, by simply adding a new root node pointing to the two BVHs. β–ͺ This works regardless of the method used to build each BVH β–ͺ This can be applied repeatedly to combine many BVHs

slide-40
SLIDE 40

Advanced Graphics – Real-time Ray Tracing 40

Scene Graph

slide-41
SLIDE 41

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 41

Scene Graph

world car wheel wheel wheel wheel turret plane plane car wheel wheel wheel wheel turret buggy wheel wheel wheel wheel dude dude dude

slide-42
SLIDE 42

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 42

Scene Graph

If our application uses a scene graph, we can construct a BVH for each scene graph node. The BVH for each node is built using an appropriate construction algorithm: β–ͺ High-quality SBVH for static scenery (offline) β–ͺ Fast binned SAH BVHs for dynamic scenery The extra nodes used to combine these BVHs into a single BVH are known as the Top-level BVH .

slide-43
SLIDE 43

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 43

Rigid Motion

Applying rigid motion to a BVH:

  • 1. Refit the top-level BVH
  • 2. Refit the affected BVH
slide-44
SLIDE 44

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 44

Rigid Motion

Applying rigid motion to a BVH:

  • 1. Refit the top-level BVH
  • 2. Refit the affected BVH
  • r:
  • 2. Transform the ray, not the node

Rigid motion is achieved by transforming the rays by the inverse transform upon entering the sub-BVH.

(this obviously does not only apply to translation)

slide-45
SLIDE 45

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 45

The Top-level BVH - Construction

Input: list of axis aligned bounding boxes for transformed scene graph nodes Algorithm:

  • 1. Find the two elements in the list for which the AABB has the smallest

surface area

  • 2. Create a parent node for these elements
  • 3. Replace the two elements in the list by the parent node
  • 4. Repeat until one element remains in the list.

Note: algorithmic complexity is 𝑃(𝑂3).

slide-46
SLIDE 46

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 46

The Top-level BVH – Faster Construction*

Algorithm:

Node A = list.GetFirst(); Node B = list.FindBestMatch( A ); while (list.size() > 1) { Node C = list.FindBestMatch( B ); if (A == C) { list.Remove( A ); list.Remove( B ); A = new Node( A, B ); list.Add( A ); B = list.FindBestMatch( A ); } else A = B, B = C; }

*: Fast Agglomerative Clustering for Rendering, Walter et al., 2008

A B C A B A B

slide-47
SLIDE 47

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 47

The Top-level BVH – Traversal

The leafs of the top-level BVH contain the sub-BVHs. When a ray intersects such a leaf, it is transformed by the inverted transform matrix of the sub-BVH. After this, it traverses the sub-BVH. Once the sub-BVH has been traversed, we transform the ray again, this time by the transform matrix of the sub-BVH. For efficiency, we store the inverted matrix with the sub-BVH root.

slide-48
SLIDE 48

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 48

slide-49
SLIDE 49

Top-level BVH

Advanced Graphics – Real-time Ray Tracing 49

The Top-level BVH – Summary

The top-level BVH enables complex animated scenes: β–ͺ for static objects, it contains high-quality sub-BVHs; β–ͺ for objects undergoing rigid motion, it also contains high-quality sub-BVHs, with a transform matrix and its inverse; β–ͺ for deforming objects, it contains sub-BVHs that can be refitted; β–ͺ for arbitrary animations, it contains lower quality sub-BVHs. Combined, this allows for efficient maintenance of a global BVH.

slide-50
SLIDE 50

INFOMAGR – Advanced Graphics

Jacco Bikker - November 2019 - February 2020

END of β€œThe Perfect BVH”

next lecture: β€œPath Tracing”

slide-51
SLIDE 51

Practical:

  • 1. Converging
  • 2. Handling materials and textures