Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an...
Transcript of Clipping and Scan Conversionmisha/Fall19/13.pdfCohen-Sutherland Line Clipping • Associate an...
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!
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 World
Coordinates
3D Object
Coordinates
Transformations
ModelingTransformation
ViewingTransformation
2D Image Coordinates
ProjectionTransformation
Window-to-ViewportTransformation
3D Object Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
3D World
Coordinates
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 World
Coordinates
3D Camera
Coordinates(𝑥, 𝑦, 𝑧)
(𝑥′, 𝑦′)
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
𝑤𝑦2
Window Viewport
Screen Coordinates Image Coordinates
(𝑤𝑥, 𝑤𝑦) (𝑣𝑥 , 𝑣𝑦)
(𝑥, 𝑦, 𝑧)
(𝑥′, 𝑦′)
𝑉 = viewport transform
𝑉 =1 0 𝑣𝑥
1
0 1 𝑣𝑥2
0 0 1
𝑣𝑥2 − 𝑣𝑥
1
𝑤𝑥2 − 𝑤𝑥
1 0 0
0𝑣𝑦2 − 𝑣𝑦
1
𝑤𝑦2 − 𝑤𝑦
1 0
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
ModelingTransformation
ViewingTransformation
ProjectionTransformation
Lighting
Clipping
ScanConversion
3D Geometric Primitives
Image
𝑁
𝐿1
𝐿2
𝑉
Viewer
𝐼 = 𝐼𝐸 +
𝐿
𝐾𝐴 ⋅ 𝐼𝐿𝐴 + 𝐾𝐷 ⋅ 𝑁, 𝐿 + 𝐾𝑆 ⋅ 𝑉, 𝑅
𝑛 ⋅ 𝐼𝐿
3D Model2D Screen
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 an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃1
𝑃10
𝑃9
𝑃8
𝑃7
𝑃4𝑃3
𝑃6
𝑃5
𝑃2
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃1
𝑃10
𝑃9
𝑃8
𝑃7
𝑃6
𝑃5
𝑃2
𝑃4𝑃3
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃10
𝑃9
𝑃8
𝑃7
𝑃6
𝑃5
𝑃4𝑃3
𝑃1
𝑃2
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃10
𝑃9
𝑃8
𝑃7
𝑃6
𝑃5
𝑃4𝑃3
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃10
𝑃9
𝑃8
𝑃7
𝑃4𝑃3
𝑃6
𝑃5
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃10
𝑃9
𝑃8
𝑃7
𝑃4𝑃3
𝑃6
𝑃5
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010𝑃5′
𝑃10
𝑃9
𝑃8
𝑃7
𝑃4𝑃3
𝑃6
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010𝑃5′
𝑃10
𝑃9
𝑃4𝑃3
𝑃6
𝑃8
𝑃7
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010𝑃5′
𝑃10
𝑃9
𝑃3
𝑃6
𝑃8
𝑃7
𝑃4
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃7′
𝑃5′
𝑃10
𝑃9
𝑃3
𝑃6
𝑃8𝑃4
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃7′
𝑃5′
𝑃10
𝑃9
𝑃3
𝑃6
𝑃8𝑃4
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃8′
𝑃7′
𝑃5′
𝑃10
𝑃9
𝑃3
𝑃6
𝑃4
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃8′
𝑃7′
𝑃5′
𝑃3
𝑃6
𝑃4
𝑃10
𝑃9
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃8′
𝑃7′
𝑃5′
𝑃3
𝑃6
𝑃4
𝑃10
𝑃9
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010𝑃9′
𝑃8′
𝑃7′
𝑃5′
𝑃3
𝑃6
𝑃4
𝑃10
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃8′
𝑃7′
𝑃5′
𝑃3
𝑃6
𝑃4
Cohen-Sutherland Line Clipping
• Associate an outcode to each vertex
• If both outcodes are 0, line segment is inside
• If AND of outcodes not 0, line segment is outside
• Otherwise clip and test
Bit 1 Bit 2
Bit 3
Bit 4
0000 01001000
0001 01011001
0010 01101010
𝑃8′
𝑃7′
𝑃5′
𝑃3
𝑃6
𝑃4
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 polygon with respect to a line?
Outside
Inside
Window
Boundary
𝑃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
Outside
Inside
Window
Boundary
𝑃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
Outside
Inside
Window
Boundary
𝑃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
Outside
Inside
Window
Boundary
𝑃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
Outside
Inside
Window
Boundary
𝑃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
Outside
Inside
Window
Boundary 𝑃′
𝑃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
Outside
Inside
Window
Boundary 𝑃′
𝑃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
Outside
Inside
Window
Boundary 𝑃′
𝑃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
Outside
Inside
Window
Boundary 𝑃′′𝑃′
𝑃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
Outside
Inside
Window
Boundary 𝑃′′𝑃′
𝑃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
Outside
Inside
Window
Boundary 𝑃′′𝑃′
𝑃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
Outside
Inside
Window
Boundary
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 primitives
residing 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 Test
Boolean 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 Algorithm
void ScanTriangle( Triangle T , Color rgba ){
for both edge pairs{
initialize xL, xR;compute dxL/dyL and dxR/dyR;for each scanline at y
for( int x=xL ; x<=xR ; x++ ) SetPixel( x , y , rgba );xL += dxL/dyL;xR += dxR/dyR;
}}
𝑥𝐿 𝑥𝑅
𝑑𝑥𝐿𝑑𝑦𝐿
𝑑𝑥𝑅𝑑𝑦𝑅Bresenham’s algorithm
works 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
Antialiasing
Note 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-Aliasing
Images 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