evc-08 clipping+antialiasing slides€¦ · polygon clipping df f l l modification o ine c ipping...

Post on 17-Jun-2020

2 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Einführung in Visual ComputingEinführung in Visual Computing186.822

ClippingClipping

W P h fWerner Purgathofer

Viewing in the Rendering PipelineViewing  in the Rendering Pipelinebj t t / tiobject capture/creation

bj t i bj tmodeling

scene objects in object spacemodelingviewing vertex stageviewing

projection

g(„vertex shader“)

projectiont f d ti i li

clipping + homogenizationtransformed vertices in clip space

clipping + homogenizationi li d d i di t

viewport transformationscene in normalized device coordinates

t i tiviewport transformation

rasterizationh di pixel stageshading pixel stage

(„fragment shader“)Werner Purgathofer 2raster image in pixel coordinates

(„fragment shader )

Overview: ClippingOverview: Clipping

line clippingpolygon clippingp yg pp gtriangle clippingtriangle clipping

Werner Purgathofer 3

ClippingClipping

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

ignored?: scrolled?:

vertices edgesvertices edges must be cut off  (as early as possible)

Werner Purgathofer 4

Clipping OperationsClipping Operations

remove objects outside a clip windowclip window: rectangle, polygon, curved boundariesp g , p yg ,applied somewhere in the viewing pipelineapplied somewhere in the viewing pipelinecan be combined with scan conversioncan be combined with scan conversionobjects to clip: points lines triangles polygons curves textobjects to clip: points, lines, triangles, polygons, curves, text, ...

Werner Purgathofer 5

3 Principle Possibilities for Clipping3 Principle Possibilities for Clipping

analytically in world coordinatesreduces WC DC transformations

analytically in clip coordinatesanalytically in clip coordinatessimple comparisonssimple comparisons

during raster conversationduring raster conversation= as part of the rasterization algorithm= as part of the rasterization algorithm

b ffi i t f l i itimay be efficient for complex primitives

Werner Purgathofer 6

Line Clipping (1)Line Clipping (1)P9

PP10P4 P2 P2

P8

2 2

P'P1 P6

8

PP1 P6

P'8P6P3

P6P'5

P7P5

5P'7

before lippin after lippin

7 7

before clipping after clipping

[line clipping against a rectangular clip window][line clipping against a rectangular clip window]

Werner Purgathofer 7

Line Clipping (2)Line Clipping (2)

goalseliminate simple cases fastpavoid intersection calculationsavoid intersection calculations 

for endpoints (x0,y0), (xend,yend)for endpoints (x0,y0), (xend,yend)intersect parametric representationp p

x = x0 + u·(xend - x0)0 ( end 0)y = y0 + u·(yend - y0)y y0 (yend y0)

with window borders:intersection 0 < u < 1

Werner Purgathofer 8

Line Clipping (2)Line Clipping (2)

goalseliminate simple cases fastpavoid intersection calculationsavoid intersection calculations 

for endpoints (x0,y0), (xend,yend)for endpoints (x0,y0), (xend,yend)intersect parametric representationp p

x = x0 + u·(xend - x0)( ) ( ) ( )0 ( end 0)y = y0 + u·(yend - y0)( ) ( ) ( )y y0 (yend y0)

with window borders:

( ) ( ) ( )intersection 0 < u < 1

Werner Purgathofer 9

Cohen‐Sutherland Line ClippingCohen Sutherland Line Clipping

assignment of region codes to line endpoints

bit1: left1001 1000 1010

Window

bit1: leftbit2: rightbit2: rightbit3 b l

0001 0000 0010bit3: belowbit4: above 0101 0100 0110

b d d l d d lbinary region codes assigned to line endpoints according to relative i i i h h li i lposition with respect to the clipping rectangle

Werner Purgathofer 10

Cohen‐Sutherland Line ClippingCohen Sutherland Line Clipping

“or” of codes of both points= 0000  line entirely visible 1001 1000 1010

Window

