30
CGRA 408 Primitives and Acceleration Structure Week 5.2

Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

CGRA 408

Primitives and Acceleration Structure

Week 5.2

Page 2: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Course Schedule (CGRA408 2020T1)

Week Monday Wednesday Friday Note1 (Mar 2,4,6) Course Outline Ray Tracing Overview I Ray Tracing Overview II

Project 1 instruction

2 (Mar 9,11,13) PBRT Intro Shape Intersection P: Ray tracing (Robert)

3 (Mar 16,18,20) T: Blender/Maya (CO332, Graphics Lab)

Camera models P: Lens (Marc)

4 (Apr/M. 27,29,1) Anzac Day observed Course Recap and updates Primitive Acceleration

5 (May 4,6,8) Project 1 presentationProject 3 instruction

Texture I (Image Texture) Texture II (Procedural Texture)Project 1 code/report due

Project 1

6 (May 11,13,15) P: Scene (Wenbo) P: Lens (Anna) Project 3 helpdesk

7 (May 18, 20, 22) Radiometry 1 Radiometry 2 P: Composition (Henry)

8 (May 25,27,29) P: Rendering (Wenbo) P: BRDF (Anna) Project 3 helpdesk

9 (June 1,3,5) Queen's Birthday Reflection Models P: Rendering (Marc)

10 (June 8,10,12) Monte Carlo Integration P: Rendering (Robert) Project 3 helpdesk

11 (June 15,17,19) Path tracing P: Participating Media (Henry)

Project 3 presentation Project 3

12 (June 22,24,26)Wrap upProject 3 code/report due

P: Student presentationT : TutorialG : Guest Lecture

Page 3: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Primitives● The Shape class provides geometry operation

§ Intersection, bounding§ But does not support enough information for materials

● GeometricPrimitive class binds appearance properties (e.g. material properties) with geometry shapes

● TransformedPrimitive class handles animated transformation matrices and object instancing§ Instancing save memory for

many instances of same geometry at different location

● Aggregate class hold manyprimitives§ E.g. Acceleration structure

3[ PBR book ]

Page 4: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Primitives● Primitive class is the bridge btw geometry processing

and shading subsystem of PBRT● It inherits from a “ReferenceCounted” base class

§ Automatically tracks the num of references of an object§ Other class storing primitives should hold reference

(32 bit identifier) rather than having pointer of the primitivesü The reference is used for instancing

§ The class contains methods for both shape and shadingü Five geometric routines corresponded with shape classü WorldBound(), CanIntersect(), Intersect(), IntersectP(), Refine()ü E.g. Primitive::CanIntersect() returns intersection structures

(hold material properties at the hit as well as the local geometric structure)

4

Page 5: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Non-Geometric Primitives● Primitive object has three methods not related to

the geometric methods§ GetAreaLight() : return a pointer of an emissive primitive

ü If the primitive is emissive, return the pointerü If not, return null

§ GetBSDF() : return BSDF object ü local scattering at the intersection point

§ GetBSSRDF() : return BSSRDF object ü sub surface scattering inside the primitive such as skin, milk, etc

5

Page 6: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Geometric Primitive● The GeometricPrimitive class represents a single shape

(e.g. sphere) in a scene§ Holds reference to a shape, material, area light

<GeometricPrimitive Declarataions> =Class GeometricPrimitive:public Primitive {Public:

<GeometricPrimitive Public Methods 188>Private:

Reference<Shape> shape;Reference<Material> material;AreaLight *areaLight;

}

§ Most of the geometric method are simply forwarded to corresponding Shape methodü GeometricPrimitive::Intersect() à Shape::Intersect()

6

Page 7: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Object Instancing, Animated Primitives

● TransformPrimitive class holds a single primitive and related transform§ The transform is used for object instancing and

primitives with animated transforms§ Object instancing

ü Reuses a single object in many different locations while varying its transformations (e.g. Seats in the concert hall)

ü 19.5 million tri. à 1.1 million tri.ü 11GB à 600MB

§ Animated transformsü Rigid body animation in the scene

during shutter open/off

7

Page 8: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Acceleration Structure● One of the core parts of ray tracing

§ Without acceleration algorithm, tracing single ray will be linear in the number of primitives

§ The goal is quick and simultaneous rejection of unnecessary groups of primitives

§ Spatial subdivision vs Object subdivisionü Cannot tell which one is better : good topic to debate

§ Spatial subdivision : GridAceel, KD Treeü Divide 3D scene into regions and check intersection

hierarchically by the sub-regions§ Object subdivision : BVH

ü Divide object and check intersection hierarchically by the sub objects (e.g. room à chair à legs à …)

8

Page 9: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Acceleration Structure● Aggregate class provides an interface for

