Cli Clipping and i d A ti li Antialiasing i Werner Purgathofer - - PowerPoint PPT Presentation

cli clipping and i d a ti li antialiasing i
SMART_READER_LITE
LIVE PREVIEW

Cli Clipping and i d A ti li Antialiasing i Werner Purgathofer - - PowerPoint PPT Presentation

Einfhrung in Einfhrung in Visual Computing Visual Computing 186.822 Cli Clipping and i d A ti li Antialiasing i Werner Purgathofer g Clipping in the Rendering Pipeline object capture/creation scene objects in object space


slide-1
SLIDE 1

Einführung in Einführung in Visual Computing Visual Computing

186.822

Cli i d Clipping and A ti li i Antialiasing

Werner Purgathofer g

slide-2
SLIDE 2

Clipping in the Rendering Pipeline

scene objects in object space

  • bject capture/creation

modeling viewing

vertex stage ( vertex shader“)

g projection

(„vertex shader )

transformed vertices in clip space clipping + homogenization transformed vertices in clip space scene in normalized device coordinates viewport transformation rasterization shading

pixel stage

Werner Purgathofer 1

raster image in pixel coordinates shading

p g („fragment shader“)

slide-3
SLIDE 3

Overview: Clipping line clipping l li i polygon clipping triangle clipping g pp g

Werner Purgathofer 2

slide-4
SLIDE 4

Clipping partly visible or completely invisible parts must not be ignored and must not be drawn i d ll d ignored scrolled vertices edges  must be cut off (as early as possible) g

Werner Purgathofer 3

(as early as possible)

slide-5
SLIDE 5

Clipping Operations remove objects outside a clip window

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

  • bjects to clip: points, lines, triangles,

polygons curves text polygons, curves, text, ...

Werner Purgathofer 4

slide-6
SLIDE 6

3 Principle Possibilities for Clipping analytically in world coordinates

reduces WC DC transformations reduces WC DC transformations

analytically in clip coordinates

simple comparisons simple comparisons

d i t ti during raster conversation = as part of the rasterization algorithm

may be efficient for complex primitives

Werner Purgathofer 5

slide-7
SLIDE 7

Line Clipping (1)

P9 P10 P4 P2 P2 P1 P6 P8 P10 P3 P1 P6 P´8

6

P7 P5 P3

6

P´5 P´7

before clipping after clipping

7 7

[line clipping against a rectangular clip window]

pp g pp g

Werner Purgathofer 6

slide-8
SLIDE 8

Line Clipping (2) goals

eliminate simple cases fast eliminate simple cases fast avoid intersection calculations

for endpoints (x0,y0), (xend,yend) for endpoints (x0,y0), (xend,yend) intersect parametric representation x = x0 + u·(x

  • x0)

x x0 + u (xend x0) y = y0 + u·(yend - y0) with window borders: with window borders: intersection  0 < u < 1

Werner Purgathofer 7

slide-9
SLIDE 9

Cohen-Sutherland Line Clipping assignment of region codes to line endpoints

bit1: left

1001 1000 1010

Window

bit2: right bit3: below

0001 0000 0010

bit3: below bit4: above

0101 0100 0110 0101 0100 0110

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

Werner Purgathofer 8

the clipping rectangle

slide-10
SLIDE 10

Cohen-Sutherland Line Clipping “or” of codes of both

1001 1000 1010

  • r of codes of both

points = 0000  li ti l i ibl

Window

0001 0000 0010

line entirely visible “and” of codes of both

0101 0100 0110

points  0000  line entirely invisible

0101 0100 0110

line entirely invisible all others intersect!

Werner Purgathofer 9

slide-11
SLIDE 11

Cohen-Sutherland Line Clipping

P2 [lines extending from one coordinate Window P2 P”2 P’2 from one coordinate region to another may pass through Window P 2 may pass through the clip window, or they may intersect they may intersect clipping boundaries without entering the P3 P’1 without entering the window] P1 P4 P’3

Werner Purgathofer 10

slide-12
SLIDE 12

Cohen-Sutherland Line Clipping remaining lines

intersection test with bounding lines of clipping intersection test with bounding lines of clipping window left, right, bottom, top discard an outside part discard an outside part repeat intersection test up to four times vertical: y = y0 + m(xwmin – x0), y = y0 + m(xwmax – x0) horiz : + ( )/m + ( )/m

Werner Purgathofer 11

horiz.: x = x0 + (ywmin – y0)/m, x = x0 + (ywmax – y0)/m

slide-13
SLIDE 13

Cohen-Sutherland Line Clipping

P passes through li i i d Wi d P2 P” P’2 clipping window Window P 2 intersects boundaries without boundaries without entering clipping window P3 P’1 window P1 P4 P’3

vertical: y = y0 + m(xwmin – x0), y = y0 + m(xwmax – x0) horiz : + ( )/m + ( )/m

Werner Purgathofer 12

horiz.: x = x0 + (ywmin – y0)/m, x = x0 + (ywmax – y0)/m

slide-14
SLIDE 14

Polygon Clipping modification of line clipping goal: one or more closed areas g

[di l f l [display of a polygon [display of a correctly clipped polygon] [display of a polygon processed by a line- clipping algorithm]

Werner Purgathofer 13

clipping algorithm]

slide-15
SLIDE 15

Sutherland-Hodgman Polygon Clipping processing polygon boundary as a whole against each window edge against each window edge

  • utput: list of vertices
  • riginal

polygon clip left clip right clip bottom clip top clipping a polygon against successive polygon

Werner Purgathofer 14

window boundaries

slide-16
SLIDE 16

Sutherland-Hodgman Polygon Clipping four possible edge cases

V1 V2 V2 V1 V1 V2 Vnew V V

2 1

  • ut  in

in  in in  out

  • ut  out

V1 V2 V1 V2 Vnew

  • ut  in
  • utput: Vnew, V2

in  in V2 in  out Vnew

  • ut  out

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

Werner Purgathofer 15

vertices against the left window boundary

slide-17
SLIDE 17

V2:= 1st vertex

for 1 edge:

Sutherland-Hodgman

V1:=V2 V1: V2 V2:=next vertex V2 result list V2 visible?

no yes

V1 visible?

yes

V1 visible?

no yes no V1 visible?

V1 visible? V’1 = clip edge  V1V2 result list

Werner Purgathofer 16

slide-18
SLIDE 18

Sutherland-Hodgman Polygon Clipping

Window 3 [clipping a polygon against the left 2’ 2 against the left boundary of a window, starting with vertex 1. 1’ 2’ 1 4 starting with vertex 1. Primed numbers are used to label the points 3’ 6 1 4 used to label the points in the output vertex list for this window 5’ 3’ 5 for this window boundary]

finished!

5 4’ 5

Werner Purgathofer 17

slide-19
SLIDE 19

Polygon Clip: Combination of 4 Passes the polygon is clipped against each of the 4 borders separately borders separately, that would produce 3 intermediate results. by calling the 4 tests recursively by calling the 4 tests recursively, (or by using a clipping pipeline) every result point is immediately processed every result point is immediately processed

  • n, so that only one result list is produced

Werner Purgathofer 18

slide-20
SLIDE 20

Sutherland-Hodgman Clipping Example

2

pipeline of boundary

Window

2

boundary clippers to avoid 1st clip: left

2’

avoid intermediate li left

2 1’ 3

vertex lists 2nd clip:

2” 1’ 1

2 clip: bottom

3’

[Processing the polygon vertices through a boundary-clipping

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

Werner Purgathofer 19

the vertex list for the clipped polygon is {1’, 2, 2’, 2”} ]

slide-21
SLIDE 21

Sutherland-Hodgman Polygon Clipping extraneous lines for concave polygons:

split into separate parts

  • r

split into separate parts or final check of output vertex list

[clipping the concave polygon with the Sutherland-

Werner Purgathofer 20

[ pp g p yg Hodgeman clipper produces three connected areas]

slide-22
SLIDE 22

Clipping of Triangles

  • ften b-reps are “triangle soups”

li i t i l  t i l ( ) clipping a triangle  triangle(s) 4 possible cases: p

inside

  • tside

(inside)

  • utside

triangle quadrilateral  2 triangles

Werner Purgathofer 21

slide-23
SLIDE 23

Clipping of Triangles corner cases need no extra handling!

Werner Purgathofer 22

slide-24
SLIDE 24

From Object Space to Screen Space

modeling transformation camera transformation

  • bject space

world space camera space

projection p j transformation viewport transformation

Werner Purgathofer 23

clip space screen space

slide-25
SLIDE 25

Clipping in Clip-Space clipping against x = ± 1, y = ± 1, z = ± 1 ( ) i id ? (x,y,z) inside?  only compare one value! y p is done before homogenization:

  • ge

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

Werner Purgathofer 24

reduces homogenization divisions

slide-26
SLIDE 26

Antialiasing Antialiasing

slide-27
SLIDE 27

Antialiasing in the Rendering Pipeline

scene objects in object space

  • bject capture/creation

modeling viewing

vertex stage ( vertex shader“)

g projection

(„vertex shader )

transformed vertices in clip space clipping + homogenization transformed vertices in clip space scene in normalized device coordinates viewport transformation rasterization shading

pixel stage

Werner Purgathofer 26

raster image in pixel coordinates shading

p g („fragment shader“)

slide-28
SLIDE 28

Aliasing and Antialiasing h t i li i ? [' ili i ] what is aliasing? ['eiliæsiη] what is the reason for aliasing? what can we do against it? what can we do against it?

Werner Purgathofer / Computergraphik 1 27

slide-29
SLIDE 29

What is Aliasing?

errors that are caused by the discretization

too bad resolution

  • f analog data to digital data

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

Werner Purgathofer / Computergraphik 1 28

g numeric errors

slide-30
SLIDE 30

Aliasing: Staircase Effect

Werner Purgathofer / Computergraphik 1 29

slide-31
SLIDE 31

Various Aliasing Effects

Werner Purgathofer / Computergraphik 1 30

slide-32
SLIDE 32

Aliasing from too few Colors

artificial color borders can appear artificial color borders can appear

Werner Purgathofer / Computergraphik 1 31

slide-33
SLIDE 33

Aliasing in Animations jumping images "worming“

t

backwards rotating wheels

Werner Purgathofer / Computergraphik 1 32

slide-34
SLIDE 34

Solutions against Aliasing?

  • 1. improve the devices

p

higher resolution more color levels

expensive

  • r

more color levels faster image sequence

incompatible

2 improve the images = antialiasing

  • 2. improve the images = antialiasing

postprocessing

software

prefiltering !

software

Werner Purgathofer / Computergraphik 1 33

slide-35
SLIDE 35

Nyquist-Shannon Sampling Theorem a signal can only be reconstructed without information loss if the sampling frequency is at least twice the highest frequency is at least twice the highest frequency of the signal this border frequency is called "Nyquist Limit" q y yq

Werner Purgathofer / Computergraphik 1 34

slide-36
SLIDE 36

Nyquist-Shannon Sampling Theorem

  • riginal signal

g g reconstructed signal

Nyquist Nyquist sampling interval

sampling rate 

interval

Werner Purgathofer / Computergraphik 1 35

slide-37
SLIDE 37

Antialiasing: Nyquist Sampling Frequency a signal can only be reconstructed without information loss if the sampling without information loss if the sampling frequency is at least twice the highest f f th i l frequency of the signal

max

2 f fs 

Nyquist sampling frequency:

max cycle

/ 1 x with f x x

cycle s

    

max cycle

2 f

s

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

Werner Purgathofer / Computergraphik 1 36

i.e. sampling interval  one half cycle interval

slide-38
SLIDE 38

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

(adjusting boundary pixel positions) adjusting boundary pixel intensity

Werner Purgathofer / Computergraphik 1 37

slide-39
SLIDE 39

Antialiasing: Supersampling Lines

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

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

Werner Purgathofer / Computergraphik 1 38

0 = min. intensity 0 = min. intensity

slide-40
SLIDE 40

Antialiasing

Werner Purgathofer / Computergraphik 1 39

slide-41
SLIDE 41

Antialiasing: Pixel Weighting Masks more weight for center subpixels center subpixels must be divided by y sum of weights subpixel grids can subpixel grids can also include some i hb i i l neighboring pixels relative weights for a grid of 3x3 subpixels

Werner Purgathofer / Computergraphik 1 40

grid of 3x3 subpixels

slide-42
SLIDE 42

Antialiasing: Area Sampling Lines calculate the pixel coverage exactly

0% 0% 0% 0% 43% 43%

coverage exactly can be done with

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

incremental schemes

15% 15% 71% 71% 84% 84% 90% 90% 52% 52% 3% 3% 90% 90% 52% 52% 3% 3%

Werner Purgathofer / Computergraphik 1 41

slide-43
SLIDE 43

Antialiasing: Filtering Techniques continuous overlapping weighting functions to calculate the antialiased values with integrals to calculate the antialiased values with integrals

Werner Purgathofer / Computergraphik 1 42

box filter cone filter Gaussian filter

slide-44
SLIDE 44

Antialiasing: Intensity Differences unequal line lengths q g displayed with the same number of same number of pixels in each line/row have line/row have different intensities proper antialiasing compensates for compensates for that!

Werner Purgathofer / Computergraphik 1 43

slide-45
SLIDE 45

Antialiasing Area Boundaries

Werner Purgathofer / Computergraphik 1 44

slide-46
SLIDE 46

Antialiasing Area Boundaries (1) alternative 1: supersampling supersampling adjusting pixel adjusting pixel intensities along an area boundary area boundary

Werner Purgathofer / Computergraphik 1 45

slide-47
SLIDE 47

Antialiasing Area Boundaries (2) alternative 2: similar to Bresenham algorithm ´ [ ( 1) b] ( 0 5) p´ = y  ymid = [m(xk + 1) + b]  (yk + 0.5) p´<0  y closer to y p <0  y closer to yk p´>0  y closer to yk+1 p = p´+(1m) : y y

id

p p +(1 m) : p<1m  closer to yk p>1 m  closer to y ymid p>1m  closer to yk+1 ( and p  [0,1] )

Werner Purgathofer / Computergraphik 1 46

( and p  [0,1] )

slide-48
SLIDE 48

Antialiasing Area Boundaries (3) p = p´+(1m)= [m(xk + 1) + b]  (yk + 0.5) + (1  m) = mx + b y + 0 5 = = mx + b (y 0 5) = mxk + b  yk + 0.5 = mxk + b  (yk  0.5) yk+ 0 5 p for next pixel yk+ 0.5 p for next pixel = overlap area for current pixel p´ yk m for current pixel p p x x +1 p 1-m p p´

Werner Purgathofer / Computergraphik 1 47

xk xk+1 p

slide-49
SLIDE 49

Antialiasing Area Boundaries (4)

Werner Purgathofer / Computergraphik 1 48

slide-50
SLIDE 50

Antialiasing Examples

Werner Purgathofer / Computergraphik 1 49