clipping - tu wien · position with respect to the clipping rectangle. cohen-sutherland line...

Post on 24-May-2020

3 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Einführung in Visual Computing186.822

Clipping

Werner Purgathofer

Viewing in the Rendering Pipeline

Werner Purgathofer 2raster image in pixel coordinates

clipping + homogenization

object capture/creation

modelingviewing

projection

rasterizationviewport 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

Werner Purgathofer 3

line clippingpolygon clippingtriangle clipping

Overview: Clipping

Werner Purgathofer 4

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

.

ignored?:

vertices edges

scrolled?:

Clipping

⇒ must be cut off (as early as possible)

Werner Purgathofer 5

remove objects outside a clip windowclip window: rectangle, polygon, curved boundariesapplied somewhere in the viewing pipelinecan be combined with scan conversionobjects to clip: points, lines, triangles, polygons, curves, text, ...

Clipping Operations

Werner Purgathofer 6

analytically in world coordinatesreduces WC → DC transformations

analytically in clip coordinatessimple comparisons

during raster conversation= as part of the rasterization algorithm

may be efficient for complex primitives

3 Principle Possibilities for Clipping

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

Werner Purgathofer 8

goalseliminate simple cases fastavoid 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)

Window

assignment of region codes to line vertices

bit1: leftbit2: rightbit3: belowbit4: 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

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

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

P1P4

P"2

P'1

P'2

P'3

remaining linesintersection test with bounding lines of clipping windowleft, right, bottom, topdiscard an outside partrepeat 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)

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

Werner Purgathofer 14

modification of line clippinggoal: one or more closed areas

display of a correctly clipped polygon

display of a polygon processed by a line-clipping algorithm

Polygon Clipping

Werner Purgathofer 15

clipping a polygon against successive window boundaries

originalpolygon

clip left clip right clip bottom clip top

Sutherland-Hodgman Polygon Clipping

processing polygon boundary as a whole against each window edgeoutput: list of vertices

Werner Purgathofer 16

four possible edge cases

successive processing of pairs of polygon vertices against the left window boundary

out → inoutput: Vnew, V2

in → inV2

in → outVnew

out → outno output

Sutherland-Hodgman Polygon Clipping

V1

V2 V1

V2 V1

V2

V1V2Vnew

Vnew

Werner Purgathofer 17

V2:= 1st vertex

V1:=V2V2:=next vertex

V2 visible?no

V1 visible?no

for 1 edge:

Sutherland-Hodgman Polygon Clipping

V2

V1

Werner Purgathofer 18

V2:= 1st vertex

V1:=V2V2:=next vertex

V2 visible?no

V1 visible?no

Vnew = clip edge ∩ V1V2 → result list

yes

for 1 edge:

Sutherland-Hodgman Polygon Clipping

V1

V2Vnew

Werner Purgathofer 19

V2:= 1st vertex

V1:=V2V2:=next vertex

V2 visible?no

V1 visible?

yes

yesV1 visible?

no

V’1 = clip edge ∩ V1V2 → result list

yes

V2 → result list

for 1 edge:

Sutherland-Hodgman Polygon Clipping

V1

V2

Werner Purgathofer 20

V2:= 1st vertex

V1:=V2V2:=next vertex

V2 visible?no

V1 visible?

yes

yesV1 visible?

no

V’1 = clip edge ∩ V1V2 → result list

yes no

V2 → result list

for 1 edge:

Sutherland-Hodgman Polygon Clipping

V1

V2Vnew

window

61

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 output vertex list for this window boundary

Sutherland-Hodgman Polygon Clipping

1' 2'

5'4'

3'

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

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'

Werner Purgathofer 24

extraneous lines for concave polygons:split into separate parts orfinal check of output vertex list

Sutherland-Hodgman Polygon Clipping

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

Werner Purgathofer 25

often b-reps are “triangle soups”clipping a triangle triangle(s)4 possible cases:

insideoutsidetrianglequadrilateral 2 triangles

Clipping of Triangles

(inside)

Werner Purgathofer 26

corner cases need no extra handling!

Clipping of Triangles

From Object Space to Screen Space

Werner Purgathofer 27

object space world space camera space

clip space screen space

„view frustum“modeling

transformationcamera

transformation

projectiontransformation

viewporttransformation

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 = ± hclips points that are behind the camera!reduces homogenization divisions

Einführung in Visual Computing186.822

Antialiasing

Werner Purgathofer

Antialiasing in the Rendering Pipeline

Werner Purgathofer 30raster image in pixel coordinates

clipping + homogenization

object capture/creation

modelingviewing

projection

rasterizationviewport 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

Werner Purgathofer 31

what is aliasing? ['eiliæsiη]

what is the reason for aliasing?

what can we do against it?

Aliasing and Antialiasing

Werner Purgathofer 32

too bad resolutiontoo few colorstoo few images / secgeometric errorsnumeric errors

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

What is Aliasing?

Werner Purgathofer 33

Aliasing: Staircase Effect

Werner Purgathofer 34

Various Aliasing Effects

Werner Purgathofer 35

artificial color borders can appear

Aliasing from too few Colors

Werner Purgathofer 36

jumping images"worming“

backwards rotating wheels

Aliasing in Animations

t

Werner Purgathofer 37

1. improve the deviceshigher resolutionmore color levelsfaster image sequence

2. improve the images = antialiasingpostprocessingprefiltering !

expensiveor

incompatible

software !

Solutions against Aliasing?

a signal can only be reconstructed without information lossif 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

Werner Purgathofer 39

Nyquist-Shannon Sampling Theorem

Nyquistsamplinginterval

sampling rate ∆

original signal

reconstructed signal∆

Werner Purgathofer 40

maxcycle /1xwith2 fxx cycles =∆∆=∆

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

max2 ff s =Nyquist sampling frequency:

Antialiasing: Nyquist Sampling Frequency

a signal can only be reconstructed without information lossif the sampling frequency is at least

twice the highest frequency of the signal

Werner Purgathofer 41

supersampling straight-line segmentssubpixel weighting masksarea sampling straight-line segmentsfiltering techniquescompensating for line-intensity differencesantialiasing area boundaries

(adjusting boundary pixel positions)adjusting boundary pixel intensity

Antialiasing Strategies

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 10 2 23 1 0

0 0 41 6 88 5 0

Werner Purgathofer 43

Antialiasing

Werner Purgathofer 44

calculate the pixel coverage exactlycan be done with incremental schemes

Antialiasing: Area Sampling Lines

0% 0% 43%15% 71% 84%

90% 52% 3%

Werner Purgathofer 45

relative weights for a grid of 3x3 subpixels

more weight for center subpixelsmust be divided by sum of weightssubpixel grids can also include some neighboring pixels

Antialiasing: Pixel Weighting Masks

1 2 1

2 4 2

1 2 1

Werner Purgathofer 46

box filter cone filter Gaussian filter

continuous overlapping weighting functions to calculate the antialiased values with integrals

Antialiasing: Filtering Techniques

Werner Purgathofer 47

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

Antialiasing: Intensity Differences

1

1,41421

Werner Purgathofer 48

Antialiasing Area Boundaries

Werner Purgathofer 49

adjusting pixel intensities along an area boundary

alternative 1:supersampling

Antialiasing Area Boundaries (1)

Werner Purgathofer 50

alternative 2: similar to Bresenham algorithmp' = y − ymid = [m(xk + 1) + b] − (yk + 0.5)

p'<0 ⇒ y closer to ykp'>0 ⇒ y closer to yk+1

p = p' + (1−m) :p<1−m ⇒ y closer to ykp>1−m ⇒ y closer to yk+1

( and p ∈ [0,1] )

Antialiasing Area Boundaries (2)

ymid

y = mx + b

yk + 1yk + 0.5

yk

xk + 1xk

y

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

mp for next pixel= overlap areafor current pixel

p'

p p1-m

p'

= mxk + b − (yk − 0.5)

Werner Purgathofer 52

Antialiasing Area Boundaries (4)

Werner Purgathofer 53

Antialiasing Examples

Werner Purgathofer 54

Antialiasing Examples

top related