March 19, 2002 Frank Pfenning Carnegie Mellon University http://www.cs.cmu.edu/~fp/courses/graphics/ Line Clipping Polygon Clipping Clipping in Three Dimensions Scan Conversion (Rasterization) [Angel 7.3-7.6, 7.8-7.9] Line Clipping Polygon Clipping Clipping in Three Dimensions Scan Conversion (Rasterization) [Angel 7.3-7.6, 7.8-7.9] Clipping and Scan Conversion Clipping and Scan Conversion 15-462 Computer Graphics I Lecture 14
41
Embed
Clipping and Scan Conversion - Carnegie Mellon School of ...fp/courses/02-graphics/pdf-color/14-clip.pdf · • Several practical algorithms – Avoid expensive line-rectangle intersections
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
March 19, 2002Frank PfenningCarnegie Mellon University
http://www.cs.cmu.edu/~fp/courses/graphics/
Line ClippingPolygon ClippingClipping in Three DimensionsScan Conversion (Rasterization)
[Angel 7.3-7.6, 7.8-7.9]
Line ClippingPolygon ClippingClipping in Three DimensionsScan Conversion (Rasterization)
[Angel 7.3-7.6, 7.8-7.9]
Clipping and Scan ConversionClipping and Scan Conversion
15-462 Computer Graphics ILecture 14
03/19/2002 15-462 Graphics I 2
The Graphics Pipeline, RevisitedThe Graphics Pipeline, Revisited
• Must eliminate objects outside viewing frustum• Tied in with projections
– Clipping: object space (eye coordinates)– Scissoring: image space (pixels in frame buffer)
• Introduce clipping in stages– 2D (for simplicity)– 3D (as in OpenGL)
• In a later lecture: scissoring
03/19/2002 15-462 Graphics I 3
Transformations and ProjectionsTransformations and Projections
• Solution:– Implement perspective projection by perspective
normalization and orthographic projection– Perspective normalization is a homogeneous tfm.
x
y
znear far
clipped line
1
11
0
x
y
z
image planenear far
clipped line
See [Angel Ch. 5.8]
03/19/2002 15-462 Graphics I 6
The Normalized FrustumThe Normalized Frustum
• OpenGL uses -1 · x,y,z · 1 (others possible)• Clip against resulting cube• Clipping against programmer-specified planes
is different and more expensive• Often a useful programming device
03/19/2002 15-462 Graphics I 7
The Viewport TransformationThe Viewport Transformation
• Transformation sequence again:1. Camera: From object coordinates to eye coords2. Perspective normalization: to clip coordinates3. Clipping4. Perspective division: to normalized device coords.5. Orthographic projection (setting zp = 0)6. Viewport transformation: to screen coordinates
• Viewport transformation can distort• Often in OpenGL: resize callback
03/19/2002 15-462 Graphics I 8
Line-Segment ClippingLine-Segment Clipping
• General: 3D object against cube• Simpler case:
– In 2D: line against square or rectangle– Before scan conversion (rasterization)– Later: polygon clipping
• Several practical algorithms– Avoid expensive line-rectangle intersections– Cohen-Sutherland Clipping– Liang-Barsky Clipping– Many more [see Foley et al.]
03/19/2002 15-462 Graphics I 9
Clipping Against RectangleClipping Against Rectangle
• Line-segment clipping: modify endpoints of lines to lie within clipping rectangle
• Could calculate intersections of line (segments) with clipping rectangle (expensive)
• Pick outside endpoint (o ≠ 0000)• Pick a crossed edge (o = b0b1b2b3 and bk ≠ 0)• Compute intersection of this line and this edge• Replace endpoint with intersection point• Restart with new line segment
– Outcodes of second point are unchanged
• Must converge (roundoff errors?)
03/19/2002 15-462 Graphics I 14
Liang-Barsky ClippingLiang-Barsky Clipping
• Starting point is parametric form
• Compute four intersections with extended clipping rectangle
• Will see that this can be avoided
03/19/2002 15-462 Graphics I 15
Ordering of intersection pointsOrdering of intersection points
• Final step in pipeline: rasterization (scan conv.)• From screen coordinates (float) to pixels (int)• Writing pixels into frame buffer• Separate z-buffer, display, shading, blending• Concentrate on primitives: