+ All Categories
Home > Documents > Computer Graphics

Computer Graphics

Date post: 30-Dec-2015
Category:
Upload: martha-byrd
View: 28 times
Download: 0 times
Share this document with a friend
Description:
Computer Graphics. Bing-Yu Chen National Taiwan University. Hidden-Surface Removal. Back-Face Culling The Depth-Sort Algorithm Binary Space-Partitioning Trees The z-Buffer Algorithm Visible-Surface Ray Tracing (Ray Casting) Space S ubdivision A pproaches. - PowerPoint PPT Presentation
Popular Tags:
67
Computer Graphics Bing-Yu Chen National Taiwan University
Transcript

Computer Graphics

Bing-Yu ChenNational Taiwan University

Hidden-Surface Removal

Back-Face Culling The Depth-Sort Algorithm Binary Space-Partitioning Trees The z-Buffer Algorithm Visible-Surface Ray Tracing

(Ray Casting) Space Subdivision Approaches

2

Hidden-Surface Removal=Visible-Surface Determination Determining what to render at each pixel. A point is visible if there exists a direct line-of-sight to

it, unobstructed by another other objects (visible surface determination).

Moreover, some objects may be invisible because there are behind the camera, outside of the field-of-view, too far away (clipping) or back faced (back-face culling).

3

Hidden Surfaces: why care?

Occlusion: Closer (opaque) objects along same viewing ray obscure more distant ones.

Reasons for removal Efficiency: As with clipping, avoid wasting

work on invisible objects. Correctness: The image will look wrong if

we don’t model occlusion properly.

4

Back-Face Culling = Front Facingx

z G

H

E

C

B

A

D

F

5

Back-Face Culling = Front Facing

use cross-product to get the normal of the face (not the actual normal)

use inner-product to check the facing

2 1 3 1( ) ( )N v v v v v1

v2

v3

N

V

6

Clipping (View Frustum Culling)

eye

view frustum

occlusionbackface

view frustum

7

List-Priority Algorithms

The Painter’s Algorithm The Depth-Sort Algorithm Binary Space-Partitioning Trees

8

The Painter’s Algorithm

Draw primitives from back to front need for depth comparisons.

9

The Painter’s Algorithm

for the planes with constant z not for real 3D, just for 2½D

sort all polygons according to the smallest (farthest) z coordinate of each

scan convert each polygon in ascending order of smallest z coordinate (i.e., back to front)

10

The Depth-Sort Algorithm sort all polygons according to the smallest

(farthest) z coordinate of each resolve any ambiguities that sorting may

cause when the polygons’ z extents overlap, splitting polygons if necessary

scan convert each polygon in ascending order of smallest z coordinate (i.e., back to front)

11

Overlap Cases

x

x

z

PQ

y

PQ

x

y

P Q

R

12

Binary Space-Partitioning Trees An improved painter’s algorithm Key observation:

T1

T2

T3

T4

T5

( ) 0f p ( ) 0f p

0

( ) : ( ) 0

Ax By Cz D

f p n p a

14

Binary Space-Partitioning Trees

T1

T2

T2 T3

T1 +-

T3

15

Binary Space-Partitioning Trees

T1

T2

T3

T3

T1 +-

T2 +-

16

Splitting trianglesa

b

c

A

B

a

b

c

A

B

17

BSP Tree ConstructionBSPtree makeBSP(L: list of polygons) {

if (L is empty) {return the empty tree;

} Choose a polygon P from L to serve as root;Split all polygons in L according to Preturn new TreeNode (

P,makeBSP(polygons on negative side of P),makeBSP(polygons on positive side of P))

} Splitting polygons is expensive! It helps to choose P wisely

at each step. Example: choose five candidates, keep the one that splits

the fewest polygons.

18

BSP Tree Displayvoid showBSP(v: Viewer, T: BSPtree) {

if (T is empty) return;P = root of T;if (viewer is in front of P) {

showBSP(back subtree of T);draw P;showBSP(front subtree of T);

} else {showBSP(front subtree of T);draw P;showBSP(back subtree of T);

}}

2D BSP demo19

Binary Space-Partitioning Trees

Same BSP tree can be used for any eye position, constructed only once if the scene if static.

It does not matter whether the tree is balanced. However, splitting triangles is expensive and try to avoid it by picking up different partition planes.

21

3

4

1

2

56

7

9

8

11

10

BSP Tree

22

1

insideones

outsideones

3

4

1

2

56

7

9

8

11

10

BSP Tree

23

1

234

567891011

3

4

1

2

56

7

9

8

11