grouping multiple primitive objects● It handle acceleration structures

§ Inherited from Primitive class§ Return intersection between ray and the primitive that

the aggregates holds (not aggregate itself)§ Do not call Aggregate::GetAreaLight,

Aggregate::GetBSDF(), and Aggregate::GetBSSRDF()à They will show runtime error

9

Page 10: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Axis-Aligned Bound Box● AABB is commonly used to enclose complex object

§ All the accelerators in the PBRT store Bbox§ If ray misses the AABB, it miss all the primitives inside it

● AABBs are aligned with the principal axes of a coordinate system§ It simplifies intersection tests§ It simplifies representation

ü 6 constantü (xmin, xmax) (ymin, ymax) (zmin, zmax)

10

Attention: Ray-Box Intersection

Page 11: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Grid Accelerator● It divides an axis-aligned region of space into

equal-sized box shapes (voxels)§ Each voxel stores reference to the primitives to overlap§ Ray advance through the

the voxels that ray passesthroughü Check intersection only with

the primitives at the passing voxels

§ Simple to make structure

11

Page 12: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Grid Accelerator● Pros

§ Simple to create structure§ Simple to determines the sequences of voxels through

● Cons§ Biased distribution may suffer from poor performance

ü A teapot in the stadium problem§ Data structure cannot adapt well to the distribution

ü Too fine grid cause longer time for stepping through empty space

ü Too coarse grid causes little benefit to make a grid at all

12

Page 13: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Mail-boxing● A Primitive may overlap many grid voxels and

thus may be tested multiple times with a ray ● To avoid, each object stores a reference to the

last ray that has been tested (Mail-boxing)1. A ray r is tested with C.

C store reference to r2. Ray r is tested with A B

but not tested with Csince C store rà A,B store reference to r

3. Ray r is not tested with A,Bsince A,B stores r

13

1 2 3

Page 14: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

BVH● Bounding Volume Hierarchies

§ It is based on the primitive subdivisionü Primitives are hierarchically partitioned into disjoint setsü Primitives are stored in the leavesü Each node stores a bbox of the primitives in the nodes beneath it

à If a ray does not intersect with the node, it does not intersect primitives beneath the node.

14

Page 15: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

BVH● Property of BVH

§ Each primitive appears in the hierarchy only onceü But a primitive may be overlap in many grid voxelsü A ray may be tested multiple times

à Mail-boxing may avoid it

§ A number of nodes to be stored for binary BVH is 2n-1ü BVH stores a primitive in each leaf ü n leaf nodes and n-1 interior nodes (n is num of primitives)ü If leaves store multiple primitives, fewer nodes are needed

§ Building the structure is fast§ Handle irregular distributions efficiently

15

Page 16: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

BVH construction● Three stages

1. Bounding information for each primitive is computed and stored in an array

2. The tree is built while splitting the primitive into subset and recursively do for the sub-subsetü The results will be a binary tree ü Interior hold pointers to children ü Each leaf hold one or more primitives

3. The tree is converted into more compact pointerlessstructure while rendering

16

Page 17: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

BVH construction● Goals

§ Balanced tree§ Minimal size bounding volumes in the interior nodes§ Minimal overlap between the bounding volumes

● Strategies§ Grouping primitives, which are close to each other

ü Sort the primitives

§ Split primitives into groups with similar number of primitives

17

Page 18: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

BVH Traverse● Compact BVH for traversal

§ Convert BVH into a compact representation§ The final BVH is stored in a linear array

ü The original tree is laid out in depth first orderü The first child is found immediately ü The second child is linked with offset pointer (leaf has no children)

18

Page 19: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

BVH Traverse● Depth first search

If 1 is hitproceed with 2

otherwiseproceed with null

If 2 is hitproceed with 4…

otherwiseproceed with 3

19

1

2

34 5

6

7

Page 20: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

BVH Traverse● Depth first search

If 1 is hitproceed with 2

otherwiseproceed with null

If 2 is hitproceed with 4

otherwiseproceed with 3

If 3 is hitproceed with 6

otherwiseproceed with null

20

7

1

23

45

6

7

Page 21: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

BSP Trees● Binary Space Partitioning Trees

§ Adaptively subdivide space into irregular sized regionsü Start with a bounding box encompassing the entire sceneü If num of primitives are greater than threshold, split the box in a halfü If a primitive is associated with both of them, they will be assigned in

to both regions: in BVH, a primitive is only assigned into one groupü Continue recursively until

1) each leaf node contains sufficient number of primitives or2) maximum depth is reached

§ Two variation of BSP trees are KD tree and Octreeü KD tree: split a plane perpendicular to one of the coordinate axisü Octree: use three axis-perpendicular planes to split the box into eight

region at each step.

21

Page 22: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

KD-tree● KD-Tree is built by recursive splitting the

bounding box of the scene geometry along one of the coordinate axes§ X-axis§ Y-axis§ Z-axis

● Issues to be considered§ Which axis to split ?§ Where to split ?§ When to terminate ?

22

Page 23: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

KD-tree● KD-Tree is a binary tree

§ Each interior node always has both children§ Each interior node must provide

ü Split axis : which of x, y, or z was splitü Split position : position of the splitting plane along axisü Children : pointer to two child nodes

§ Each leaf node records primitives overlap it

23

Page 24: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

KD-tree construction● KD-tree is built with a recursive top-down

§ While the number of primitives are less than a threshold§ While the tree depth is less than a threshold

ü 8 + 1.3 log (N) is a reasonable maximum depth by experiment

§ Leaf node are created when reach the above thresholds

24

Page 25: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

KD-tree construction

25https://www.geeksforgeeks.org/k-dimensional-tree/

Consider following points in a 2-D plane: (3, 6), (17, 15), (13, 15), (6, 12), (9, 1), (2, 7), (10, 19) :

Creation of a 2-D Tree: 1. Insert (3, 6): Since tree is empty, make it the root node.2. Insert (17, 15): Compare it with root node point. Since root node is X-aligned, the X-coordinate value will be compared to determine if it lies in the left subtree or in the right subtree. This point will be Y-aligned.3. Insert (13, 15): X-value of this point is greater than X-value of point in root node. So, this will lie in the right subtree of (3, 6). Again Compare Y-value of this point with the Y-value of point (17, 15). Since, they are equal, this point will lie in the right subtree of (17, 15). This point will be X-aligned.4. Insert (6, 12): X-value of this point is greater than X-value of point in root node. So, this will lie inthe right subtree of (3, 6). Again Compare Y-value of this point with the Y-value of point (17, 15). Since, 12 < 15, this point will lie in the left subtree of (17, 15). This point will be X-aligned.5. Insert (9, 1): Similarly, this point will lie in the right of (6, 12).6. Insert (2, 7): Similarly, this point will lie in the left of (3, 6).7. Insert (10, 19): Similarly, this point will lie in the left of (13, 15).

Space partitioning:1. Point (3, 6) will divide the space into

two parts: Draw line X = 3.2. Point (2, 7) will divide the space to th

e left of line X = 3 into two parts horizontally. Draw line Y = 7 to the left of line X = 3.

3. Point (17, 15) will divide the space to the right of line X = 3 into two parts horizontally. Draw line Y = 15 to the right of line X = 3.

4. etc.

Page 26: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

KD-tree traverse● A ray intersects with the trees’ overall bound

§ Compute [tmin, tmax]§ If the ray misses the scene bounds, return false§ Otherwise process children from the root

● Ray enters near child in [tmin, tsplit] § If the node is leaf

ü Ray-primitive intersection test

§ Otherwise process children ● If no hit, or a hit found in [tsplit, tmax]

§ Process far child

● This sequence continues§ Process nodes in a depth-first order § Until find ray-primitive intersection

or no spaces to process

26

Page 27: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Octree Construction● Subdivide a scene with eight sub-blocks using

three planes● Continue recursively until

1) each leaf node contains sufficient number of primitives OR2) maximum depth is reached

27

Page 28: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Octree Traverse● Depth-First Search

§ If the node does not contain primitivesskip the block and entire children

§ Otherwise, process the children until find ray-primitive intersection or no spaces to process

28

Page 29: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

Summary● Good acceleration structure can minimize

intersection by efficient skipping the large parts of unnecessary region§ Grid-Accel§ BVH§ KD-Tree§ Octree

● They have pros and cons§ Irregular grid structure is usually better than regular

grid structure : teapot in a stadium§ Short Answer ?

ü It depends on your application

29

Page 30: Primitives and Acceleration Structureecs.wgtn.ac.nz/foswiki/pub/Courses/CGRA408...Course Schedule(CGRA408 2020T1) Week Monday Wednesday Friday Note 1 (Mar 2,4,6) Course Outline Ray

ReadingReading: ● PBRT book: Primitives and Intersection Acceleration ● Dynamic Scene

§ Ingo Wald et al. “Ray Tracing Deformable Scenes using Dynamic Bounding Volume Hierarchies”

§ Maxim Shevtsov et al. “Highly Parallel Fast KD-tree Construction for Interactive Ray Tracing for Dynamic Scenes”

● Bounding Interval Hierarchy § Carsten Wachter et al. “Instant Ray Tracing: The

bounding interval hierarchy (BIH)”

30