Einführung in Visual Computing g p g
186.822
Cli Clipping i Werner Purgathofer Werner Purgathofer Viewing in - - PowerPoint PPT Presentation
Einfhrung in Visual Computing g p g 186.822 Cli Clipping i Werner Purgathofer Werner Purgathofer Viewing in the Rendering Pipeline g g p object capture/creation j p scene objects in object space modeling modeling vertex stage
186.822
j p modeling scene objects in object space modeling viewing
vertex stage
viewing projection
(„vertex shader“)
p j transformed vertices in clip space clipping + homogenization i li d d i di t viewport transformation scene in normalized device coordinates rasterization viewport transformation shading
pixel stage ( fragment shader“)
Werner Purgathofer 2
raster image in pixel coordinates
(„fragment shader )
line clipping
line clipping polygon clipping polygon clipping triangle clipping triangle clipping
Werner Purgathofer 3
partly visible or completely invisible parts b b must not be ignored and must not be drawn ignored?: scrolled?: vertices edges vertices edges must be cut off (as early as possible) must be cut off (as early as possible)
Werner Purgathofer 4
remove objects outside a clip window
remove objects outside a clip window
clip window: rectangle, polygon, curved boundaries clip window: rectangle, polygon, curved boundaries applied somewhere in the viewing pipeline pp g p p can be combined with scan conversion
Werner Purgathofer 5
analytically in world coordinates
analytically in world coordinates
reduces WC DC transformations reduces WC DC transformations
analytically in clip coordinates
simple comparisons
during raster conversation during raster conversation = as part of the rasterization algorithm as part of the rasterization algorithm
may be efficient for complex primitives y p p
Werner Purgathofer 6
P9 P P4 P2 P2 P P8 P10 P P´8 P1 P6 P8 P3 P1 P6 P´
8
P7 P5 P 5 P´7
before clipping after clipping
7 7
before clipping after clipping
Werner Purgathofer 7
goals
goals
eliminate simple cases fast eliminate simple cases fast avoid intersection calculations
for endpoints (x0,y0), (xend,yend) intersect parametric representation intersect parametric representation x = x0 + u·(xend - x0) u (
end 0)
y = y0 + u·(yend - y0) with window borders: i t ti
< 1 intersection 0 < u < 1
Werner Purgathofer 8
assignment of region codes to line endpoints
assignment of region codes to line endpoints
bit1: left
1001 1000 1010
Window
bit1: left bit2: right
0001 0000 0010
g bit3: below
0001 0000 0010
bit4: above
0101 0100 0110 binary region codes assigned to line endpoints according to relative binary region codes assigned to line endpoints according to relative position with respect to the clipping rectangle position with respect to the clipping rectangle
Werner Purgathofer 9
“or” of codes of both points p = 0000 line entirely visible 1001 1000 1010
Window
0001 0000 0010 “and” of codes of both points 0000 li ti l i i ibl 0001 0000 0010 0000 line entirely invisible 0101 0100 0110 all others intersect! all others intersect!
Werner Purgathofer 10
P2 P’
window P” P’2
window P 2
P3 P’1 P1 P4 P’3
1
P4
Werner Purgathofer 11
remaining lines
remaining lines
intersection test with bounding lines of clipping window intersection test with bounding lines of clipping window left, right, bottom, top , g , , p discard an outside part repeat intersection test up to four times
vertical: y = y + m(xw x ) y = y + m(xw x ) vertical: y = y0 + m(xwmin – x0), y = y0 + m(xwmax – x0) horizontal: x = x0 + (ywmin – y0)/m, x = x0 + (ywmax – y0)/m
Werner Purgathofer 12
(ywmin y0)/ , (ywmax y0)/
P2 P’
passes through clipping window
window P”2 P 2
p g pp g
window P 2
intersects boundaries without entering clipping window entering clipping window
P3 P’1 P1 P4 P’3
vertical: y = y + m(xw x ) y = y + m(xw x )
4
vertical: y = y0 + m(xwmin – x0), y = y0 + m(xwmax – x0) horizontal: x = x0 + (ywmin – y0)/m, x = x0 + (ywmax – y0)/m
Werner Purgathofer 13
(ywmin y0)/ , (ywmax y0)/
modification of line clipping
modification of line clipping goal: one or more closed areas
Werner Purgathofer 14
processing polygon boundary as a whole against each window edge processing polygon boundary as a whole against each window edge
polygon clip left clip right clip bottom clip top li i l i t i i d b d i polygon clipping a polygon against successive window boundaries
Werner Purgathofer 15
four possible edge cases
p g
V1 V2 Vnew V2 V1
new
V1 V2 V1 V2 Vnew
in in in out
V1 V2
V2 Vnew no output successive processing of pairs of polygon vertices against the successive processing of pairs of polygon vertices against the left window boundary
Werner Purgathofer 16
y
V := 1st vertex
V2:= 1st vertex
V1:=V2 V2:=next vertex V2 result list V visible?
no yes
V2 visible?
y
V1 visible?
yes
V1 visible?
no yes no
1 1
V’1 = clip edge V1V2 result list
Werner Purgathofer 17
Werner Purgathofer 18
the polygon is clipped against each of the 4 borders separately the polygon is clipped against each of the 4 borders separately, that would produce 3 intermediate results. p by calling the 4 tests recursively, (or by using a clipping pipeline) l i i i di l d every result point is immediately processed on, so that only one result list is produced so that only one result list is produced
Werner Purgathofer 19
pipeline of boundary
window
pipeline of boundary clippers to avoid
2
1st clip:
window
intermediate vertex lists p left
2’ 2 3 2” 1’ 3
2nd clip: b tt
3’
1
bottom
3’
Werner Purgathofer 20
extraneous lines for concave polygons:
extraneous lines for concave polygons:
split into separate parts
split into separate parts or final check of output vertex list p
Werner Purgathofer 21
clipping a triangle triangle(s) clipping a triangle triangle(s) 4 possible cases: 4 possible cases:
inside
triangle quadrilateral 2 triangles
Werner Purgathofer 22
corner cases need no extra handling!
corner cases need no extra handling!
Werner Purgathofer 23
„view frustum“ d li modeling transformation camera transformation
world space camera space projection transformation viewport transformation transformation transformation
Werner Purgathofer 24
clip space screen space
clipping against x = ± 1 y = ± 1 z = ± 1
clipping against x = ± 1, y = ± 1, z = ± 1 (x y z) inside? (x,y,z) inside? only compare one value! only compare one value! is done before homogenization: x = ± h, y = ± h, z = ± h li i h b hi d h ! clips points that are behind the camera! d h i ti di i i reduces homogenization divisions
Werner Purgathofer 25
186.822
j p modeling scene objects in object space modeling viewing
vertex stage
viewing projection
(„vertex shader“)
p j transformed vertices in clip space clipping + homogenization i li d d i di t viewport transformation scene in normalized device coordinates rasterization viewport transformation shading
pixel stage ( fragment shader“)
Werner Purgathofer 27
raster image in pixel coordinates
(„fragment shader )
what is aliasing? ['eiliæsiη] what is aliasing? [ eiliæsiη] what is the reason for aliasing? what is the reason for aliasing? what can we do against it? g
Werner Purgathofer 28
errors that are caused by the discretization of analog data to digital data
too bad resolution too few colors f / too few images / sec geometric errors geometric errors numeric errors
Werner Purgathofer 29
numeric errors
Werner Purgathofer 30
Werner Purgathofer 31
artificial color borders can appear artificial color borders can appear
Werner Purgathofer 32
jumping images
jumping images "worming“ worming
backwards rotating wheels g
Werner Purgathofer 33
expensive
higher resolution
expensive
more color levels f t i
incompatible
faster image sequence
2 improve the images = antialiasing
postprocessing
f !
postprocessing prefiltering !
software !
p g
Werner Purgathofer 34
a signal can only be reconstructed without information loss if h li f i l if the sampling frequency is at least twice the highest frequency of the signal twice the highest frequency of the signal this border frequency is called "Nyquist Limit" this border frequency is called Nyquist Limit
Werner Purgathofer 35
Nyquist sampling
sampling interval
Werner Purgathofer 36
a signal can only be reconstructed without information loss if h li f i l if the sampling frequency is at least twice the highest frequency of the signal twice the highest frequency of the signal
N q ist samplin freq enc
max
Nyquist sampling frequency:
ith
cycle
max cycle
with
y s
i.e. sampling interval one‐half cycle interval
Werner Purgathofer 37
p g y
li i h li
supersampling straight‐line segments b i l i hti k subpixel weighting masks area sampling straight line segments area sampling straight‐line segments filtering techniques filtering techniques compensating for line‐intensity differences compensating for line‐intensity differences antialiasing area boundaries antialiasing area boundaries
(adjusting boundary pixel positions) (adjusting boundary pixel positions) adjusting boundary pixel intensity
Werner Purgathofer 38
mathematical line line of finite width 3 = max. intensity 9 = max. intensity ... 0 = min. intensity ... 0 = min. intensity
Werner Purgathofer 39
y y
Werner Purgathofer 40
more weight for center
more weight for center subpixels subpixels must be divided by sum of must be divided by sum of weights subpixel grids can also include some neighboring pixels relative weights for a grid of 3x3 subpixels relative weights for a grid of 3x3 subpixels
Werner Purgathofer 41
calculate the pixel coverage exactly
calculate the pixel coverage exactly can be done with incremental schemes
can be done with incremental schemes
Werner Purgathofer 42
continuous overlapping weighting functions
continuous overlapping weighting functions to calculate the antialiased values with integrals box filter cone filter Gaussian filter
Werner Purgathofer 43
box filter cone filter Gaussian filter
unequal line lengths displayed i h h b f with the same number of pixels in each line/row have 1,41421 pixels in each line/row have different intensities , proper antialiasing p p g compensates for that! 1
Werner Purgathofer 44
Werner Purgathofer 45
alternative 1:
( )
alternative 1: supersampling adjusting pixel intensities adjusting pixel intensities along an area boundary
Werner Purgathofer 46
alternative 2: similar to Bresenham algorithm
( )
alternative 2: similar to Bresenham algorithm p´ = y y = [m(x + 1) + b] (y + 0 5) p = y ymid = [m(xk + 1) + b] (yk + 0.5) ´ 0 l p´<0 y closer to yk p´>0 y closer to y
y = mx + b
p >0 y closer to yk+1 p = p´ + (1m) : y
yk + 1 + 0 5
y p p ( ) p<1m y closer to yk ymid
yk + 0.5 yk
y p>1m y closer to yk+1
yk
( and p [0,1] )
xk + 1 xk
Werner Purgathofer 47
( and p [0,1] )
p = p´+ (1m) =[m(xk + 1) + b] (yk + 0 5) + (1 m) =
( )
p p + (1 m) [m(xk + 1) + b] (yk + 0.5) + (1 m) = mxk + b yk + 0.5 = mxk + b (yk 0.5)
k
yk yk+ 0 5
k
(yk ) yk+ 0.5 p´ p for next pixel l yk m = overlap area for current pixel for current pixel p 1-m p xk xk+1 p´
Werner Purgathofer 48
k k
( )
Werner Purgathofer 49
Werner Purgathofer 50
Werner Purgathofer 51