10

BSP Tree

24

1

5

679a1011a

89b11b

3

4

1

2

9

8

11

10

56

7

9b

9a

11a

11b

BSP Tree

25

2

3

4

1

5

6

7

9a

10

11a

8

9b

11b

3

4

1

2

9

8

11

10

56

7

9b

11a

9a11b

BSP Tree

26

2

3

4

1

5

6

7

9a

10

11a

8

9b

11b

BSP Tree

3

4

1

2

9

8

11

10

56

7

9b

point

11a

9a11b

27

2

3

4

1

5

6

7

9a

10

11a

8

9b

11b

3

4

1

2

9

8

11

10

56

7

9b

point

11a

9a11b

BSP Tree Traversal

28

2

3

4

1

5

6

7

9a

10

11a

8

9b

11b

1

2

9

8

11

10

56

7

9b

point

11a

9a11b

3

4

BSP Tree Traversal

29

The z-Buffer Algorithm

Resolve depths at the pixel level Idea: add Z to frame buffer, when a

pixel is drawn, check whether it is closer than what’s already in the frame buffer

30

The z-Buffer Algorithm

+

+ =

=

31

The z-Buffer Algorithmvoid zBuffer() {

int pz;for (each polygon) {

for (each pixel in polygon’s projection) {pz=polygon’s z-value at (x,y);if (pz>=ReadZ(x,y)) {

WriteZ(x,y,pz);WritePixel(x,y,color);

}}

}}

32

The z-Buffer Algorithm

y

y1

y2

y3

ys

z1

z2

z3

zazp zb Scan line

ab

pbabbp

sb

sa

xx

xxzzzz

yy

yyzzzz

yy

yyzzzz

)(

)(

)(

31

1311

21

1211

33

The z-Buffer Algorithm Benefits

Easy to implement Works for any geometric primitive Parallel operation in hardware

independent of order of polygon drawn

Limitations Memory required for depth buffer Quantization and aliasing artifacts Overfill Transparency does not work well

35

Ray Tracing = Ray Castingselect center of projection and window on viewplane;for (each scan line in image) {

for (each pixel in scan line) {determine ray from center of projection through pixel;for (each object in scene) {

if (object is intersected and is closest considered thus far)

record intersection and object name;}set pixel’s color to that at closest object intersection;

}}

39

Ray Casting

Window

Center ofprojection

40

Ray Casting (Appel, 1968)

41

Ray Casting (Appel, 1968)

42

Ray Casting (Appel, 1968)

43

Ray Casting (Appel, 1968)

nls

i

nisidiaa VRkNLkIIk

1

44

Ray Casting (Appel, 1968)

direct illumination

45

Spatial Partitioning

46

Spatial Partitioning

R

A B

C

47

Spatial Partitioning

1

23

A

B

48

Space Subdivision Approaches

Uniform grid K-d tree

49

Space Subdivision Approaches

Quadtree (2D)Octree (3D)

BSP tree

50

Uniform Grid

51

Preprocess scene1. Find bounding box

Uniform Grid

52

Preprocess scene1. Find bounding box2. Determine grid resolution

Uniform Grid

53

Uniform Grid

Preprocess scene1. Find bounding box2. Determine grid resolution3. Place object in cell if its

bounding box overlaps the cell

54

Uniform Grid

Preprocess scene1. Find bounding box2. Determine grid resolution3. Place object in cell if its

bounding box overlaps the cell

4. Check that object overlaps cell (expensive!)

55

Uniform Grid Traversal

Preprocess sceneTraverse grid

3D line = 3D-DDA

56

From Uniform Grid to Quadtree

57

Quadtree (Octrees)

subdivide the space adaptively 58

Quadtree Data Structure

Quadrant Numbering

59

Quadtree Data Structure

Quadrant Numbering

60

Quadtree Data Structure

Quadrant Numbering

61

Quadtree Data Structure

Quadrant Numbering

62

From Quadtree to Octree

x

y

z

63

A

A

Leaf nodes correspond to unique regions in space

K-d Tree

64

A

A

B

K-d Tree

65

A

B

A

B

K-d Tree

66

A

B

A

B

C

K-d Tree

67

A

B

C A

B

C

K-d Tree

68

A

B

C A

B

C

D

K-d Tree

69

A

B

C

D

A

B

C

D

K-d Tree

70

A

B C

D

A

B

C

D

Leaf nodes correspond to unique regions in space

K-d Tree

71

A

B C

D

A

B

C

D

Leaf nodes correspond to unique regions in space

K-d Tree Traversal

72


Recommended