“and” of codes of both points 0001 0000 0010and  of codes of both points 0000 line entirely invisible 0000  line entirely invisible

0101 0100 0110

ll h i !all others intersect!

Werner Purgathofer 11

Cohen‐Sutherland Line ClippingCohen Sutherland Line Clipping

lines extending from oneP2 P'2 lines extending from one 

di t i t thi dP"P 2

coordinate region to another th h th li

windowP 2

may pass through the clip i d th i t twindow, or they may intersect li i b d i ith tclipping boundaries without 

i h i dentering the windowP3 P'13

PP

P 1

P' P1P4P 3

Werner Purgathofer 12

Cohen‐Sutherland Line ClippingCohen Sutherland Line Clipping

remaining linesintersection test with bounding lines of clipping windowg pp gleft, right, bottom, topleft, right, bottom, topdiscard an outside partdiscard an outside partrepeat intersection test up to four timesrepeat intersection test up to four times

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

Cohen‐Sutherland Line ClippingCohen Sutherland Line ClippingPP2 P'2

passes through clipping window windowP"2 window2

intersects boundaries without entering clipping windowg pp g

P3 P'1P1P4

P'3 P1P43

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

Polygon Clippingd f f l l

Polygon Clippingmodification of line clipping

l l dgoal: one or more closed areas

display of a correctly display of a polygon processed  p y yclipped polygon

p y p yg pby a line‐clipping algorithm pp p ygy pp g g

Werner Purgathofer 15

Sutherland‐Hodgman Polygon ClippingSutherland Hodgman Polygon Clipping

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

i i loriginall

clip left clip right clip bottom clip toppolygon

p p g p p p

clipping a polygon against successive window boundariespp g p yg g

Werner Purgathofer 16

Sutherland‐Hodgman Polygon Clippingf ibl dSutherland Hodgman Polygon Clippingfour possible edge cases

VV V1V2Vnew

V2 V1

V2 V1VV1 V2Vnew

out  in in in in out out outoutput: Vnew, V2 V2 Vnew no output

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

Werner Purgathofer 17

Sutherland‐Hodgman Polygon ClippingSutherland Hodgman Polygon Clipping

V2:= 1st vertexfor 1 edge: 2g

V1:=V21 2V2:=next vertex V2 result list

V2 visible?no yes

2

V1 visible?yes

V1 visible?no yes no V1 visible?V1 visible?

V’ clip edge V V res lt listV’1 = clip edge  V1V2 result list

Werner Purgathofer 18

Sutherland‐Hodgman Polygon ClippingSutherland Hodgman Polygon Clipping

windowli i l i

3clipping a polygon against h l f b d f 3the left boundary of a 

d hwindow, starting with 

2vertex 1.  2

1 4primed numbers are used 

64to label the points in the  6

output vertex list for this window boundary

5Werner Purgathofer 19

Sutherland‐Hodgman Polygon ClippingSutherland Hodgman Polygon Clipping

windowli i l i

3clipping a polygon against h l f b d f 3the left boundary of a 

d hwindow, starting with  1' 2'2vertex 1.  12

1 4primed numbers are used  3'

64to label the points in the 

36

output vertex list for this  5'4'window boundary finished!4'5

finished!Werner Purgathofer 20

Polygon Clip: Combination of 4 PassesPolygon 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 recursivelyby calling the 4 tests recursively,(or by using a clipping pipeline)(or by using a clipping pipeline)every result point is immediately processed onevery result point is immediately processed on, so that only one result list is producedso that only one result list is produced

Werner Purgathofer 21

Sutherland‐Hodgman Clipping ExampleSutherland Hodgman Clipping Examplepipeline of boundary  windowclippers to avoid  2 1st clip:intermediate vertex lists left

3 2nd li3

12nd clip:b tt1 bottom

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"} Werner Purgathofer 22

Sutherland‐Hodgman Clipping ExampleSutherland Hodgman Clipping Examplepipeline of boundary  windowclippers to avoid  2 1st clip:intermediate vertex lists left 2'2

