Einführung in Visual Computing
186.822
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
186.822
Werner Purgathofer 2
raster image in pixel coordinates clipping + homogenization
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
Werner Purgathofer 3
line clipping polygon clipping triangle clipping
Werner Purgathofer 4
partly visible or completely invisible parts must not be ignored and must not be drawn
.
ignored?: vertices edges scrolled?:
⇒ must be cut off (as early as possible)
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
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
Werner Purgathofer 7
before clipping after clipping
P1 P6 P7 P8 P10 P9 P5 P4 P3 P2 P1 P6 P2 P'5 P'8 P'7
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
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
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!
Window
1001 1000 1010 0001 0000 0010 0101 0100 0110
Werner Purgathofer 11
window P2 P3 P1 P4 P"2 P'1 P'2 P'3
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
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
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 clipping goal: one or more closed areas
Werner Purgathofer 15
clipping a polygon against successive window boundaries
polygon clip left clip right clip bottom clip top
processing polygon boundary as a whole against each window edge
Werner Purgathofer 16
four possible edge cases successive processing of pairs of polygon vertices against the left window boundary
in → in V2 in → out Vnew
no output
V1 V2 V1 V2 V1 V2 V1 V2 Vnew Vnew
Werner Purgathofer 17
V2:= 1st vertex V1:=V2 V2:=next vertex V2 visible?
no
V1 visible?
no
V2 V1
Werner Purgathofer 18
V2:= 1st vertex V1:=V2 V2:=next vertex V2 visible?
no
V1 visible?
no
Vnew = clip edge ∩ V1V2 → result list
yes
V1 V2 Vnew
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
V1 V2
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
V1 V2 Vnew
Werner Purgathofer 21
Werner Purgathofer 22
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
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 or final check of output vertex list
Werner Purgathofer 25
clipping a triangle triangle(s) 4 possible cases:
inside
triangle quadrilateral 2 triangles
Werner Purgathofer 26
corner cases need no extra handling!
Werner Purgathofer 27
world space camera space clip space screen space „view frustum“ modeling transformation camera transformation projection transformation viewport transformation
Werner Purgathofer 28
clipping against x = ± 1, y = ± 1, z = ± 1 (x,y,z) inside? only compare one value per border!
is done before homogenization:
x = ± h, y = ± h, z = ± h clips points that are behind the camera! reduces homogenization divisions
186.822
Werner Purgathofer 30
raster image in pixel coordinates clipping + homogenization
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
Werner Purgathofer 31
what is aliasing? ['eiliæsiη] what is the reason for aliasing? what can we do against it?
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
Werner Purgathofer 33
Werner Purgathofer 34
Werner Purgathofer 35
artificial color borders can appear
Werner Purgathofer 36
jumping images "worming“ backwards rotating wheels
Werner Purgathofer 37
higher resolution more color levels faster image sequence
postprocessing prefiltering !
expensive
incompatible software !
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
Werner Purgathofer 39
∆
Werner Purgathofer 40
max cycle
with
cycle s
i.e. sampling interval ≤ one-half cycle interval
max
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
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
Werner Purgathofer 42
3 = max. intensity ... 0 = min. intensity 9 = max. intensity ... 0 = min. intensity mathematical line line of finite width
Werner Purgathofer 43
Werner Purgathofer 44
calculate the pixel coverage exactly can be done with incremental schemes
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
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
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!
1 1,41421
Werner Purgathofer 48
Werner Purgathofer 49
adjusting pixel intensities along an area boundary alternative 1: supersampling
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] )
ymid
y = mx + b yk + 1 yk + 0.5 yk xk + 1 xk
y
Werner Purgathofer 51
p = p'+ (1−m) = [m(xk + 1) + b] − (yk + 0.5) + (1 − m) = mxk + b − yk + 0.5 =
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)
Werner Purgathofer 52
Werner Purgathofer 53
Werner Purgathofer 54