+ All Categories
Home > Documents > Clipping - University of California, Berkeley

Clipping - University of California, Berkeley

Date post: 26-Dec-2021
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
8
CS-184: Computer Graphics Lecture #6: Clipping and Hidden Surfaces Prof. James O’Brien University of California, Berkeley V2005F-06-1.0 2 Today Clipping Clipping to view volume Clipping arbitrary polygons Hidden Surface Removal Z-Buffer BSP Trees Others 3 Clipping Stuff outside view volume should not be drawn Too close: obscures view 4 Clipping Stuff outside view volume should not be drawn Too close: obscures view Too far: Complexity Z-buffer problems Too high/low/right/left: Memory errors Broken algorithms Complexity
Transcript
Page 1: Clipping - University of California, Berkeley

CS-184: Computer Graphics

Lecture #6: Clipping andHidden Surfaces

Prof. James O’Brien

University of California, Berkeley

V2005F-06-1.0

2

Today

Clipping

Clipping to view volume

Clipping arbitrary polygons

Hidden Surface Removal

Z-Buffer

BSP Trees

Others

3

Clipping

Stuff outside view volume should not be drawn

Too close: obscures view

4

Clipping

Stuff outside view volume should not be drawn

Too close: obscures view

Too far:

Complexity

Z-buffer problems

Too high/low/right/left:

Memory errors

Broken algorithms

Complexity

Page 2: Clipping - University of California, Berkeley

5

Clipping Line to Line/Plane

a

bn̂

Line segment to be clipped

Line/plane that clips it r

x(t) = a+ t(b−a)

n̂ ·x− n̂ · r= 0

6

Clipping Line to Line/Plane

a

bn̂

Line segment to be clipped

Line/plane that clips it

x(t) = a+ t(b−a)

n̂ ·x− f = 0

}n̂ · (a+ t(b−a))− f = 0

n̂ ·a+ t(n̂ · (b−a))− f = 0

t =f − n̂ ·an̂ ·d

7

Clipping Line to Line/Plane

a

bn̂

t =f − n̂ ·an̂ ·d

Segment may be on one side

Lines may be parallel

t !∈ [0 . . .1]

n̂ ·d= 0

|n̂ ·d|≤ ! (Recall comments about numerical issues)

8

Polygon Clip to Convex Domain

Convex domain defined by collection of planes (or lines or hyper-planes)

Planes have outward pointing normals

Clip against each plane in turn

Check for early/trivial rejection

Page 3: Clipping - University of California, Berkeley

9

Polygon Clip to Convex Domain

10

Polygon Clip to Convex Domain

Inside Outside

s

p

Output p

Inside Outside

sp

Output i

Inside Outside

s

p

No output

Inside Outside

sp

Output i and p

i

i

11

Polygon Clip to Convex Domain

Sutherland-Hodgman algorithm

Basically edge walking

Clipping done often... should be efficient

Liang-Barsky parametric space algorithm

See text for clipping in 4D homogenized coordiantes

12

General Polygon Clipping

AB

A−B

B−A

A∩B

A∪B

Page 4: Clipping - University of California, Berkeley

13

Weiler Algorithm

Double edges

General Polygon Clipping

14

Hidden Surface Removal

True 3D to 2D projection would put every thing overlapping into the view plane.

We need to determine what’s in front and display only that.

15

Z-Buffers

Add extra depth channel to image

Write Z values when writing pixels

Test Z values before writing Images from Okan Arikan

16

Z-Buffers

Benefits

Easy to implement

Works for most any geometric primitive

Parallel operation in hardware

Limitations

Quantization and aliasing artifacts

Overfill

Transparency does not work well

Page 5: Clipping - University of California, Berkeley

17

Z-Buffers

Transparency requires partial sorting:

Partially

transparent

Opaque

Opaque 1st

2nd

3rd

Front

Good

Partially

transparent

Opaque

Opaque 2nd

3rd

1st

Not Good

18

Z-Buffers

Recall depth-value distortions.

It’s a feature...! More resolution near viewer! Best use of limited precision

19

A-Buffers

Store sorted list of “fragments” at each pixel

Draw all opaque stuff first then transparent

Stuff behind full opacity gets ignored

Nice for antialiasing...

20

Scan-line Algorithm

Assume polygons don’t intersect

Each time an edge is crossed determine who’s on top

Page 6: Clipping - University of California, Berkeley

21

Painter’s Algorithm

Sort Polygons Front-to-Back

Draw in order

Back-to-Front works also, but wasteful

How to sort quickly?

Intersecting polygons?

Cycles?

22

BSP-Trees

Binary Space Partition Trees

Split space along planes

Allows fast queries of some spatial relations

Simple construction algorithm

Select a plane as sub-tree root

Everything on one side to one child

Everything on the other side to other child

Use random polygon for splitting plane

23

a,b,c,d,e,f,g

BSP-Trees

a

b

c

d

e

g

f

24

a

b,c1,d c2,e,f,ga

b

c1

d

e

g

f

c2

BSP-Trees

Page 7: Clipping - University of California, Berkeley

25

a

b c2,e,f,g

c1 d

a

b

c1

d

e

g

f

c2

BSP-Trees

26

a

b c2

c1 d e1 ,f e2 ,g

a

b

c1

d

g

f

c2

e1 e2

BSP-Trees

27

a

b c2

c1 d e1 e2 ,g

f

a

b

c1

d

g

f

c2

e1 e2

BSP-Trees

28

a

b c2

c1 d e1 e2

f g

a

b

c1

d

g

f

c2

e1 e2

BSP-Trees

+ -

+ - + -

+ +

+

++

+

Page 8: Clipping - University of California, Berkeley

29

Visibility Traversal

Variation of in-order-traversal

Child one

Sub-tree root

Child two

Select “child one” based on location of viewpoint

Child one on same side of sub-tree root as viewpoint

30

a

b c2

c1 d e1 e2

f g

a

b

c1

d

g

f

c2

e1 e2

BSP-Trees

c1:b:d:a:f:e1:c2:g:e2

31

g:e2:c2:f:e1:a:c1:b:d

a

b c2

c1 d e1 e2

f g

a

b

c1

d

g

f

c2

e1 e2

BSP-Trees


Recommended