BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp...

44
BSP Tree Supplement Jyun-Ming Chen

description

Fall 20053

Transcript of BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp...

Page 1: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

BSP Tree SupplementJyun-Ming Chen

Page 2: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 2

Kd-Tree and BSP treekd-tree is a special kind of bsp tree

Page 3: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 3

Page 4: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 4

Equation at a NodeDefines the hyperplane: ax+by+cz+d=0Subtree polygons are classified according to the coefficients stored at (internal) nodes

Page 5: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 5

Elements of BSP Construction

Choosing the partition plane Auto-partition: choose the partition plane from the input set of polygons It is desirable to have a balanced tree, where each leaf contains roughly the same number of polygons. However, there is some cost in achieving this. [deBerg et al.] choose free splits if possible, else, random selectionPartitioning polygons If a polygon happens to span the partition plane, it will be split into two or more pieces. A poor choice of the partition plane can result in many such splits, and a marked increase in the number of polygons.

Page 6: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 6

Elements of BSP Construction (cont)

The decision to terminate tree construction can be:

when the number of polygons in a leaf node is below a maximum value.

until every polygon is placed in an internal node. maximum tree depth.

Page 7: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 7

S3S3S2S2

S2

S2S3

S3

S1

S1

SIZE=3

Different ordering generates different trees

Page 8: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 8

S3

S2

S2b

S2a

S2

S3

S3a

S3bS1

S2b S3b S2a S3a

S1

S2b S3b S2a S3aS2b S2a

S3b S3aS3b S3aS3b S3a

SIZE=5

Page 9: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 9

Painter’s Algorithm Subtleties

What do we mean sort in z? That is for a triangle, what is its representative z value? Minimum z Maximum z Polygon’s centroid

Work cost = sort + drawWe still use Painter’s Algorithms for blended objects (discussed in the Blending Lesson)An object space visibility algorithm

Page 10: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 10

Painter’s Algorithm (cont)Pros: No extra memory Relatively fast Easy to

understand and implement

Cons: Precision issues

(and additional work to handle them)

Sort stage Intersecting

objects

Page 11: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 11

Painter’s Algorithm (BSP Version)

S(v) need not be drawn!

Page 12: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 12

Example Scene

Page 13: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 13

A

B

E

C

F

D

G

Page 14: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 14

A

E

C1

F

D

G

C2B2

B1

D

A B1 C1 B2 C2 EFG

+–

Page 15: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 15

A

E

C1

F

D

G

C2B2

B1

D

C1F

A B1 C2 B2 EG

Page 16: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 16

A

E

C1

F

D

G

C2B2

B1

D

C1F

B1 C2 E

G B2 A

Tree completed!

Page 17: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 17

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

Rendering BSP [b-to-f]

Page 18: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 18

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

hv-

hv+

Page 19: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 19

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

C1

hv-

hv+

Page 20: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 20

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1

hv-

hv+

Page 21: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 21

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1A

Page 22: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 22

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1AD

hv-

hv+

Page 23: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 23

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1AD

hv- hv

+

Page 24: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 24

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1AD

hv-hv

+

Page 25: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 25

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1ADB2

Page 26: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 26

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1AB2 E D

hv-hv

+

Page 27: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 27

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1AB2 E D

G

Page 28: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 28

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1AB2 E DFG

hv- hv

+

Page 29: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 29

A

E

C1

F

D

G

C2

B2

B1

D

C1F

B1 C2 E

G B2 Aeye

V

B1 C1AB2 E DFG

hv- hv

+

C2

Page 30: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 30

Consider Viewing Direction…

[From FAQ] … It is possible to substantially improve the quality of this example by including the viewing direction vector in the computation. You can determine that entire subtrees are behind the viewer by comparing the view vector to the partition plane normal vector. This test can also make a better decision about tree drawing when the eye point lies on the partition plane. Need not consider hv-

Page 31: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 31

Details

hvv

n

902

:eNot visibl

fov

v

n

v n

Page 32: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 32

Overdraw ProblemsBack-to-front: severe overdraw problemFront-to-back: no overdraw problem (with z-buffer). Most practical bsp renderers use this ordering

1000 rectangles

Front-to-back:0.06 sec

back-to-front:0.4 sec

Page 33: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 33

Other TopicsHistory of BSP (H. Fuchs et al. Siggraph80) see bspfaqBSP & ray tracing…… & collision detection…… & shadow (SVBSP)…… & motion planningBSP for dynamic scene

Page 34: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 34

BSP & Ray TracingSpeed up ray tracing by:

Reaching leaf nodesDetermine face through which ray exits

Find region-binding faces: collect all parental halfplanes

Compute exit pointsExtending ray into next region

… until the ray shoots into infinity

Page 35: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 35

Shadow Volume BSP (2D) (ref)

For every occluder, we can construct an SVBSP as shown right

l

a

b

a

b

ab

lit

lit

litshadow

Same

side as

ab

Not so

Same side as lNot so

Two types of nodes:i. light-to-endptii. occluder

Chin & Feiner (1989)

Page 36: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 36

SVBSP (cont)Incrementally, insert

blockers into SVBSPSplit cd into ca’ and a’bClassify a’d and find it is in shadow. No need to insert (does not create new shadow)Insert ca’ into right child of a (shown left)

l

a

b

c

da’

a

b

ab lit

litshadow

c

a’

ca’

lit

lit

litshadow

Page 37: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 37

Query Against SVBSPl

a

b

c

d

a’

a

b

ab lit

litshadow

c

a’

ca’

lit

lit

litshadow

Page 38: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 38

BSP in Games (ref)

•To account for character size, use offset planes in BSP•Problems when angles between planes are large

Character-environment collision detection

Page 39: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 39

Collision ResolutionBetter to solve a collision by deflecting the motion rather than stopping at the impact pointStepping and climbing

Page 40: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 40

BSP & Collision Detection (Ref)

Moving objects (as OBB)[Out of 12 faces, only check with 1, 3, 6, 7]

Page 41: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 41

Dynamic ScenesMoving camera: no problemMoving objects: Fuchs et. al. was to specify a bounding

polygon around the area that of the scene that would be changing.

Doom: use z-buffer for for dynamic objects (missiles and bullets)

Adding objects: no problemDeleting objects: BIG problem (ref)

Page 42: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 42

a

b c

d

e

f

g

h i

j

k l

Homework

1. Construct the bsp tree until every line segment is in a leaf node2. From the given view point, list the ordering (1) back-to-front (2) front-to-back according to the bsp tree3. Considering viewing direction, list the b-to-f order

+–

Page 43: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 43

Ans1(i,d)

3(k) 2(c)

4(a) 5(g) 7(l)6(f)

b h e j

B-2-f: 1+ 3+

7-, 7, 7+ 3 3- 6-,6,6+ 1 1- 2- 4+,4,4- 2 2+ 5+,5,5-

Page 44: BSP Tree Supplement Jyun-Ming Chen. Fall 20052 Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.

Fall 2005 44

Ans1(i,d)

3(k) 2(c)

4(a) 5(g) 7(l)6(f)

b h e j

B-2-f: 1+ [3+

7-, 7, 7+] 3 3- 6-,6,6+ 1 1- 2- 4+,4,4- 2 2+ 5+,5,5-