Академический Документы
Профессиональный Документы
Культура Документы
? ?
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
No Lines Removed
Viewer
Occluding Occluded
Polygon Polygon
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Motivation
• Surfaces may be overlapping:
Viewer
Viewer
n
z
p
y
(p - n)n = 0
x
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Backface Culling
• Avoid drawing polygons facing away from the viewer
Front-facing polygons occlude these polygons in a closed
polyhedron
• Test if a polygon is front- or back-facing?
back-facing
Ideas?
front-facing
If (n v) > 0 “back-face”
If (n v) ≤ 0 “front-face” back
v = view vector
front
• glCullFace(GL_BACK)
v0 v1
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Normal Direction
• Vertices counterclockwise Front-facing
• Vertices clockwise Back-facing
2 1
0 0
1 2
y
d=(-1,0)
a=(-1,1) b=(0,1) c=(1,1)
a·d = (-1,1)·(-1,0) = 1 > 0
b·d = (0,1)·(-1,0) = 0
x c·d = (1,1)·(-1,0) = -1 < 0
C1•N1 = 0 N1
C1
C2 N2
• Requirements
Draw polygons in back-to-
front order
Need to sort the polygons by
depth order to get a correct
image from Shirley
zmin
zmin
Viewer C
View B
Plane
Depth Sort
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Painter’s Example
z = 0.7
z = 0.3
z = 0.1
Sort by depth:
Green rect
Red circle z=0
Blue tri
cyclic overlap
Overlap in all directions
but can one is fully on
one side of the other
penetration
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Painter’s Algorithm
• Problem: Can you get a total sorting?
zmin zmin
zmin zmin
Correct?
• Sorting is nontrivial
Split polygons in order to get a total ordering
Not easy to do in general
A D E
Viewer C
B
View
Plane
Screen
Department of Computer Science Lectures
CSE528 STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Not Parallel
Department of Computer Science Lectures
CSE528 STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Z-Buffer Algorithm
Algorithm easily handles this case
top view
4 5 7
1 3
+ 6
4 5 7
1 3
If we want to draw 5 correctly
2
- we need draw 6 and 7 first,
- then draw 5,
- then draw 1,2,3,4
+ 6
4 5 7
If we want to draw 5 correctly
1 3 - we need draw 6 and 7 first,
2 - then draw 5,
- then draw 1,2,3,4
+ 6
4 5 7
If we want to draw 5 correctly
1 3 - we need draw 6 and 7 first,
2 - then draw 5,
- then draw 1,2,3,4
+ -
+ +
+ - + -
+
+ + +
9
8
6 7
5
4
1 2 3
9
8 -
6 7
+
5
4
1 2 3
9
8 -
6 7
+
5
4
1 2 3
9
8
6 7
5
4
1 2 3
9
8
6 7
5
4
1 2 3
9
8
6 7
5
4
1 2 3
9
8
6 7
5
4
1 2 3
Ouch
9 + -
8
6 7
+ - + -
5
4 1
+ - + - + -
1 2 3
2 3 5 6 6 8
+ - + -
2 4 7 9
Traversal order?
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
BSP Trees: Objects
9 + -
8
6 7
+ - + -
5
4 1
+ - + - + -
1 2 3
2 3 5 6 6 8
+ - + -
2 4 7 9
Traversal order:
8->9->7->6->5->3->4->2->1
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Building a BSP Tree for Polygons
• Choose a splitting polygon
• Sort all other polygons as
– Front
– Behind
– Crossing
– On
• Add “front” polygons to front child, “behind” to back
child
• Split “crossing” polygons with infinite plane
• Add “on” polygons to root
• Recursion until all polygons are processed
7
3 5
1 2 4
7
3 5
1 2 4
1
b
2,34,5,6,7
7
3 5
1 2 4
1
b
2,34,5,6,7
7-2 5-2
3
7-1 5-1
1 2 4
1
b
3
f b
2,4,5-1,7-1 7-2, 6,5-2
7-2 5-2
3
7-1 5-1
1 2 4
1
b
3
f b
2,4,5-1,7-1 7-2, 6,5-2
7-2 5-2
3
7-1 5-1
1 2 4
1
b
f 3
b
7-1 7-2, 6,5-2
f b
2 4,5-1
7-2 5-2
3
7-1 5-1
1 2 4
1
b
f 3
b
7-2, 6,5-2
7-1
f b
4
2 b
5-1
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Building a BSP Tree
6
7-2 5-2
3
7-1 5-1
1 2 4
1
b
3
f b
7-1 7-2, 6,5-2
f b
4
2 b
5-1
7-2 5-2
3
7-1 5-1
1 2 4
1
b
3
f b
7-1 7-2, 6,5-2
f b
4
2 b
5-1
7-2 5-2
3
7-1 5-1
1 2 4
1
b
3
f b
7-1 7-2
f b b
4 6,5-2
2 b
5-1
7-2 5-2
3
7-1 5-1
1 2 4
1
b
3
f b
7-1 7-2
f b b
4 6
2 b f
5-1 5-2
7-2 5-2
3
7-1 5-1
1 2 4
1
1
b
3
f b
7-1 7-2
f b b
4 6
2 b f
5-1 5-2
7-2 5-2
3
7-1 5-1
1 2 4
1
1
b
3
f b
7-1 7-2
f b b
4 6
2 b f
5-1 5-2
7-2 5-2
3
7-1 5-1
1 2 4
1
1
b
3
f b
7-1 7-2
f b b
4 6
2 b f
Traversal order: 5-1 5-2
7-2 5-2
3
7-1 5-1
1 2 4
1
1
b
3
f b
7-1 7-2
f b b
4 6
2 b f
Traversal order: 5-1 5-2
6->(5-2)->(7-2)->3->(5-1)->4->(7-1)->2->1
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Building a BSP Tree
6
7-2 5-2
3
7-1 5-1
1 2 4
1
1
b
3
f b
7-1 7-2
f b b
4 6
2 b f
Traversal order: 5-1 5-2
7-2 5-2
3
7-1 5-1
1 2 4
1
1
b
f 3
b
7-1 b 7-2
f b b
4 6
2 b f
Traversal order: 5-1 5-2
1->2->(7-1)->4->(5-1)->3->(7-2)->(5-2)->6
Department of Computer Science CSE528 Lectures STNY BRK
Center for Visual Computing STATE UNIVERSITY OF NEW YORK
Building a BSP Tree
6
7-2 5-2
3
7-1 5-1
1 2 4
1
1
b
f 3
b
7-1 7-2
f b b
4 6
2 b f
Traversal order? 5-1 5-2
View frustum