clipping and scan conversionmisha/fall20/13.pdfcohen-sutherland line clipping β’ associate a 4-bit...
TRANSCRIPT
Clipping and Scan Conversion
Michael Kazhdan
(601.357/456)
HB Ch. 3.2, 3.11, 6.7, 6.8
FvDFH Ch. 3.2, 3.6, 3.12, 3.14
Announcementsβ’ Assignment 2 posted
Start yesterday!!!
Lighting
ViewingTransformation
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
3D Camera Coordinates
2D Image Coordinates
3D Model
2D Image
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
3D WorldCoordinates
3D ObjectCoordinates
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
3D WorldCoordinates
Transform = ππππ = local to world transform
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
3D WorldCoordinates
3D CameraCoordinates
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
Transform = ππππ = local to world transform
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
Camera Right
Camera Up
x
y
zCamera Back
πππΆπΆβππ is the camera to world transformπ π π₯π₯ πππ₯π₯ π΅π΅π₯π₯ πΈπΈπ₯π₯π π π¦π¦ πππ¦π¦ π΅π΅π¦π¦ πΈπΈπ¦π¦π π π§π§ πππ§π§ π΅π΅π§π§ πΈπΈπ§π§0 0 0 1
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
Transform = πππΆπΆβππβ1 ππ
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
Transform = πππππΆπΆβππβ1 ππππ = projection transform
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
ππππ =
1 0 πΏπΏ cosππ 00 1 πΏπΏ sinππ 00 0 0 00 0 0 1
ππππ =
1 0 0 00 1 0 00 0 1 00 0 1 0
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
π£π£π₯π₯1 π£π£π₯π₯2π£π£π¦π¦1
π£π£π¦π¦2
π€π€π₯π₯1 π€π€π₯π₯2π€π€π¦π¦1
π€π€π¦π¦2Window Viewport
Screen Coordinates Image Coordinates
(π€π€π₯π₯,π€π€π¦π¦) (π£π£π₯π₯ , π£π£π¦π¦)
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²)
ππ = viewport transform
ππ =1 0 π£π£π₯π₯1
0 1 π£π£π₯π₯20 0 1
π£π£π₯π₯2 β π£π£π₯π₯1
π€π€π₯π₯2 β π€π€π₯π₯10 0
0π£π£π¦π¦2 β π£π£π¦π¦1
π€π€π¦π¦2 β π€π€π¦π¦10
0 0 1
1 0 βπ€π€π₯π₯1
0 1 βπ€π€π¦π¦1
0 0 1
Transform = πππππππΆπΆβππβ1 ππ
3D Rendering Pipeline (for direct illumination)
3D Model
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
(π₯π₯,π¦π¦, π§π§)
(π₯π₯β²,π¦π¦β²) 2D Screen
Transformationsππ
πΏπΏ1
πΏπΏ2
ππ
Viewer
πΌπΌ = πΌπΌπΈπΈ + οΏ½πΏπΏ
πΎπΎπ΄π΄ β πΌπΌπΏπΏπ΄π΄ + πΎπΎπ·π· β ππ, πΏπΏ + πΎπΎππ β ππ,π π ππ β πΌπΌπΏπΏ
3D Model2D Screen
Lighting
ViewingTransformation
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
Lighting
ViewingTransformation
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
3D Camera Coordinates
2D Image Coordinates
Clippingβ’ Avoid drawing parts of primitives outside window
Window defines part of scene being viewed Must draw geometric primitives only inside window
Screen Coordinates
Window
Clippingβ’ Avoid drawing parts of primitives outside window
Points Line Segments Polygons
Screen Coordinates
Window
β’ Is point (π₯π₯,π¦π¦) inside the clip window?
Point Clipping
Windowπ€π€π₯π₯1 π€π€π₯π₯2
π€π€π¦π¦2
π€π€π¦π¦1
(π₯π₯,π¦π¦)
β’ Is point (π₯π₯,π¦π¦) inside the clip window?
Point Clipping
Window
(π₯π₯,π¦π¦)
inside = (x >= wx1) &&(x < wx2) &&(y >= wy1) &&(y < wy2);
π€π€π₯π₯1 π€π€π₯π₯2
π€π€π¦π¦2
π€π€π¦π¦1
Clippingβ’ Avoid drawing parts of primitives outside window
Points Line Segments Polygons
Screen Coordinates
Window
Line Segment Clippingβ’ Find the part of a line inside the clip window
Do this as efficiently as possible by identifying the easiest cases first
ππ1
ππ10
ππ9
ππ8
ππ7
ππ4ππ3
ππ6
ππ5
ππ2
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππππππππππππππππ to each vertex
ππ0 = 1 if the vertex is left of the window ππ1 = 1 if the vertex is right of the window ππ2 = 1 if the vertex is below the window ππ3 = 1 if the vertex is above the window
ππ0 ππ1
ππ2
ππ3
0000 01001000
0001 01011001
0010 01101010
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ1
ππ10
ππ9
ππ8
ππ7
ππ6
ππ5
ππ2
ππ4ππ3
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ10
ππ9
ππ8
ππ7
ππ6
ππ5
ππ4ππ3
ππ1
ππ2
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ10
ππ9
ππ8
ππ7
ππ6
ππ5
ππ4ππ3
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ10
ππ9
ππ8
ππ7
ππ4ππ3
ππ6
ππ5
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ10
ππ9
ππ8
ππ7
ππ4ππ3
ππ6
ππ5
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010ππ5β²
ππ10
ππ9
ππ8
ππ7
ππ4ππ3
ππ6
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010ππ5β²
ππ10
ππ9
ππ4ππ3
ππ6
ππ8
ππ7
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010ππ5β²
ππ10
ππ9
ππ3
ππ6
ππ8
ππ7
ππ4
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ7β²
ππ5β²
ππ10
ππ9
ππ3
ππ6
ππ8ππ4
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ7β²
ππ5β²
ππ10
ππ9
ππ3
ππ6
ππ8ππ4
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ8β²
ππ7β²
ππ5β²
ππ10
ππ9
ππ3
ππ6
ππ4
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ8β²
ππ7β²
ππ5β²
ππ3
ππ6
ππ4
ππ10
ππ9
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ8β²
ππ7β²
ππ5β²
ππ3
ππ6
ππ4
ππ10
ππ9
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010ππ9β²
ππ8β²
ππ7β²
ππ5β²
ππ3
ππ6
ππ4
ππ10
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes is not 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ8β²
ππ7β²
ππ5β²
ππ3
ππ6
ππ4
ππ0 ππ1
ππ2
ππ3
Cohen-Sutherland Line Clippingβ’ Associate a 4-bit outcode ππ0ππ1ππ2ππ3 to each vertexβ’ If both outcodes are 0, line segment is insideβ’ If AND of outcodes isnot 0, line segment is outsideβ’ Otherwise clip and test
0000 01001000
0001 01011001
0010 01101010
ππ8β²
ππ7β²
ππ5β²
ππ3
ππ6
ππ4
ππ0 ππ1
ππ2
ππ3
How many bits would you need in 3D?
Clippingβ’ Avoid drawing parts of primitives outside window
Points Line Segments Polygons
Screen Coordinates
Window
Polygon Clippingβ’ Find the part of a polygon inside the clip window
Before Clipping
Sutherland-Hodgeman Clippingβ’ Clip to each window boundary, one at a time
Sutherland-Hodgeman Clippingβ’ Clip to each window boundary, one at a time
Sutherland-Hodgeman Clippingβ’ Clip to each window boundary, one at a time
Sutherland-Hodgeman Clippingβ’ Clip to each window boundary, one at a time
Sutherland-Hodgeman Clippingβ’ Clip to each window boundary, one at a time
Sutherland-Hodgeman Clippingβ’ How do we clip a convex polygon with respect to
a line?
OutsideInside
WindowBoundary
ππ1ππ2
ππ5
ππ4
ππ3
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary
ππ1ππ2
ππ5
ππ4
ππ3
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary
ππ1ππ2
ππ5
ππ4
ππ3
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary
ππ1ππ2
ππ5
ππ4
ππ3
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary
ππ1ππ2
ππ5
ππ4
ππ3
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππ
ππ1ππ2
ππ5
ππ4
ππ3
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππ
ππ1ππ2
ππ5
ππ4
ππ3
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππ
ππ1ππ2
ππ5
ππ4
ππ3
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππππππ
ππ1ππ2
ππ5
ππ4
ππ3
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππππππ
ππ1ππ2
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary πππππππ
ππ1ππ2
When polygons are clipped, per-vertex properties (e.g. lighting) is interpolated to the new vertices.
Sutherland-Hodgeman Clippingβ’ Do inside test for each point in sequence,
Insert new points when cross window boundary, Remove points outside window boundary
OutsideInside
WindowBoundary
What happens if the polygon is not convex?
Lighting
ViewingTransformation
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
3D Camera Coordinates
2D Image Coordinates3D Model
2D Screen
2D Rendering Pipeline
ScanConversion
Clipping
2D Primitives
Image
Clip portions of geometric primitivesresiding outside the window
Fill pixels representing primitives in screen coordinates
3D Primitives
Overviewβ’ Scan conversion
Figure out which pixels to fill
β’ Shading Determine a color for each filled pixel
β’ Depth test Determine when the color of a pixel should be
overwritten
Scan Conversionβ’ Render an image of a geometric primitive
by setting pixel colors
β’ Example: Filling the inside of a triangle
ππ1
ππ2
ππ3
void SetPixel( int x , int y , Color rgba )
Triangle Scan Conversionβ’ Properties of a good algorithm
Must be fast No cracks between adjacent primitives
ππ1
ππ2
ππ3
ππ4
Triangle Scan Conversionβ’ Properties of a good algorithm
Must be fast No cracks between adjacent primitives
ππ1
ππ2
ππ3
ππ4
Simple Algorithm
ππ1
ππ2
ππ3
void ScanTriangle( Triangle T , Color rgba ){
for each pixel center (x,y)if( PointInsideTriangle( (x,y) , T ) )
SetPixel( x , y , rgba );}
β’ Color all pixels inside triangle
ππ1
ππ2
Line defines two halfspacesβ’ Test: use implicit equation for a line
On line: πππ₯π₯ + πππ¦π¦ + ππ = 0 To the right: πππ₯π₯ + πππ¦π¦ + ππ < 0 To the left: πππ₯π₯ + πππ¦π¦ + ππ > 0
πΏπΏ
Inside Triangle Testβ’ A point is inside a triangle if it is in the
positive half-space of all three boundary lines Triangle vertices are ordered counter-clockwise Point must be on the left side of every boundary line
πππΏπΏ1
πΏπΏ2
πΏπΏ3
Inside Triangle TestBoolean PointInsideTriangle( Point P , Triangle T ){
for each boundary line L of T{
Scalar d = L.a*P.x + L.b*P.y + L.c;if( d<0.0 ) return FALSE;
}return TRUE;
}
πΏπΏ1
πΏπΏ2
πΏπΏ3
Simple Algorithm
ππ1
ππ2
ππ3
void ScanTriangle( Triangle T , Color rgba ){
for each pixel center (x,y)if( PointInsideTriangle( (x,y) , T ) )
SetPixel( x , y , rgba );}
β’ What is bad about this algorithm?
Triangle Sweep-Line Algorithmβ’ Take advantage of spatial coherence
β’ Take advantage of edge linearity
πππ₯π₯πππ¦π¦
Triangle Sweep-Line Algorithmvoid ScanTriangle( Triangle T , Color rgba ){
for both edge pairs{
initialize xL, xR, y;compute dxL/dyL and dxR/dyR;until y reaches the first end-point
for( int x=xL ; x<=xR ; x++ ) SetPixel( x , y , rgba );xL += dxL/dyL;xR += dxR/dyR;y++;
}} πππ₯π₯πΏπΏ
πππ¦π¦πΏπΏπππ₯π₯π π
πππ¦π¦π π
π₯π₯πΏπΏ π₯π₯π π
Triangle Sweep-Line Algorithmvoid ScanTriangle( Triangle T , Color rgba ){
for both edge pairs{
initialize xL, xR, y;compute dxL/dyL and dxR/dyR;until y reaches the first end-point
for( int x=xL ; x<=xR ; x++ ) SetPixel( x , y , rgba );xL += dxL/dyL;xR += dxR/dyR;y++;
}}
π₯π₯πΏπΏ π₯π₯π π πππ₯π₯πΏπΏ
πππ¦π¦πΏπΏ
πππ₯π₯π π πππ¦π¦π π
Triangle Sweep-Line Algorithmvoid ScanTriangle( Triangle T , Color rgba ){
for both edge pairs{
initialize xL, xR, y;compute dxL/dyL and dxR/dyR;until y reaches the first end-point
for( int x=xL ; x<=xR ; x++ ) SetPixel( x , y , rgba );xL += dxL/dyL;xR += dxR/dyR;y++;
}}
Bresenhamβs algorithmworks the same way, but uses only integer operations!
Polygon Scan Conversionβ’ Will this method work for convex polygons?
Polygon Scan Conversionβ’ Will this method work for convex polygons?
Yes, since each scan line will only intersect the polygon at two points.
Polygon Scan Conversionβ’ How about these polygons?
Polygon Scan Conversionβ’ How about these polygons?
Polygon Scan Conversionβ’ Fill pixels inside a polygon
Triangle Quadrilateral Convex Star-shaped Concave Self-intersecting Holes
What problems do we encounter with arbitrary polygons?
Polygon Scan Conversionβ’ Need better test for points inside polygon
Triangle method works only for convex polygons
Convex Polygon
πΏπΏ1
πΏπΏ2
πΏπΏ3
πΏπΏ4πΏπΏ5
πΏπΏ1
πΏπΏ2
π³π³ππππ
πΏπΏ4πΏπΏ5
Concave Polygon
πΏπΏ3π΅π΅
Inside Polygon Rule
β’ What is a good rule for which pixels are inside?
Concave Self-Intersecting With Holes
Inside Polygon Rule
Concave Self-Intersecting With Holes
β’ Odd-parity rule Any ray from inside ππ to infinity must cross an odd
number of edges
Polygon Sweep-Line Algorithm Use incremental algorithm to find spans Determine βinsidenessβ with odd parity rule
β’ Takes advantage of scan line coherence
π₯π₯πΏπΏ π₯π₯π π
Triangle Polygon
Polygon Sweep-Line Algorithmvoid ScanPolygon( Polygon P , Color rgba ){
sort edges by maxymake empty βactive edge listβfor each scanline ( top-to-bottom ){
insert/remove edges from βactive edge listβupdate x coordinate of every active edgesort active edges by x coordinatefor each succesive pair of edge-points (left-to-right)
SetPixels( xi , xi+1 , y , rgba );}
}
Polygon Scan Conversionβ’ Convert everything into triangles
Scan convert the triangles
Polygon Scan Conversionβ’ Convert everything into triangles
Scan convert the triangles
Note:OpenGL will render polygons, but it assumes that:β’ The polygon is planarβ’ The polygon is convex
Note:Even if you only pass in triangles for rendering, OpenGL may still have to render (convex planar) polygons after the triangle is clipped.
Scan Conversionβ’ What about pixels on edges?
If we set them either βonβ or βoffβ we get aliasing or βjaggiesβ
ππ1
ππ2
ππ3
Scan Conversionβ’ What about pixels on edges?
If we set them either βonβ or βoffβ we get aliasing or βjaggiesβ
ππ1
ππ2
ππ3This is like using a βnearestβ interpolation filter!
Antialiasing Techniquesβ’ Display at higher resolution
Corresponds to increasing sampling rate Not always possible (fixed size monitors, fixed refresh
rates, etc.)
β’ Modify pixel intensities Vary pixel intensities along boundaries for antialiasing
Scan Conversionβ’ What about pixels on edges?
Setting them either βonβ or βoffβ we get aliasing/βjaggiesβ Antialias by varying pixel intensities along boundaries
ππ1
ππ2
ππ3
Antialiasingβ’ Method 1: Area sampling
Calculate percent of pixel covered by primitive Multiply this percentage by desired intensity/color
ππ1
ππ2
ππ3
ππ1
ππ2
ππ3
100%2% 25% 60%
Antialiasingβ’ Method 1: Area sampling
Calculate percent of pixel covered by primitive Multiply this percentage by desired intensity/color
ππ1
ππ2
ππ3
ππ1
ππ2
ππ3
100%2% 25% 60%
This is like using a βbilinearβ interpolation filter!
Antialiasingβ’ Method 2: Supersampling (aka postfiltering)
Sample as if screen were higher resolution Average multiple samples to get final intensity
Β» This can be done by rendering the scene multiple times with different (fractional) offsets
ππ1
ππ2
ππ3ππ3
ππ1
ππ2
AntialiasingNote that this makes things harder because pixels are no longer βownedβ by a single triangle.
Triangles contribute color rather than set color Along edges the total contribution must sum to one. Makes depth-testing more complicated.
ππ4
ππ2
ππ3
ππ1
Scan Conversionβ’ Example:
No Anti-Aliasing 4 x Anti-AliasingImages courtesy of NVIDIA
Lighting
ViewingTransformation
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
3D Camera Coordinates
2D Image Coordinates3D Model
2D Window
2D Screen
Overviewβ’ Scan conversion
Figure out which pixels to fill
β’ Shading Determine a color for each filled pixel
β’ Depth test Determine when the color of a pixel comes from the
front-most primitive
β’ Recall:In the βlightingβ phase, we calculated the color at each vertex.
Gouraud Shading
ππ1 πΏπΏ1
ππ1
ππ2
ππ3πΏπΏ3
πΏπΏ2ππ3
ππ2
πΌπΌ1
πΌπΌ2
πΌπΌ3
Lighting
ViewingTransformation
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
β’ Recall:In the βlightingβ phase, we calculated the color at each vertex. In the βscan conversionβ phase, linearly
interpolate colors at vertices
Gouraud Shading
πΌπΌ1
πΌπΌ2
πΌπΌ3
πΌπΌ
π½π½
πΎπΎ
π΅π΅ = (1 β π½π½) β πΌπΌ2 + π½π½ β πΌπΌ3
πΌπΌ = (1 β πΎπΎ) β π΄π΄ + πΎπΎ β π΅π΅
π΄π΄ π΅π΅πΌπΌ
Lighting
ViewingTransformation
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
π΄π΄ = (1 β πΌπΌ) β πΌπΌ1 + πΌπΌ β πΌπΌ2
β’ Recall:In the βlightingβ phase, we calculated the color at each vertex. In the βscan conversionβ phase, linearly
interpolate colors at vertices
Gouraud Shading
πΌπΌ1
πΌπΌ2
πΌπΌ3
πΌπΌ
π½π½
πΎπΎ
π΅π΅ = (1 β π½π½) β πΌπΌ2 + π½π½ β πΌπΌ3
πΌπΌ = (1 β πΎπΎ) β π΄π΄ + πΎπΎ β π΅π΅
π΄π΄ π΅π΅
Lighting
ViewingTransformation
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
Note: The values of πΌπΌ and π½π½ only need to be updated as we move to the next scan-line. The value of πΎπΎ needs
to be updated as we advance along the scan-line.
π΄π΄ = (1 β πΌπΌ) β πΌπΌ1 + πΌπΌ β πΌπΌ2
πΌπΌ
Lighting
ViewingTransformation
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
3D Camera Coordinates
2D Image Coordinates3D Model
2D Screen