the graphics pipeline: clipping & line rasterization
DESCRIPTION
The Graphics Pipeline: Clipping & Line Rasterization. Last Time?. Modeling Transformations. Illumination (Shading). Viewing Transformation (Perspective / Orthographic). Clipping. Projection (to Screen Space). Scan Conversion (Rasterization). Visibility / Display. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/1.jpg)
MIT EECS 6.837, Durand and Cutler
The Graphics Pipeline:
Clipping & Line Rasterization
![Page 2: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/2.jpg)
MIT EECS 6.837, Durand and Cutler
Last Time?• Ray Tracing vs. Scan Conversion• Overview of the Graphics Pipeline• Projective Transformations
Modeling Transformations
Illumination(Shading)
Viewing Transformation(Perspective / Orthographic)
Clipping
Projection (to Screen Space)
Scan Conversion(Rasterization)
Visibility / Display
![Page 3: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/3.jpg)
MIT EECS 6.837, Durand and Cutler
Today: Clipping & Line Rasterization
• Portions of the object outside the view frustum are removed
• Rasterize objects into pixels
Modeling Transformations
Illumination(Shading)
Viewing Transformation(Perspective / Orthographic)
Clipping
Projection (to Screen Space)
Scan Conversion(Rasterization)
Visibility / Display
![Page 4: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/4.jpg)
MIT EECS 6.837, Durand and Cutler
Today
• Why Clip?• Line Clipping• Polygon clipping• Line Rasterization
![Page 5: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/5.jpg)
MIT EECS 6.837, Durand and Cutler
Framebuffer Model
• Raster Display: 2D array of picture elements (pixels)
• Pixels individually set/cleared (greyscale, color)• Window coordinates: pixels centered at integers
(x1,y1)
(x2,y2) glBegin(GL_LINES)glVertex3f(...)glVertex3f(...)glEnd();
![Page 6: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/6.jpg)
MIT EECS 6.837, Durand and Cutler
2D Scan Conversion• Geometric primitives
(point, line, polygon, circle, polyhedron, sphere... )
• Primitives are continuous; screen is discrete
• Scan Conversion: algorithms for efficient generation of the samples comprising this approximation
![Page 7: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/7.jpg)
MIT EECS 6.837, Durand and Cutler
Clipping problem
• How do we clip parts outside window?
![Page 8: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/8.jpg)
MIT EECS 6.837, Durand and Cutler
Clipping problem
• How do we clip parts outside window?• Create two triangles or more. Quite annoying.
![Page 9: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/9.jpg)
MIT EECS 6.837, Durand and Cutler
Also, what if the pz is < eyez?
(eyex, eyey, eyez)
image plane
z axis →+
![Page 10: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/10.jpg)
MIT EECS 6.837, Durand and Cutler
The Graphics Pipeline
• Former hardware relied on full clipping
• Modern hardware mostly avoids clipping– Only with respect to
plane z=0
• In general, it is useful to learn clipping because it is similar to many geometric algorithms
Modeling Transformations
Illumination(Shading)
Viewing Transformation(Perspective / Orthographic)
Clipping
Projection (to Screen Space)
Scan Conversion(Rasterization)
Visibility / Display
![Page 11: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/11.jpg)
MIT EECS 6.837, Durand and Cutler
Full Clipping
(eyex, eyey, eyez)
image plane
z axis
"clip" geometry to view frustum
![Page 12: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/12.jpg)
MIT EECS 6.837, Durand and Cutler
One-plane clipping
(eyex, eyey, eyez)
image plane
z axis
"clip" geometry to near plane
![Page 13: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/13.jpg)
MIT EECS 6.837, Durand and Cutler
When to clip? • Perspective Projection: 2 conceptual steps:
– 4x4 matrix– Homogenize
• In fact not always needed• Modern graphics hardware performs most
operations in 2D homogeneous coordinates
x
y
1
z / d
=
x
y
z
1
1
0
0
0
0
1
0
0
0
0
0
1/d
0
0
1
0
x * d / z
y * d / z
d/z
1
=
homogenize
![Page 14: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/14.jpg)
MIT EECS 6.837, Durand and Cutler
When to clip?• Before perspective transform
in 3D space– Use the equation of 6 planes– Natural, not too degenerate
• In homogeneous coordinates after perspective transform (Clip space)– Before perspective divide
(4D space, weird w values)– Canonical,independent of camera– The simplest to implement in fact
• In the transformed 3D screen space after perspective division– Problem: objects in the plane of the camera
![Page 15: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/15.jpg)
MIT EECS 6.837, Durand and Cutler
Working in homogeneous coordinates
• In general, many algorithms are simpler in homogeneous coordinates before division– Clipping– Rasterization
![Page 16: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/16.jpg)
MIT EECS 6.837, Durand and Cutler
Today
• Why Clip?• Line Clipping• Polygon clipping• Line Rasterization
![Page 17: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/17.jpg)
MIT EECS 6.837, Durand and Cutler
Implicit 3D Plane Equation
• Plane defined by:point p & normal n ORnormal n & offset d OR3 points
• Implicit plane equationAx+By+Cz+D = 0
P0P
![Page 18: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/18.jpg)
MIT EECS 6.837, Durand and Cutler
Homogeneous Coordinates
• Homogenous point: (x,y,z,w) infinite number of equivalenthomogenous coordinates: (sx, sy, sz, sw)
• Homogenous Plane Equation: Ax+By+Cz+D = 0 → H = (A,B,C,D)
Infinite number of equivalent plane expressions: sAx+sBy+sCz+sD = 0 → H = (sA,sB,sC,sD)
P0P
H = (A,B,C,D)
![Page 19: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/19.jpg)
MIT EECS 6.837, Durand and Cutler
Point-to-Plane Distance
• If (A,B,C) is normalized:d = H•p = HTp(the dot product in homogeneous coordinates)
• d is a signed distance positive = "inside"
negative = "outside"
P’
P0
P
H = (A,B,C,D)
d
![Page 20: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/20.jpg)
MIT EECS 6.837, Durand and Cutler
Clipping a Point with respect to a Plane
• If d = H•p 0Pass through
• If d = H•p < 0:Clip (or cull or reject)
P’
P0
P
H = (A,B,C,D)
d
![Page 21: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/21.jpg)
MIT EECS 6.837, Durand and Cutler
Clipping with respect to View Frustum
• Test against each of the 6 planes– Normals oriented towards the interior
• Clip (or cull or reject) point p if any H•p < 0
P
![Page 22: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/22.jpg)
MIT EECS 6.837, Durand and Cutler
What are the View Frustum Planes?
Hnear =
Hfar =
Hbottom =
Htop =
Hleft =
Hright =
( 0 0 –1 –near)
( 0 0 1 far )
( 0 near bottom 0 )
( 0 –near –top 0 )
( left near 0 0 )
(–right –near 0 0 )
P
(left, bottom, –near)
(right*far/near, top*far/near, –far)
![Page 23: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/23.jpg)
MIT EECS 6.837, Durand and Cutler
Recall: When to clip?• Before perspective transform
in 3D space– Use the equation of 6 planes– Natural, not too degenerate
• In homogeneous coordinates after perspective transform (Clip space)– Before perspective divide
(4D space, weird w values)– Canonical,independent of camera– The simplest to implement in fact
• In the transformed 3D screen space after perspective division– Problem: objects in the plane of the camera
![Page 24: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/24.jpg)
MIT EECS 6.837, Durand and Cutler
Questions?
• You are now supposed to be able to clip points wrt view frustum
• Using homogeneous coordinates
![Page 25: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/25.jpg)
MIT EECS 6.837, Durand and Cutler
Line – Plane Intersection
• Explicit (Parametric) Line EquationL(t) = P0 + t * (P1 – P0)
L(t) = (1-t) * P0 + t * P1
• How do we intersect?Insert explicit equation of line intoimplicit equation of plane
• Parameter t is used to interpolate associated attributes (color, normal, texture, etc.)
P0
PP1
![Page 26: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/26.jpg)
MIT EECS 6.837, Durand and Cutler
Segment Clipping
• If H•p > 0 and H•q < 0
• If H•p < 0 and H•q > 0
• If H•p > 0 and H•q > 0
• If H•p < 0 and H•q < 0
p
q
![Page 27: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/27.jpg)
MIT EECS 6.837, Durand and Cutler
Segment Clipping
• If H•p > 0 and H•q < 0– clip q to plane
• If H•p < 0 and H•q > 0
• If H•p > 0 and H•q > 0
• If H•p < 0 and H•q < 0
p
q
n
![Page 28: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/28.jpg)
MIT EECS 6.837, Durand and Cutler
Segment Clipping
• If H•p > 0 and H•q < 0– clip q to plane
• If H•p < 0 and H•q > 0– clip p to plane
• If H•p > 0 and H•q > 0
• If H•p < 0 and H•q < 0
p
q
n
![Page 29: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/29.jpg)
MIT EECS 6.837, Durand and Cutler
Segment Clipping
• If H•p > 0 and H•q < 0– clip q to plane
• If H•p < 0 and H•q > 0– clip p to plane
• If H•p > 0 and H•q > 0– pass through
• If H•p < 0 and H•q < 0
p
q
n
![Page 30: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/30.jpg)
MIT EECS 6.837, Durand and Cutler
Segment Clipping
• If H•p > 0 and H•q < 0– clip q to plane
• If H•p < 0 and H•q > 0– clip p to plane
• If H•p > 0 and H•q > 0– pass through
• If H•p < 0 and H•q < 0– clipped out
p
q
n
![Page 31: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/31.jpg)
MIT EECS 6.837, Durand and Cutler
Clipping against the frustum• For each frustum plane H
– If H•p > 0 and H•q < 0, clip q to H
– If H•p < 0 and H•q > 0, clip p to H
– If H•p > 0 and H•q > 0, pass through
– If H•p < 0 and H•q < 0, clipped out
Result is a single segment. Why?
![Page 32: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/32.jpg)
MIT EECS 6.837, Durand and Cutler
Questions?
• You are now supposed to be able to clip segments wrt view frustum
![Page 33: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/33.jpg)
MIT EECS 6.837, Durand and Cutler
Is this Clipping Efficient?
p
H1 H2
H3
H4
q
• For each frustum plane H– If H•p > 0 and H•q < 0, clip q to H
– If H•p < 0 and H•q > 0, clip p to H
– If H•p > 0 and H•q > 0, pass through
– If H•p < 0 and H•q < 0, clipped out
![Page 34: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/34.jpg)
MIT EECS 6.837, Durand and Cutler
Is this Clipping Efficient?
q
p
H1 H2
H3
H4
• For each frustum plane H– If H•p > 0 and H•q < 0, clip q to H
– If H•p < 0 and H•q > 0, clip p to H
– If H•p > 0 and H•q > 0, pass through
– If H•p < 0 and H•q < 0, clipped out
![Page 35: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/35.jpg)
MIT EECS 6.837, Durand and Cutler
Is this Clipping Efficient?
q
p
H1 H2
H3
H4
What is the problem?
The computation of the intersections, and any corresponding interpolated values is unnecessary
Can we detect this earlier?
• For each frustum plane H– If H•p > 0 and H•q < 0, clip q to H
– If H•p < 0 and H•q > 0, clip p to H
– If H•p > 0 and H•q > 0, pass through
– If H•p < 0 and H•q < 0, clipped out
![Page 36: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/36.jpg)
MIT EECS 6.837, Durand and Cutler
H1 H2
H3
H4
0000
1010 0010 0110
1000 0100
00011001 0101
Improving Efficiency: Outcodes
• Compute the sidedness of each vertex with respect to each bounding plane (0 = valid)
• Combine into binary outcode using logical AND
Outcode of p : 1010
Outcode of q : 0110
Outcode of [pq] : 0010
Clipped because there is a 1
p q
![Page 37: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/37.jpg)
MIT EECS 6.837, Durand and Cutler
Improving Efficiency: Outcodes
• When do we fail to save computation?
Outcode of p : 1000
Outcode of q : 0010
Outcode of [pq] : 0000
Not clipped
H1 H2
H3
H4
0000
1010 0010 0110
1000 0100
00011001 0101
p
q
![Page 38: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/38.jpg)
MIT EECS 6.837, Durand and Cutler
Improving Efficiency: Outcodes
• It works for arbitrary primitives• And for arbitrary dimensions
Outcode of p : 1010
Clipped
H1 H2
H3
H4
0000
1010 0010 0110
1000 0100
00011001 0101
Outcode of q : 1010
Outcode of r : 0110
Outcode of s : 0010
Outcode of t : 0110
Outcode of u : 0010
Outcode : 0010
![Page 39: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/39.jpg)
MIT EECS 6.837, Durand and Cutler
Questions?
• You are now supposed to be able to make clipping efficient using outcodes
![Page 40: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/40.jpg)
MIT EECS 6.837, Durand and Cutler
Today
• Why Clip?• Line Clipping• Polygon clipping• Line Rasterization
![Page 41: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/41.jpg)
MIT EECS 6.837, Durand and Cutler
Polygon clipping
![Page 42: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/42.jpg)
MIT EECS 6.837, Durand and Cutler
Polygon clipping
![Page 43: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/43.jpg)
MIT EECS 6.837, Durand and Cutler
Polygon clipping
• Clipping is symmetric
![Page 44: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/44.jpg)
MIT EECS 6.837, Durand and Cutler
Polygon clipping is complex
• Even when the polygons are convex
![Page 45: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/45.jpg)
MIT EECS 6.837, Durand and Cutler
Polygon clipping is nasty
• When the polygons are concave
![Page 46: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/46.jpg)
MIT EECS 6.837, Durand and Cutler
Naïve polygon clipping?
• N*m intersections• Then must link all segment• Not efficient and not even easy
![Page 47: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/47.jpg)
MIT EECS 6.837, Durand and Cutler
Weiler-Atherton Clipping
• Strategy: “Walk" polygon/window boundary
• Polygons are oriented (CCW)
![Page 48: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/48.jpg)
MIT EECS 6.837, Durand and Cutler
Weiler-Atherton Clipping
• Compute intersection points
![Page 49: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/49.jpg)
MIT EECS 6.837, Durand and Cutler
Weiler-Atherton Clipping
• Compute intersection points• Mark points where polygons enters
clipping window (green here)
![Page 50: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/50.jpg)
MIT EECS 6.837, Durand and Cutler
Clipping
While there is still an unprocessed entering intersection
Walk" polygon/window boundary
![Page 51: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/51.jpg)
MIT EECS 6.837, Durand and Cutler
Walking rules• Out-to-in pair:
– Record clipped point– Follow polygon boundary (ccw)
• In-to-out pair:– Record clipped point– Follow window boundary (ccw)
![Page 52: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/52.jpg)
MIT EECS 6.837, Durand and Cutler
Walking rules• Out-to-in pair:
– Record clipped point– Follow polygon boundary (ccw)
• In-to-out pair:– Record clipped point– Follow window boundary (ccw)
![Page 53: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/53.jpg)
MIT EECS 6.837, Durand and Cutler
Walking rules• Out-to-in pair:
– Record clipped point– Follow polygon boundary (ccw)
• In-to-out pair:– Record clipped point– Follow window boundary (ccw)
![Page 54: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/54.jpg)
MIT EECS 6.837, Durand and Cutler
Walking rules• Out-to-in pair:
– Record clipped point– Follow polygon boundary (ccw)
• In-to-out pair:– Record clipped point– Follow window boundary (ccw)
![Page 55: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/55.jpg)
MIT EECS 6.837, Durand and Cutler
Walking rules
While there is still an unprocessed entering intersection
Walk" polygon/window boundary
![Page 56: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/56.jpg)
MIT EECS 6.837, Durand and Cutler
Walking rules
While there is still an unprocessed entering intersection
Walk" polygon/window boundary
![Page 57: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/57.jpg)
MIT EECS 6.837, Durand and Cutler
Walking rules
While there is still an unprocessed entering intersection
Walk" polygon/window boundary
![Page 58: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/58.jpg)
MIT EECS 6.837, Durand and Cutler
Walking rules
While there is still an unprocessed entering intersection
Walk" polygon/window boundary
![Page 59: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/59.jpg)
MIT EECS 6.837, Durand and Cutler
Weiler-Atherton Clipping
• Importance of good adjacency data structure(here simply list of oriented edges)
![Page 60: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/60.jpg)
MIT EECS 6.837, Durand and Cutler
Robustness, precision, degeneracies
• What if a vertex is on the boundary?• What happens if it is “almost” on the boundary?
– Problem with floating point precision
• Welcome to the real world of geometry!
![Page 61: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/61.jpg)
MIT EECS 6.837, Durand and Cutler
Clipping
• Many other clipping algorithms:• Parametric, general windows, region-region,
One-Plane-at-a-Time Clipping, etc.
![Page 62: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/62.jpg)
MIT EECS 6.837, Durand and Cutler
Questions?
![Page 63: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/63.jpg)
MIT EECS 6.837, Durand and Cutler
Today
• Why Clip?• Line Clipping• Polygon clipping• Line Rasterization
![Page 64: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/64.jpg)
MIT EECS 6.837, Durand and Cutler
Scan Converting 2D Line Segments
• Given:– Segment endpoints (integers x1, y1; x2, y2)
• Identify:– Set of pixels (x, y) to display for segment
(x1, y1)
(x2, y2)
![Page 65: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/65.jpg)
MIT EECS 6.837, Durand and Cutler
Line Rasterization Requirements
• Transform continuous primitive into discrete samples
• Uniform thickness & brightness• Continuous appearance• No gaps• Accuracy• Speed
(x1, y1)
(x2, y2)
![Page 66: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/66.jpg)
MIT EECS 6.837, Durand and Cutler
Algorithm Design Choices
• Assume:– m = dy/dx, 0 < m < 1
• Exactly one pixel per column– fewer → disconnected, more → too thick
(x1, y1)
(x2, y2)
![Page 67: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/67.jpg)
MIT EECS 6.837, Durand and Cutler
Algorithm Design Choices
• Note: brightness can vary with slope– What is the maximum variation?
• How could we compensate for this?– Answer: antialiasing
2
![Page 68: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/68.jpg)
MIT EECS 6.837, Durand and Cutler
Naive Line Rasterization Algorithm
• Simply compute y as a function of x– Conceptually: move vertical scan line from x1 to x2– What is the expression of y as function of x?– Set pixel (x, round (y(x)))
x
y
(x1, y1)
(x2, y2))1(1 xxmy
)12(12
11 yy
xx
xxyy
dx
dym
![Page 69: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/69.jpg)
MIT EECS 6.837, Durand and Cutler
Efficiency
• Computing y value is expensive
• Observe: y += m at each x step (m = dy/dx)
)1(1 xxmyy
y(x+1)
y(x)
x x+1
m
x
y(x)
(x1, y1)
(x2, y2)
y(x+1)
x+1
![Page 70: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/70.jpg)
MIT EECS 6.837, Durand and Cutler
Bresenham's Algorithm (DDA)
• Select pixel vertically closest to line segment– intuitive, efficient,
pixel center always within 0.5 vertically
• Same answer as naive approach
![Page 71: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/71.jpg)
MIT EECS 6.837, Durand and Cutler
Bresenham's Algorithm (DDA)
• Observation: – If we're at pixel P (xp, yp), the next pixel must be
either E (xp+1, yp) or NE (xp, yp+1)
– Why?
ENE
![Page 72: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/72.jpg)
MIT EECS 6.837, Durand and Cutler
Bresenham Step
• Which pixel to choose: E or NE?– Choose E if segment passes below or
through middle point M– Choose NE if segment passes above M
E
NE
M
E
NE
M
![Page 73: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/73.jpg)
MIT EECS 6.837, Durand and Cutler
Bresenham Step• Use decision function D to identify points
underlying line L:
D(x, y) = y-mx-b
– positive above L– zero on L– negative below L
D(px,py) =
MF<0
F>0F=0
p
vertical distance from point to line
![Page 74: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/74.jpg)
MIT EECS 6.837, Durand and Cutler
Bresenham's Algorithm (DDA)• Decision Function:
D(x, y) = y-mx-b
• Initialize:error term e = –D(x,y)
• On each iteration:update x:update e:if (e ≤ 0.5): if (e > 0.5):
x' = x+1e' = e + my' = y (choose pixel E)y' = y + (choose pixel NE) e' = e - 1
e
e’
![Page 75: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/75.jpg)
MIT EECS 6.837, Durand and Cutler
Summary of Bresenham• initialize x, y, e
• for (x = x1; x ≤ x2; x++)– plot (x,y)– update x, y, e
• Generalize to handle all eight octants using symmetry
• Can be modified to use only integer arithmetic
ENE
![Page 76: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/76.jpg)
MIT EECS 6.837, Durand and Cutler
Line Rasterization
• We will use it for ray-casting acceleration• March a ray through a grid
![Page 77: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/77.jpg)
MIT EECS 6.837, Durand and Cutler
Grid Marching vs. Line Rasterization
Ray Acceleration:
Must examine every cell the line touches
Line Rasterization:
Best discrete approximation of the line
![Page 78: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/78.jpg)
MIT EECS 6.837, Durand and Cutler
Questions?
![Page 79: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/79.jpg)
MIT EECS 6.837, Durand and Cutler
Circle Rasterization
• Generate pixels for 2nd octant only• Slope progresses from 0 → –1• Analog of Bresenham
Segment Algorithm
![Page 80: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/80.jpg)
MIT EECS 6.837, Durand and Cutler
Circle Rasterization• Decision Function:
D(x, y) =
• Initialize:error term e =
• On each iteration:update x:update e:if (e ≥ 0.5): if (e < 0.5):
x' = x + 1e' = e + 2x + 1 y' = y (choose pixel E)y' = y - 1 (choose pixel SE), e' = e + 1
x2 + y2 – R2
–D(x,y)
R
![Page 81: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/81.jpg)
MIT EECS 6.837, Durand and Cutler
Philosophically
Discrete differential analyzer (DDA):• Perform incremental computation• Work on derivative rather than function• Gain one order for polynomial
– Line becomes constant derivative– Circle becomes linear derivative
![Page 82: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/82.jpg)
MIT EECS 6.837, Durand and Cutler
Questions?
![Page 83: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/83.jpg)
MIT EECS 6.837, Durand and Cutler
Antialiased Line Rasterization
• Use gray scales to avoid jaggies• Will be studied later in the course
aliased antialiased
![Page 84: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/84.jpg)
MIT EECS 6.837, Durand and Cutler
High-level concepts for 6.837
• Linearity• Homogeneous coordinates• Convexity• Discrete vs. continuous
![Page 85: The Graphics Pipeline: Clipping & Line Rasterization](https://reader036.vdocuments.net/reader036/viewer/2022062314/56812db2550346895d92dfd6/html5/thumbnails/85.jpg)
MIT EECS 6.837, Durand and Cutler
Thursday
Polygon Rasterization
& Visibility