1'3 2nd li

2"1

3

12nd clip:b tt3' 1 bottom3'

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"} Werner Purgathofer 23

Sutherland‐Hodgman Polygon ClippingSutherland Hodgman Polygon Clipping

extraneous lines for concave polygons:split into separate parts    orp p pfinal check of output vertex listfinal check of output vertex list

li i hclipping the concave l i h hpolygon with the h l d dSutherland‐Hodgeman 

clipper produces three connected areas

Werner Purgathofer 24

Clipping of TrianglesClipping of Triangles

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

insideinsidet id

(inside)outsidetrianglequadrilateral  2 triangles

Werner Purgathofer 25

Clipping of TrianglesClipping of Triangles

corner cases need no extra handling!

Werner Purgathofer 26

From Object Space to Screen SpaceFrom Object Space to Screen Spaceview frustum“„view frustum“

modeling cameragtransformation transformation

object space world space camera spaceobject space world space camera space

projectiont f ti

viewporttransformation transformation

Werner Purgathofer 27clip space screen space

Clipping in Clip‐SpaceClipping in Clip Space

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

is done before homogenization:is done before homogenization:x = ± h y = ± h z = ± hx = ± h, y = ± h, z = ± hclips points that are behind the camera!clips points that are behind the camera!d h i ti di i ireduces homogenization divisions

Werner Purgathofer 28

Einführung in Visual ComputingEinführung in Visual Computing186.822

AntialiasingAntialiasing

W P h fWerner Purgathofer

Antialiasing in the Rendering PipelineAntialiasing   in the Rendering Pipelinebj t t / tiobject capture/creation

bj t i bj tmodeling

scene objects in object spacemodelingviewing vertex stageviewing

projection

g(„vertex shader“)

projectiont f d ti i li

clipping + homogenizationtransformed vertices in clip space

clipping + homogenizationi li d d i di t

viewport transformationscene in normalized device coordinates

t i tiviewport transformation

rasterizationh di pixel stageshading pixel stage

(„fragment shader“)Werner Purgathofer 30raster image in pixel coordinates

(„fragment shader )

Aliasing and AntialiasingAliasing and Antialiasing

