1.Opener a)Is this polygon convex or concave? How do you know?
Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5...
Transcript of Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5...
![Page 1: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/1.jpg)
Scan Conversion& Shading
Courtesy of Adam Finkelstein, Princeton University
![Page 2: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/2.jpg)
3D Rendering Pipeline (for direct illumination)
3D Primitives
ModelingTransformation
ModelingTransformation
ProjectionTransformation
ProjectionTransformation
ClippingClipping
LightingLighting
Image
ViewportTransformation
ViewportTransformation
ScanConversion
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
ViewingTransformation
ViewingTransformation
3D World Coordinates
2D Image Coordinates
Scan Conversion& Shading
P1
P2
P3
![Page 3: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/3.jpg)
Overview• Scan conversion
o Figure out which pixels to fill
• Shadingo Determine a color for each filled pixel
![Page 4: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/4.jpg)
Rasterization• After projection, we work in a 2-D space again
• Screen coordinate representation
• Generate a set of pixels through rasterization or scan conversion
• OpenGL allows us to manipulate pixels directly, need not worry about writing to frame buffer directly
![Page 5: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/5.jpg)
Scan-Line Algorithm
• Most efficient method when memory was limited
• Move from left to right
• Draw polygons as we come to them
• For intersecting polygons determine z value
• Comparison with z-Buffer:One scan line at a time not one polygon at a time
![Page 6: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/6.jpg)
Scan Conversion
• Rasterization of primitives
• Assume frame buffer is an n × m array of pixels, (0,0) in lower-left corner
• write_pixel(int ix, int iy, int value);
• Frame buffers are inherently discrete
• Screen coordinates are real numbers
![Page 7: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/7.jpg)
Differential Digital Analyzer
![Page 8: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/8.jpg)
DDA Algorithm• Simplest scan-conversion algorithm
• Digital Differential Analyzer – an electromechanical device to simulate differential equations
• Simple differential equation: dy/dx=m
1012
12 ≤≤∆∆
=−−
= mxy
xxyy
m where
![Page 9: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/9.jpg)
DDA Algorithm
![Page 10: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/10.jpg)
DDA Algorithm
for(x=x1, ix <= x2, x++){
y+=m;write_pixel(x, round(y), line_color);
}
![Page 11: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/11.jpg)
DDA Algorithm
Slope greater than 1 Swap the roles of x and y
![Page 12: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/12.jpg)
Bresenham’s Algorithm
![Page 13: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/13.jpg)
Bresenham’s Algorithm
Decision variabled = a - bd > 0 then lower pixel,
otherwise upper pixel
![Page 14: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/14.jpg)
Flood Fill• Start off with Bresenham’s algorithm for the edges
• Find a seed point (x,y)
flood_fill(int x, int y){
if(read_pixel(x,y)==WHITE){
write_pixel(x,y,BLACK);flood_fill(x-1,y);flood_fill(x+1,y);flood_fill(x,y-1);flood_fill(x,y+1);
}}
![Page 15: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/15.jpg)
Scan Conversion• Render an image of a geometric primitive
by setting pixel colors
• Example: Filling the inside of a triangle
P1
P2
P3
void SetPixel(int x, int y, Color rgba)void SetPixel(int x, int y, Color rgba)
![Page 16: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/16.jpg)
Scan Conversion• Render an image of a geometric primitive
by setting pixel colors
• Example: Filling the inside of a triangle
P1
P2
P3
void SetPixel(int x, int y, Color rgba)void SetPixel(int x, int y, Color rgba)
![Page 17: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/17.jpg)
Triangle Scan Conversion• Properties of a good algorithm
o Symmetrico Straight edgeso Antialiased edgeso No cracks between adjacent primitiveso MUST BE FAST!
P1
P2
P3
P4
![Page 18: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/18.jpg)
Triangle Scan Conversion• Properties of a good algorithm
o Symmetrico Straight edgeso Antialiased edgeso No cracks between adjacent primitiveso MUST BE FAST!
P1
P2
P3
P4
![Page 19: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/19.jpg)
Simple Algorithm
P1
P2
P3
void ScanTriangle(Triangle T, Color rgba){for each pixel P at (x,y){
if (Inside(T, P)) SetPixel(x, y, rgba);
}}
void ScanTriangle(Triangle T, Color rgba){for each pixel P at (x,y){
if (Inside(T, P)) SetPixel(x, y, rgba);
}}
• Color all pixels inside triangle
![Page 20: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/20.jpg)
P1
P2
Line defines two halfspaces• Implicit equation for a line
o On line: ax + by + c = 0o On right: ax + by + c < 0o On left: ax + by + c > 0
L
![Page 21: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/21.jpg)
Inside Triangle Test• A point is inside a triangle if it is in the
positive halfspace of all three boundary lineso Triangle vertices are ordered counter-clockwiseo Point must be on the left side of every boundary line
PL1
L2
L3
![Page 22: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/22.jpg)
Inside Triangle TestBoolean Inside(Triangle T, Point P){
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;
}
L1
L2
L3
![Page 23: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/23.jpg)
Simple Algorithm
P1
P2
P3
void ScanTriangle(Triangle T, Color rgba){for each pixel P at (x,y){
if (Inside(T, P)) SetPixel(x, y, rgba);
}}
void ScanTriangle(Triangle T, Color rgba){for each pixel P at (x,y){
if (Inside(T, P)) SetPixel(x, y, rgba);
}}
• What is bad about this algorithm?
![Page 24: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/24.jpg)
Triangle Sweep-Line Algorithm• Take advantage of spatial coherence
o Compute which pixels are inside using horizontal spanso Process horizontal spans in scan-line order
• Take advantage of edge linearityo Use edge slopes to update coordinates incrementally
dxdy
![Page 25: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/25.jpg)
Triangle Sweep-Line Algorithmvoid ScanTriangle(Triangle T, Color rgba){
for each edge pair {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;
}}
xL xR
dxLdyL
dxRdyR
Bresenham’s algorithmworks the same way, but uses only integer operations!
![Page 26: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/26.jpg)
Polygon Scan Conversion• Fill pixels inside a polygon
o Triangleo Quadrilateralo Convexo Star-shapedo Concaveo Self-intersectingo Holes
What problems do we encounter with arbitrary polygons?
![Page 27: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/27.jpg)
Polygon Scan Conversion• Need better test for points inside polygon
o Triangle method works only for convex polygons
Convex Polygon
L1
L2
L3
L4L5
L1
L2
L3A
L4L5
Concave Polygon
L3B
![Page 28: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/28.jpg)
Inside Polygon Rule
Concave Self-Intersecting With Holes
• What is a good rule for which pixels are inside?
![Page 29: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/29.jpg)
Inside Polygon Rule
Concave Self-Intersecting With Holes
• Odd-parity ruleo Any ray from P to infinity crosses odd number of edges
![Page 30: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/30.jpg)
Polygon Sweep-Line Algorithm• Incremental algorithm to find spans,
and determine insideness with odd parity ruleo Takes advantage of scanline coherence
xL xR
Triangle Polygon
![Page 31: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/31.jpg)
Polygon Sweep-Line Algorithmvoid ScanPolygon(Triangle T, 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 pair of active edges (left-to-right)
SetPixels(xi, xi+1, y, rgba);}
}
![Page 32: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/32.jpg)
Hardware Scan Conversion• Convert everything into triangles
o Scan convert the triangles
![Page 33: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/33.jpg)
Display• All is not perfect on the screen
• Numerous quality problems
• image oriented (pixels) vs. object oriented rendering
• Jaggedness on raster displays
• Introduce aliasing
![Page 34: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/34.jpg)
Antialiasing• Aliasing – an attempt to go from the continuous
representation of an object, which has infinite resolution, to a discrete approximation, which has limited resolution
![Page 35: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/35.jpg)
Antialiasing
![Page 36: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/36.jpg)
Antialiasing
Mathematical lines are one-dimensional entities that have length but no widthRasterized lines must have width in order to be visible
![Page 37: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/37.jpg)
Antialiasing
Shade each box by the percentage of the ideal line that crosses itAntialiasing by area averaging
![Page 38: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/38.jpg)
Hardware Antialiasing• Supersample pixels
o Multiple samples per pixelo Average subpixel intensities (box filter)o Trades intensity resolution for spatial resolution
P1
P2
P3
![Page 39: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/39.jpg)
Overview• Scan conversion
o Figure out which pixels to fill
• Shadingo Determine a color for each filled pixel
![Page 40: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/40.jpg)
Shading• How do we choose a color for each filled pixel?
o Each illumination calculation for a ray from the eyepointthrough the view plane provides a radiance sample» How do we choose where to place samples?» How do we filter samples to reconstruct image?
Angel Figure 6.34
Emphasis on methods that can be implemented in hardware Emphasis on methods that can be implemented in hardware
![Page 41: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/41.jpg)
Ray Casting• Simplest shading approach is to perform
independent lighting calculation for every pixelo When is this unnecessary?
))()((∑ •+•++=i i
niSiiDALAE IRVKILNKIKII
![Page 42: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/42.jpg)
Polygon Shading• Can take advantage of spatial coherence
o Illumination calculations for pixels covered by same primitive are related to each other
))()((∑ •+•++=i i
niSiiDALAE IRVKILNKIKII
![Page 43: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/43.jpg)
Polygon Shading Algorithms• Flat Shading
• Gouraud Shading
• Phong Shading
![Page 44: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/44.jpg)
Polygon Shading Algorithms• Flat Shading
• Gouraud Shading
• Phong Shading
![Page 45: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/45.jpg)
Flat Shading• What if a faceted object is illuminated only by
directional light sources and is either diffuse or viewed from infinitely far away
))()((∑ •+•++=i i
niSiiDALAE IRVKILNKIKII
![Page 46: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/46.jpg)
Flat Shading• One illumination calculation per polygon
o Assign all pixels inside each polygon the same color
N
![Page 47: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/47.jpg)
Flat Shading• Objects look like they are composed of polygons
o OK for polyhedral objectso Not so good for smooth surfaces
![Page 48: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/48.jpg)
Polygon Shading Algorithms• Flat Shading
• Gouraud Shading
• Phong Shading
![Page 49: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/49.jpg)
Gouraud Shading• What if smooth surface is represented by
polygonal mesh with a normal at each vertex?
))()((∑ •+•++=i i
niSiiDALAE IRVKILNKIKII
Watt Plate 7
![Page 50: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/50.jpg)
Gouraud Shading• Method 1: One lighting calculation per vertex
o Assign pixels inside polygon by interpolating colors computed at vertices
![Page 51: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/51.jpg)
Gouraud Shading• Bilinearly interpolate colors at vertices
down and across scan lines
![Page 52: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/52.jpg)
Gouraud Shading• Smooth shading over adjacent polygons
o Curved surfaceso Illumination highlightso Soft shadows
Mesh with shared normals at verticesWatt Plate 7
![Page 53: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/53.jpg)
Gouraud Shading• Produces smoothly shaded polygonal mesh
o Piecewise linear approximation o Need fine mesh to capture subtle lighting effects
Gouraud ShadingFlat Shading
![Page 54: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/54.jpg)
Polygon Shading Algorithms• Flat Shading
• Gouraud Shading
• Phong Shading
![Page 55: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/55.jpg)
Phong Shading• What if polygonal mesh is too coarse to capture
illumination effects in polygon interiors?
))()((∑ •+•++=i i
niSiiDALAE IRVKILNKIKII
![Page 56: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/56.jpg)
Phong Shading• Method 2: One lighting calculation per pixel
o Approximate surface normals for points inside polygons by bilinear interpolation of normals from vertices
![Page 57: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/57.jpg)
Phong Shading• Bilinearly interpolate surface normals at vertices
down and across scan lines
![Page 58: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/58.jpg)
Polygon Shading Algorithms
Gouraud Phong
Wireframe Flat
Watt Plate 7
![Page 59: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/59.jpg)
Shading Issues• Problems with interpolated shading:
o Polygonal silhouetteso Perspective distortiono Orientation dependence (due to bilinear interpolation)o Problems computing shared vertex normalso Problems at T-vertices
![Page 60: Scan Conversion & Shadingvis.ucsd.edu/courses/ece104/current/ScanConversion.pdf · L3A L4 L5 Concave Polygon L3B. Inside Polygon Rule Concave Self-Intersecting With Holes • What](https://reader034.fdocuments.us/reader034/viewer/2022042709/5f41cdf7951a731843606eed/html5/thumbnails/60.jpg)
Summary• 2D polygon scan conversion
o Paint pixels inside primitiveo Sweep-line algorithm for polygons
• Polygon Shading Algorithmso Flato Gouraudo Phongo Ray casting
• Key ideas:o Sampling and reconstructiono Spatial coherence
Less expensive
More accurate