Clipping Werner Purgathofer Viewing in the Rendering Pipeline - - PowerPoint PPT Presentation

clipping
SMART_READER_LITE
LIVE PREVIEW

Clipping Werner Purgathofer Viewing in the Rendering Pipeline - - PowerPoint PPT Presentation

Einfhrung in Visual Computing 186.822 Clipping Werner Purgathofer Viewing in the Rendering Pipeline object capture/creation scene objects in object space modeling vertex stage viewing (vertex shader) projection transformed


slide-1
SLIDE 1

Einführung in Visual Computing

186.822

Clipping

Werner Purgathofer

slide-2
SLIDE 2

Viewing in the Rendering Pipeline

Werner Purgathofer 2

raster image in pixel coordinates clipping + homogenization

  • bject capture/creation

modeling viewing projection rasterization viewport transformation shading

vertex stage („vertex shader“) pixel stage („fragment shader“)

scene in normalized device coordinates transformed vertices in clip space scene objects in object space

slide-3
SLIDE 3

Werner Purgathofer 3

line clipping polygon clipping triangle clipping

Overview: Clipping

slide-4
SLIDE 4

Werner Purgathofer 4

partly visible or completely invisible parts must not be ignored and must not be drawn

.

ignored?: vertices edges scrolled?:

Clipping

⇒ must be cut off (as early as possible)

slide-5
SLIDE 5

Werner Purgathofer 5

remove objects outside a clip window

clip window: rectangle, polygon, curved boundaries applied somewhere in the viewing pipeline can be combined with scan conversion

  • bjects to clip: points, lines, triangles, polygons, curves, text, ...

Clipping Operations

slide-6
SLIDE 6

Werner Purgathofer 6

analytically in world coordinates

reduces WC → DC transformations

analytically in clip coordinates

simple comparisons

during raster conversation = as part of the rasterization algorithm

may be efficient for complex primitives

3 Principle Possibilities for Clipping

slide-7
SLIDE 7

Werner Purgathofer 7

[line clipping against a rectangular clip window]

before clipping after clipping

Line Clipping (1)

P1 P6 P7 P8 P10 P9 P5 P4 P3 P2 P1 P6 P2 P'5 P'8 P'7

slide-8
SLIDE 8

Werner Purgathofer 8

goals

eliminate simple cases fast avoid intersection calculations

for endpoints (x0,y0), (xend,yend) intersect parametric representation x = x0 + u·(xend - x0) y = y0 + u·(yend - y0) with window borders: intersection ⇔ 0 < u < 1

Line Clipping (2)

slide-9
SLIDE 9

Window

assignment of region codes to line vertices

bit1: left bit2: right bit3: below bit4: above

Werner Purgathofer 9

binary region codes assigned to line endpoints according to relative position with respect to the clipping rectangle

Cohen-Sutherland Line Clipping

1001 1000 1010 0001 0000 0010 0101 0100 0110

slide-10
SLIDE 10

Werner Purgathofer 10

“or” of codes of both points = 0000 ⇒ line entirely visible “and” of codes of both points ≠ 0000 ⇒ line entirely invisible all others ⇒ intersect!

Cohen-Sutherland Line Clipping

Window

1001 1000 1010 0001 0000 0010 0101 0100 0110

slide-11
SLIDE 11

Werner Purgathofer 11

lines extending from one coordinate region to another may pass through the clip window, or they may intersect clipping boundaries without entering the window

Cohen-Sutherland Line Clipping

window P2 P3 P1 P4 P"2 P'1 P'2 P'3

slide-12
SLIDE 12

remaining lines

intersection test with bounding lines of clipping window left, right, bottom, top discard an outside part repeat intersection test up to four times

(x0,y0) xwmin

Werner Purgathofer 12

Cohen-Sutherland Line Clipping

vertical: y = y0 + m(xwmin – x0), y = y0 + m(xwmax – x0) horizontal: x = x0 + (ywmin – y0)/m, x = x0 + (ywmax – y0)/m

(xwmin,y) (xwmin–x0) m(xwmin–x0)

vertical: (x = xwmin) y = y0 + m(xwmin – x0)

slide-13
SLIDE 13

Werner Purgathofer 13

passes through clipping window intersects boundaries without entering clipping window

Cohen-Sutherland Line Clipping

vertical: y = y0 + m(xwmin – x0), y = y0 + m(xwmax – x0) horizontal: x = x0 + (ywmin – y0)/m, x = x0 + (ywmax – y0)/m

window P2 P1 P"2 P'1 P'2 P'3 P3 P4

slide-14
SLIDE 14

Werner Purgathofer 14

modification of line clipping goal: one or more closed areas

display of a correctly clipped polygon display of a polygon processed by a line-clipping algorithm

Polygon Clipping

slide-15
SLIDE 15

Werner Purgathofer 15

clipping a polygon against successive window boundaries

  • riginal

polygon clip left clip right clip bottom clip top

Sutherland-Hodgman Polygon Clipping

processing polygon boundary as a whole against each window edge

  • utput: list of vertices
slide-16
SLIDE 16

Werner Purgathofer 16

four possible edge cases successive processing of pairs of polygon vertices against the left window boundary

  • ut → in
  • utput: Vnew, V2

in → in V2 in → out Vnew

  • ut → out

no output

Sutherland-Hodgman Polygon Clipping

V1 V2 V1 V2 V1 V2 V1 V2 Vnew Vnew

slide-17
SLIDE 17

Werner Purgathofer 17

V2:= 1st vertex V1:=V2 V2:=next vertex V2 visible?

no

V1 visible?

no

for 1 edge: Sutherland-Hodgman Polygon Clipping

V2 V1

slide-18
SLIDE 18

Werner Purgathofer 18

V2:= 1st vertex V1:=V2 V2:=next vertex V2 visible?

no

V1 visible?

no

Vnew = clip edge ∩ V1V2 → result list

yes

for 1 edge: Sutherland-Hodgman Polygon Clipping

V1 V2 Vnew

slide-19
SLIDE 19

Werner Purgathofer 19

V2:= 1st vertex V1:=V2 V2:=next vertex V2 visible?

no

V1 visible?

yes yes

V1 visible?

no

V’1 = clip edge ∩ V1V2 → result list

yes

V2 → result list

for 1 edge: Sutherland-Hodgman Polygon Clipping

V1 V2

slide-20
SLIDE 20

Werner Purgathofer 20

V2:= 1st vertex V1:=V2 V2:=next vertex V2 visible?

no

V1 visible?

yes yes

V1 visible?

no

V’1 = clip edge ∩ V1V2 → result list

yes no

V2 → result list

for 1 edge: Sutherland-Hodgman Polygon Clipping

V1 V2 Vnew

slide-21
SLIDE 21

window 6 1 2 3 5 4

Werner Purgathofer 21

clipping a polygon against the left boundary of a window, starting with vertex 1. primed numbers are used to label the points in the

  • utput vertex list for this

window boundary

Sutherland-Hodgman Polygon Clipping

1' 2' 5' 4' 3'

slide-22
SLIDE 22

Werner Purgathofer 22

Polygon Clip: Combination of 4 Passes

the polygon is clipped against each of the 4 borders separately, that would produce 3 intermediate results. by calling the 4 tests recursively, (or by using a clipping pipeline) every result point is immediately processed on, so that only one result list is produced

slide-23
SLIDE 23

Werner Purgathofer 23

pipeline of boundary clippers to avoid intermediate vertex lists

Processing the polygon vertices through a boundary-clipping

  • pipeline. After all vertices are processed through the pipeline, the

