15
CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University of California, Berkeley V2013-F-10-1.0 2 Today Clipping Clipping to view volume Clipping arbitrary polygons Hidden Surface Removal Z-Buffer BSP Trees Others 1 2 Sunday, October 6, 13

CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

CS-184: Computer GraphicsLecture #10: Clipping and

Hidden Surfaces

Prof. James O’BrienUniversity of California, Berkeley

V2013-F-10-1.0

2

Today

• Clipping • Clipping to view volume• Clipping arbitrary polygons• Hidden Surface Removal• Z-Buffer• BSP Trees• Others

1

2Sunday, October 6, 13

Page 2: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

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

3

4Sunday, October 6, 13

Page 3: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

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

5

6Sunday, October 6, 13

Page 4: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

7

Clipping Line to Line/Plane

a

bn̂

t =f � n̂ ·an̂ ·d

• Segment may be on one side

• Lines may be parallel

t 62 [0 . . .1]

n̂ ·d= 0|n̂ ·d| ε (Recall comments about numerical issues)

Triangle Clip/Split

8

a

b

c

-

+

-a

b

c

-

+

-a

b

c

-

+

-

Double vertices if you want separation...

7

8Sunday, October 6, 13

Page 5: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

9

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

Polygon Clipping• Find the part of a polygon inside the clip window?

Before Clipping

9

10Sunday, October 6, 13

Page 6: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

Polygon Clipping• Find the part of a polygon inside the clip window?

After Clipping

• Clip to each window boundary one at a time

Sutherland-Hodgman Clipping

11

12Sunday, October 6, 13

Page 7: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

• Clip to each window boundary one at a time

Sutherland-Hodgman Clipping

• Clip to each window boundary one at a time

Sutherland-Hodgman Clipping

13

14Sunday, October 6, 13

Page 8: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

Sutherland-Hodgman Clipping• Clip to each window boundary one at a time

Sutherland-Hodgman Clipping• Clip to each window boundary one at a time

15

16Sunday, October 6, 13

Page 9: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

Polygon Clip to Convex Domain

17

Note double edges.

18

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

17

18Sunday, October 6, 13

Page 10: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

19

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 coordinates

20

General Polygon Clipping

A B A�B

B�A

A\B

A[B

19

20Sunday, October 6, 13

Page 11: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

21

•Weiler Algorithm• Double edges

General Polygon Clipping

22

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.

21

22Sunday, October 6, 13

Page 12: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

23

Z-Buffers• Add extra depth channel to image•Write Z values when writing pixels• Test Z values before writing

Images from Okan Arikan

24

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

23

24Sunday, October 6, 13

Page 13: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

25

Z-Buffers• Transparency requires partial sorting:

Partiallytransparent

Opaque

Opaque 1st

2nd

3rdFront

Good

Partiallytransparent

Opaque

Opaque 2nd

3rd

1st

Not Good

26

Z-BuffersRecall depth-value distortions.

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

25

26Sunday, October 6, 13

Page 14: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

27

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...

28

Scan-line Algorithm• Assume polygons don’t intersect• Each time an edge is crossed determine who’s on top

27

28Sunday, October 6, 13

Page 15: CS-184: Computer Graphics - University of California, Berkeleyjob/Classes/CS... · CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces Prof. James O’Brien University

29

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?

30

BSP-Trees

• Binary Space Partition Trees• Split space along planes• Allows fast queries of some spatial relations•Draw Front-to-Back• Draw same-side polygons first• Draw root node polygon (if any)• Draw other-side polygons last

29

30Sunday, October 6, 13