what is aliasing? ['eiliæsiη]what is aliasing?         [ eiliæsiη]

h t i th f li i ?what is the reason for aliasing?

what can we do against it?

Werner Purgathofer  31

What is Aliasing?What is Aliasing?

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

too bad resolutiontoo few colorstoo few images / secgeometric errorsnumeric errors

Werner Purgathofer  32

Aliasing: Staircase EffectAliasing: Staircase Effect

Werner Purgathofer  33

Various Aliasing EffectsVarious Aliasing Effects

Werner Purgathofer  34

Aliasing from too few ColorsAliasing from too few Colors

artificial color borders can appearartificial color borders can appear

Werner Purgathofer  35

Aliasing in AnimationsAliasing in Animations

jumping imagesj p g g"worming“worming

tt

backwards rotating wheelsbackwards rotating wheels

Werner Purgathofer  36

Solutions against Aliasing?Solutions against Aliasing?

1 impro e the de ices1. improve the devicesh h l expensivehigher resolution expensive

ormore color levels

or incompatible

faster image sequenceincompatible

2. improve the images = antialiasing2. improve the images   antialiasingpostprocessingpostprocessingprefiltering !

software !prefiltering !

Werner Purgathofer  37

Nyquist‐Shannon Sampling TheoremNyquist Shannon Sampling Theorem

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

twice the highest frequency of the signaltwice the highest frequency of the signal

this border frequency is called "Nyquist Limit"

Werner Purgathofer 38

Nyquist‐Shannon Sampling TheoremNyquist Shannon Sampling Theorem

i i l i loriginal signal

d i lreconstructed signal

Nyquist

Nyquistsamplingsampling rate  samplingintervalinterval

Werner Purgathofer  39

Antialiasing: Nyquist Sampling FrequencyAntialiasing: Nyquist Sampling Frequency

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

twice the highest frequency of the signaltwice the highest frequency of the signal

2 ff Nyquist sampling frequency: max2 ff sNyquist sampling frequency:

/1 fxcycle maxcycle /1xwith2 fx cycles

2i.e. sampling interval  one‐half cycle interval

Werner Purgathofer  40

Antialiasing StrategiesAntialiasing Strategies

supersampling straight‐line segmentssupersampling straight line segmentssubpixel weighting maskssubpixel weighting masks

li t i ht li tarea sampling straight‐line segmentsfiltering techniquescompensating for line‐intensity differencesp g yantialiasing area boundariesantialiasing area boundaries

(adjusting boundary pixel positions)(adjusting boundary pixel positions)adjusting boundary pixel intensityadjusting boundary pixel intensity

Werner Purgathofer  41

Antialiasing: Supersampling LinesAntialiasing: Supersampling Lines

00 00 11 00 00 4400 00 11 00 00 4400 22 22 11 66 8800 22 22 11 66 8833 11 00 88 55 0033 11 00 88 55 00

mathematical line line of finite width3 = max intensity 9 = max intensity3 max. intensity...

9 max. intensity...

0 = min. intensity 0 = min. intensityWerner Purgathofer  42

AntialiasingAntialiasing

Werner Purgathofer  43

Antialiasing: Area Sampling LinesAntialiasing: Area Sampling Lines

calculate the pixel coverage exactlycan be done with incremental schemes 0%0% 0%0% 43%43%

15%15% 71%71% 84%84%15%15% 71%71% 84%84%

90%90% 52%52% 3%3%90%90% 52%52% 3%3%

Werner Purgathofer  44

Antialiasing: Pixel Weighting MasksAntialiasing: Pixel Weighting Masks

more weight for center gsubpixelspmust be divided by sum of1 2 1 must be divided by sum of weightsweightssubpixel grids can also include2 4 2 subpixel grids can also include some neighboring pixels

2 4 2some neighboring pixels

1 2 11 2 1

l ti i ht f id f 3 3 b i lrelative weights for a grid of 3x3 subpixels

Werner Purgathofer  45

Antialiasing: Filtering TechniquesAntialiasing: Filtering Techniquescontinuous overlapping weighting functions to calculate the antialiased values with integrals

box filter cone filter Gaussian filterWerner Purgathofer  46

box filter       cone filter    Gaussian filter

Antialiasing: Intensity DifferencesAntialiasing:  Intensity Differences

unequal line lengths displayedunequal line lengths displayed with the same number ofwith the same number of pixels in each line/row have1,41421 pixels in each line/row have different intensities

1,41421different intensities

i li iproper antialiasing f h !compensates for that!

1Werner Purgathofer  47

Antialiasing Area BoundariesAntialiasing Area Boundaries

Werner Purgathofer  48

Antialiasing Area Boundaries (1)Antialiasing Area Boundaries (1)alternative 1:supersampling

adjusting pixel intensities along j g p gan area boundary

Werner Purgathofer  49

Antialiasing Area Boundaries (2)Antialiasing Area Boundaries (2)

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

p'<0 y closer to yky = mx + bp'>0 y closer to yk+1

y mx b

+ 1 p = p' + (1m) :yyk + 1

y + 0 5 y p p ( )p<1m y closer to yk

ymidyk + 0.5y

yk

p>1m y closer to yk+1yk

k 1

xk + 1xk( and p [0,1] )

xk + 1xk

Werner Purgathofer  50

Antialiasing Area Boundaries (3)Antialiasing Area Boundaries (3)

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

y + 0 5yk+ 0.5p'

p for next pixel

p

y mp for next pixel= overlap areayk m = overlap areafor current pixelfor current pixel

p p11-m

p'xk xk+1p'

Werner Purgathofer 51

Antialiasing Area Boundaries (4)Antialiasing Area Boundaries (4)

Werner Purgathofer 52

Antialiasing ExamplesAntialiasing Examples

Werner Purgathofer  53

top related