vertex list for the clipped polygon is {1', 2, 2', 2"}

Sutherland-Hodgman Clipping Example

3 1 2

1st clip: left 2nd clip: bottom

window

2' 3' 2" 1'

slide-24
SLIDE 24

Werner Purgathofer 24

extraneous lines for concave polygons:

split into separate parts or final check of output vertex list

Sutherland-Hodgman Polygon Clipping

clipping the concave polygon with the Sutherland-Hodgeman clipper produces three connected areas

slide-25
SLIDE 25

Werner Purgathofer 25

  • ften b-reps are “triangle soups”

clipping a triangle  triangle(s) 4 possible cases:

inside

  • utside

triangle quadrilateral  2 triangles

Clipping of Triangles

(inside)

slide-26
SLIDE 26

Werner Purgathofer 26

corner cases need no extra handling!

Clipping of Triangles

slide-27
SLIDE 27

From Object Space to Screen Space

Werner Purgathofer 27

  • bject space

world space camera space clip space screen space „view frustum“ modeling transformation camera transformation projection transformation viewport transformation

slide-28
SLIDE 28

Werner Purgathofer 28

clipping against x = ± 1, y = ± 1, z = ± 1 (x,y,z) inside?  only compare one value per border!

Clipping in Clip-Space

is done before homogenization:

x = ± h, y = ± h, z = ± h clips points that are behind the camera! reduces homogenization divisions

slide-29
SLIDE 29

Einführung in Visual Computing

186.822

Antialiasing

Werner Purgathofer

slide-30
SLIDE 30

Antialiasing in the Rendering Pipeline

Werner Purgathofer 30

raster image in pixel coordinates clipping + homogenization

  • bject capture/creation

modeling viewing projection rasterization viewport transformation shading

vertex stage („vertex shader“) pixel stage („fragment shader“)

scene in normalized device coordinates transformed vertices in clip space scene objects in object space

slide-31
SLIDE 31

Werner Purgathofer 31

what is aliasing? ['eiliæsiη] what is the reason for aliasing? what can we do against it?

Aliasing and Antialiasing

slide-32
SLIDE 32

Werner Purgathofer 32

too bad resolution too few colors too few images / sec geometric errors numeric errors

errors that are caused by the discretization of analog data to digital data

What is Aliasing?

slide-33
SLIDE 33

Werner Purgathofer 33

Aliasing: Staircase Effect

slide-34
SLIDE 34

Werner Purgathofer 34

Various Aliasing Effects

slide-35
SLIDE 35

Werner Purgathofer 35

artificial color borders can appear

Aliasing from too few Colors

slide-36
SLIDE 36

Werner Purgathofer 36

jumping images "worming“ backwards rotating wheels

Aliasing in Animations

t

slide-37
SLIDE 37

Werner Purgathofer 37

  • 1. improve the devices

higher resolution more color levels faster image sequence

  • 2. improve the images = antialiasing

postprocessing prefiltering !

expensive

  • r

incompatible software !

Solutions against Aliasing?

slide-38
SLIDE 38

a signal can only be reconstructed without information loss if the sampling frequency is at least twice the highest frequency of the signal this border frequency is called "Nyquist Limit"

Werner Purgathofer 38

Nyquist-Shannon Sampling Theorem

slide-39
SLIDE 39

Werner Purgathofer 39

Nyquist-Shannon Sampling Theorem

Nyquist sampling interval sampling rate ∆

  • riginal signal

reconstructed signal

slide-40
SLIDE 40

Werner Purgathofer 40

max cycle

/ 1 x

with

2 f x x

cycle s

= ∆ ∆ = ∆

i.e. sampling interval ≤ one-half cycle interval

max

2 f f s =

Nyquist sampling frequency:

Antialiasing: Nyquist Sampling Frequency

a signal can only be reconstructed without information loss if the sampling frequency is at least twice the highest frequency of the signal

slide-41
SLIDE 41

Werner Purgathofer 41

supersampling straight-line segments subpixel weighting masks area sampling straight-line segments filtering techniques compensating for line-intensity differences antialiasing area boundaries

(adjusting boundary pixel positions) adjusting boundary pixel intensity

Antialiasing Strategies

slide-42
SLIDE 42

Werner Purgathofer 42

3 = max. intensity ... 0 = min. intensity 9 = max. intensity ... 0 = min. intensity mathematical line line of finite width

Antialiasing: Supersampling Lines

0 0 1 0 2 2 3 1 0 0 0 4 1 6 8 8 5 0

slide-43
SLIDE 43

Werner Purgathofer 43

Antialiasing

slide-44
SLIDE 44

Werner Purgathofer 44

calculate the pixel coverage exactly can be done with incremental schemes

Antialiasing: Area Sampling Lines 0% 0% 43% 15% 71% 84% 90% 52% 3%

slide-45
SLIDE 45

Werner Purgathofer 45

relative weights for a grid of 3x3 subpixels more weight for center subpixels must be divided by sum of weights subpixel grids can also include some neighboring pixels

Antialiasing: Pixel Weighting Masks

1 2 1 2 4 2 1 2 1

slide-46
SLIDE 46

Werner Purgathofer 46

box filter cone filter Gaussian filter continuous overlapping weighting functions to calculate the antialiased values with integrals

Antialiasing: Filtering Techniques

slide-47
SLIDE 47

Werner Purgathofer 47

unequal line lengths displayed with the same number of pixels in each line/row have different intensities proper antialiasing compensates for that!

Antialiasing: Intensity Differences

1 1,41421

slide-48
SLIDE 48

Werner Purgathofer 48

Antialiasing Area Boundaries

slide-49
SLIDE 49

Werner Purgathofer 49

adjusting pixel intensities along an area boundary alternative 1: supersampling

Antialiasing Area Boundaries (1)

slide-50
SLIDE 50

Werner Purgathofer 50

alternative 2: similar to Bresenham algorithm p' = y − ymid = [m(xk + 1) + b] − (yk + 0.5) p'<0 ⇒ y closer to yk p'>0 ⇒ y closer to yk+1 p = p' + (1−m) : p<1−m ⇒ y closer to yk p>1−m ⇒ y closer to yk+1 ( and p ∈ [0,1] )

Antialiasing Area Boundaries (2)

ymid

y = mx + b yk + 1 yk + 0.5 yk xk + 1 xk

y

slide-51
SLIDE 51

Werner Purgathofer 51

p = p'+ (1−m) = [m(xk + 1) + b] − (yk + 0.5) + (1 − m) = mxk + b − yk + 0.5 =

Antialiasing Area Boundaries (3)

xk xk+1 yk yk+ 0.5 m p for next pixel = overlap area for current pixel p' p p 1-m p' = mxk + b − (yk − 0.5)

slide-52
SLIDE 52

Werner Purgathofer 52

Antialiasing Area Boundaries (4)

slide-53
SLIDE 53

Werner Purgathofer 53

Antialiasing Examples

slide-54
SLIDE 54

Werner Purgathofer 54

Antialiasing Examples