Philipp Slusallek
Computer Graphics
- Clipping -
Computer Graphics - Clipping - Philipp Slusallek Clipping - - PowerPoint PPT Presentation
Computer Graphics - Clipping - Philipp Slusallek Clipping Motivation Projected primitive might fall (partially) outside of display area E.g. if standing inside a building Eliminate non-visible geometry early in the pipeline to
– Projected primitive might fall (partially) outside of display area
– Eliminate non-visible geometry early in the pipeline to process visible parts only – Happens after transformation from 3D to 2D – Must cut off parts outside the window
– Must maintain information properly
correct interpolation of colors at triangle vertices when one is clipped
– Cutting off a vertex of a triangle produces a quadrilateral – Might need to be split into triangle again
– Cut off parts of objects which lie outside/inside of a defined region – Often clip against viewport (2D) or canonical view-volume (3D)
pa pe
– If both end points 𝑞𝑐 and 𝑞𝑓 are inside viewport
– Otherwise, clip the line at each edge
– Intersection within segment if both 0 ≤ 𝑢𝑚𝑗𝑜𝑓, 𝑢𝑓𝑒𝑓 ≤ 1
– Unnecessarily test many cases that are irrelevant
pb pe eb ee
– Efficient trivial accept and trivial reject – Non-trivial case: divide and test
– Bit encoding (outcode, OC)
– Trivial accept: both are in viewport
– Trivial reject: both lie outside w.r.t. at least one common edge
– Line has to be clipped to all edges where XOR bits are set, i.e. the points lies on different sides of that edge
0000 1000 1010 0010 0110 0100 0101 0001 1001 Bit order: top, bottom, right, left Viewport (xmin, ymin, xmax, ymax)
do { if ((oc1 AND oc2) != 0) // trivial reject of remaining segment return REJECT; else if ((oc1 OR oc2) == 0) // trivial accept of remaining segment return (ACCEPT, p1, p2); if ((oc1 XOR oc2)[edge]) { if (oc1[edge]) // p1 outside {p1 = cut(p1, p2, edge); oc1 = OC(p1);} else // p2 outside {p2 = cut(p1, p2, edge); oc2 = OC(p2);} } } while (++edge < 4); // Not the most efficient solution return ((oc1 OR oc2) == 0) ? (ACCEPT, p1, p2) : REJECT;
𝑧 − 𝑧𝑏 𝑧𝑓 − 𝑧𝑏 = xmin − 𝑦𝑏 𝑦𝑓 − 𝑦𝑏 𝑧 = ( 𝑧𝑏 + xmin − 𝑦𝑏) 𝑧𝑓 − 𝑧𝑏 𝑦𝑓 − 𝑦𝑏 1010 0101 1000 0001
– Only convex polygons: max 2 intersection points – Use edge orientation
– Clip line p = 𝑞𝑐 + 𝑢𝑗(𝑞𝑓 − 𝑞𝑐) with each edge – Intersection points sorted by parameter ti – Select
– If tout < tin, line lies completely outside (akin to ray-box intersect.)
𝑞 − 𝑞݁݀݃݁ ⋅ 𝑂𝑗 = 0 𝑢𝑗 𝑞𝑓 − 𝑞𝑐 ⋅ 𝑂𝑗 + 𝑞𝑐 − 𝑞݁݀݃݁ ⋅ 𝑂𝑗 = 0 𝑢𝑗 = 𝑞݁݀݃݁ − 𝑞𝑐 ⋅ 𝑂𝑗 𝑞𝑓 − 𝑞𝑐 ⋅ 𝑂𝑗 pe pb pedge Ni p Ni pb pe pb pe tin tout tout tin
– Using window-edge coordinates (with respect to an edge T)
– Window-edge coordinate (WEC): decision function for an edge
– Only sign matters, similar to Cohen-Sutherland opcode
ܹܧܥ𝑈(𝑞) = (𝑞 − 𝑞𝑈) ⋅ 𝑂𝑈 𝑂𝑈 = 0 1 , 𝑞𝑐 − 𝑞𝑈 = 𝑦𝑐 − 𝑦max 𝑧𝑐 − 𝑧max 𝑢𝑈 = 𝑞𝑐 − 𝑞𝑈 ⋅ 𝑂𝑈 𝑞𝑐 − 𝑞𝑓 ⋅ 𝑂𝑈 = WEC𝑈 𝑞𝑐 WEC𝑈 𝑞𝑐 − WEC𝑈 𝑞𝑓 = 𝑧𝑐 − 𝑧max 𝑧𝑐 − 𝑧𝑓 NT x y
pe pb pT
+ Efficient when majority of lines can be trivially accepted / rejected
– Repeated clipping for remaining lines – Testing for 2D/3D point coordinates
+ Efficient when many lines must be clipped + Testing for 1D parameter values – Testing intersections always for all clipping edges (in the Liang- Barsky trivial rejection testing possible)
– Condition: polygons have to remain closed
– Iterative clipping against each edge in sequence – Four different local operations based on sides of pi-1 and pi
pi pi-1 inside
pi inside
pi inside
pi inside
pi-1 pi-1 pi-1
p p 1st output: p 2nd output: pi
– Pipelined Sutherland-Hodgeman
– Degenerated polygons/edges
p0, p1, ... p0, p1, ... Top Bottom Left Right
– Arbitrary concave polygons with holes against each other
– Also with self-overlap
– Simpler and faster as Vatti – Also supports Boolean operations – Idea:
– Intersection with the polygon leads to a winding number 1
Non-zero WN: in Even WN: out
– Avoid unnecessary rasterization – Avoid overflow on transformation at fixed point!
– Enhanced Cohen-Sutherland with 6-bit outcode – After perspective division
– Clip against side planes of the canonical viewing frustum – Works analogously with Liang-Barsky or Sutherland-Hodgeman
– Use canonical view frustum, but avoid costly division by W – Inside test with a linear distance function (WEC)
X / W > -1 W + X = WECL(p) > 0
Y / W < 1 W – Y = WECT(p) > 0
W + Z = WECB(p) > 0
– Intersection point calculation (before homogenizing)
𝑋𝐹𝐷 𝑞𝑐 + 𝑢 𝑞𝑓 − 𝑞𝑐 = 0 𝑋
𝑐 + 𝑢 𝑋 𝑓 − 𝑋 𝑐 + 𝑌𝑐 + 𝑢 𝑌𝑓 − 𝑌𝑐 = 0
𝑢 = 𝑋
𝑐 + 𝑌𝑐
(𝑋
𝑐+𝑌𝑐) − (𝑋 𝑓 + 𝑌𝑓) =
𝑋𝐹𝐷𝑀(𝑞𝑐) 𝑋𝐹𝐷𝑀 𝑞𝑐 − 𝑋𝐹𝐷𝑀(𝑞𝑓)
– Points with w < 0 or lines with wb < 0 and we < 0
– Lines with wb · we < 0 (NURBS)
– External „line“
– Original line – Negated line
w x pb pe
W=1
– Clipping is expensive and should be avoided
– Enlargement of clipping region
– Result
the viewport/viewing frustum
during rasterization
processed (triangle setup)