Clipping
Clipping
California Stars
Billy Bragg & Wilco
from Mermaid Avenue
Released June 23, 1998
Vertex Processing:
Clipping
• Discuss clipping
• Points
• Lines
• Polygons
Rendering Pipeline
Modelview
Transform
Projection
Transform
Vertex
Lighting
Processing
Viewport
Transform
• Need to cull
• Need to clip
• Lines
• Polygons
Point Clipping
• This one is easy
• How to determine if a point (x, y, z) is in the
viewing volume (xnear, ynear, znear), (xfar, yfar,
zfar)?
• Who wants to tell me how?
• 6 bits
• y = y1 + u∆y
• Rearranging, we get
• -u∆x ≤ (x1 - xmin)
• u∆x ≤ (xmax - x1)
• -v∆y ≤ (y1 - ymin)
• v∆y ≤ (ymax - y1)
• In general: u * pk ≤ qk
Liang-Barsky
Line Clipping
• Cases:
1. pk = 0
• Also extends to 3D
• Just add equations for z = z1 + u∆z
➡ 2 more p’s and q’s
Liang-Barsky
Line Clipping
• Inmore
most cases, Liang-Barsky is slightly
efficient
• According to the Hearn-Baker textbook
• Avoids multiple shortenings of line segments
Case 2 LT
T L
Case 3 L
T TR p1 L LR
L
LB TB LB
Nicholl-Lee-Nicholl
Line Clipping
• Can use symmetry to handle all other cases
• “Algorithm” (really just a sketch):
• Find slopes of the line and the 4 region bounding
lines
• Winding number
Polygon Inside/Outside:
Even / Odd
• Count edge crossings
• If the number is even, that area is outside
• If odd, it is inside
2 2
1
0 1 3
0 1 2
4
2 1 3
2
Polygon Inside/Outside:
Winding Number
• Each line segment is assigned a direction by
walking around the edges in some pre-
defined order
• OpenGL walks counter-clockwise
Lines Polygons
Polygon Clipping
• Many tricky bits
• Maintaining inside/outside
Out -> In
In -> In In -> Out Out -> Out
Save new clip vertex
Save ending vertex Save new clip vertex Save nothing
and ending vertex
Sutherland-Hodgeman
Polygon Clipping
• Example 2: NOTE:
Remember
this?
Final Result:
Continue from
Nothing added
2 unconnected
cached vertex and polygons
Finished
direction
Weiler-Atherton
Polygon Clipping
• Difficulties:
• What if the polygon recrosses
an edge?
• Line Clipping
• Cohen-Sutherland
Any
Any Questions?
Questions?
• Liang-Barsky
• Nicholl-Lee-Nicholl
• Polygon Clipping
• Sutherland-Hodgeman
• Weiler-Atherton
Next Time