06b rendering iii
TRANSCRIPT
-
7/27/2019 06b Rendering III
1/13
T h o m a s
F u n
k h o u s e r
2 0 0 0 Scan Conversion
& Shading
Thomas FunkhouserPrinceton UniversityC0S 426, Fall 1999
2008'
3D PolygonRendering Pipeline
T h o m a s
F u n
k h o u s e r
2 0 0 0
3D Rendering Pipeline (for direct illumination)3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
ViewportTransformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
ViewingTransformation
3D World Coordinates
2D Image Coordinates
Scan Conversion& Shading
P1
P2
P3
T h o m a s
F u n
k h o u s e r
2 0 0 0
Overview Scan conversion
Figure out which pixels to fill
ShadingDetermine a color for each filled pixel
Texture MappingDescribe shading variation within polygon interiors
Visible Surface DeterminationFigure out which surface is front-most at every pixel
T h o m a s
F u n
k h o u s e r
2 0 0 0
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)
T h o m a s
F u n
k h o u s e r
2 0 0 0
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)
T h o m a s
F u n
k h o u s e r
2 0 0 0
Triangle Scan Conversion Properties of a good algorithm
SymmetricStraight edgesAntialiased edgesNo cracks between adjacent primitivesMUST BE FAST!
P1
P2
P3
P4
-
7/27/2019 06b Rendering III
2/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Triangle Scan Conversion Properties of a good algorithm
SymmetricStraight edges
Antialiased edgesNo cracks between adjacent primitivesMUST BE FAST!
P1
P2
P3
P4
T h o m a s
F u n
k h o u s e r
2 0 0 0
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);
}}
Color all pixels inside triangle
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Inside Triangle Test A point is inside a triangle if it is in the
positive halfspace of all three boundary linesTriangle vertices are ordered counter-clockwisePoint must be on the left side of every boundary line
PL1
L2
L3
T h o m a s
F u n
k h o
u s e r
2 0 0 0
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
T h o m a s
F u n
k h o u s e r
2 0 0 0
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);
}}
What is bad about this algorithm?
T h o m a s
F u n
k h o u s e r
2 0 0 0
Triangle Sweep-Line Algorithm Take advantage of spatial coherence
Compute which pixels are inside using horizontal spansProcess horizontal spans in scan-line order
Take advantage of edge linearityUse edge slopes to update coordinates incrementally
dxdy
-
7/27/2019 06b Rendering III
3/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Triangle Sweep-Line Algorithmvoid ScanTriangle(Triangle T, Color rgba){
for each edge pair {initialize x L, x R ;compute dx L/dy L and dx R /dy R ;for each scanline at y
for (int x = x L; x
-
7/27/2019 06b Rendering III
4/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Polygon Sweep-Line Algorithmvoid ScanPolygon(Triangle T, Color rgba){
sort edges by maxy make empty active e dge list
for each scanline (top-to-bottom) {insert/remove edges from active edge listupdate x coordinate of every active edgesort active edges by x coordinatefor each pair of active edges (left-to-right)
SetPixels(x i , x i+1 , y, rgba);}
}
T h o m a s
F u n
k h o u s e r
2 0 0 0
Hardware Scan Conversion Convert everything into triangles
Scan convert the triangles
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Hardware Antialiasing Supersample pixels
Multiple samples per pixelAverage subpixel intensities (box filter)Trades intensity resolution for spatial resolution
P1
P2
P3
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Overview Scan conversion
Figure out which pixels to fill
ShadingDetermine a color for each filled pixel
Texture MappingDescribe shading variation within polygon interiors
Visible Surface DeterminationFigure out which surface is front-most at every pixel
T h o m a s
F u n
k h o u s e r
2 0 0 0
Shading How do we choose a color for each fi lled pixel?
Each illumination calculation for a ray f rom 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 canbe implemented in hardware
T h o m a s
F u n
k h o u s e r
2 0 0 0
Ray Casting Simplest shading approach is to perform
independent lighting calculation for every pixelWhen is this unnecessary?
))()((i i
n
iS ii D AL A E I RV K I L N K I K I I
-
7/27/2019 06b Rendering III
5/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Polygon Shading Can take advantage of spatial coherence
Illumination calculations for pixels covered by sameprimitive are related to each other
))()((i i
n
iS ii D AL A E I RV K I L N K I K I I
T h o m a s
F u n
k h o u s e r
2 0 0 0
Polygon Shading Algorithms Flat Shading
Gouraud Shading
Phong Shading
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Flat Shading What if a faceted object is il luminated only by
directional light sources and is either diffuse orviewed from infinitely far away
))()((i i
n
iS ii D AL A E I RV K I L N K I K I I
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Flat Shading One illumination calculation per polygon
Assign all pixels inside each polygon the same color
N
T h o m a s
F u n
k h o u s e r
2 0 0 0
Flat Shading Objects look like they are composed of polygons
OK for polyhedral objectsNot so good for ones with smooth surfaces
T h o m a s
F u n
k h o u s e r
2 0 0 0
Polygon Shading Algorithms Flat Shading
Gouraud Shading Phong Shading
-
7/27/2019 06b Rendering III
6/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Gouraud Shading What if smooth surface is represented by
polygonal mesh with a normal at each vertex?
))()((i i
n
iS ii D AL A E I RV K I L N K I K I I
Watt Plate 7
T h o m a s
F u n
k h o u s e r
2 0 0 0
Gouraud Shading Method 1: One lighting calculation per vertex
Assign pixels inside polygon by interpolating colorscomputed at vertices
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Gouraud Shading Bilinearly interpolate colors at vertices
down and across scan lines
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Gouraud Shading Smooth shading over adjacent polygons
Curved surfacesIllumination highlightsSoft shadows
Mesh with shared normals at verticesWatt Plate 7
T h o m a s
F u n
k h o u s e r
2 0 0 0
Gouraud Shading Produces smoothly shaded polygonal mesh
Piecewise linear approximationNeed fine mesh to capture subtle lighting effects
Gouraud ShadingFlat Shading
T h o m a s
F u n
k h o u s e r
2 0 0 0
Polygon Shading Algorithms Flat Shading
Gouraud Shading Phong Shading
-
7/27/2019 06b Rendering III
7/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Phong Shading What if polygonal mesh is too coarse to capture
illumination effects in polygon interiors?
))()((i i
n
iS ii D AL A E I RV K I L N K I K I I
T h o m a s
F u n
k h o u s e r
2 0 0 0
Phong Shading One lighting calculation per pixel
Approximate surface normals for points inside polygonsby bilinear interpolation of normals from vertices
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Phong Shading Bilinearly interpolate surface normals at vertices
down and across scan lines
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Polygon Shading Algorithms
Gouraud Phong
Wireframe Flat
Watt Plate 7
T h o m a s
F u n
k h o u s e r
2 0 0 0
Shading Issues Problems with interpolated shading:
Polygonal silhouettesPerspective distortionOrientation dependence (due to bilinear interpolation)Problems at T-verticesProblems computing shared vertex normals
T h o m a s
F u n
k h o u s e r
2 0 0 0
Overview Scan conversion
Figure out which pixels to fill
ShadingDetermine a color for each filled pixel
Texture MappingDescribe shading variation within polygon interiors
Visible Surface DeterminationFigure out which surface is front-most at every pixel
-
7/27/2019 06b Rendering III
8/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
SurfaceImageTexture
Textures Describe color variation in interior of 3D polygon
When scan converting a polygon, vary pixel colorsaccording to values fetched from a texture
Angel Figure 9.3 T h o m a s
F u n
k h o u s e r
2 0 0 0
Surface Textures Add visual detail to surfaces of 3D objects
Polygonal model
With surface texture
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Surface Textures
T h o m a s
F u n
k h o
u s e r
2 0 0 0
3D Rendering Pipeline (for direct illumination)3D Primitives
ModelingTransformation
ProjectionTransformation
Clipping
Lighting
Image
Viewport
Transformation
ScanConversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
ViewingTransformation
3D World Coordinates
2D Image Coordinates
Texture mapping
T h o m a s
F u n
k h o u s e r
2 0 0 0
Overview Texture mapping methods
MappingFilteringParameterization
Texture mapping applicationsModulation texturesIllumination mappingBump mappingEnvironment mappingImage-based renderingNon-photorealistic rendering
T h o m a s
F u n
k h o u s e r
2 0 0 0
Texture Mapping Steps:
Define textureSpecify mapping from texture to surfaceLookup texture values during scan conversion
(0,0)
(1,0)
(0,1)
uv
x
y
ModelingCoordinate
System
ImageCoordinate
System
s
t
TextureCoordinate
System
-
7/27/2019 06b Rendering III
9/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Texture Mapping When scan convert, map from
image coordinate system (x,y) tomodeling coordinate system (u,v) to
texture image (t,s)
(0,0)
(1,0)
(1,1)(0,1)
uv
x
y
ModelingCoordinate
System
ImageCoordinate
System
s
t
TextureCoordinate
System T h o m a s
F u n
k h o u s e r
2 0 0 0
Texture Mapping
Chris Buehler & Leonard McMillan, MIT
Texture mapping is a 2D projective transformationtexture coordinate system: (t,s) toimage coordinate system (x,y)
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Texture Mapping Scan conversion
Interpolate texture coordinates down/across scan linesDistortion due to bilinear interpolation approximation Cut polygons into smaller ones, or Perspective divide at each pixel
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Texture Mapping
Linear interpolationof texture coordinates
Correct interpolationwith perspective divide
Hill Figure 8.42
T h o m a s
F u n
k h o u s e r
2 0 0 0
Overview Texture mapping methods
MappingFilteringParameterization
Texture mapping applicationsModulation texturesIllumination mappingBump mappingEnvironment mappingImage-based renderingNon-photorealistic rendering
T h o m a s
F u n
k h o u s e r
2 0 0 0
Texture Filtering
Angel Figure 9.4
Must sample texture to determine colorat each pixel in image
-
7/27/2019 06b Rendering III
10/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Texture Filtering
Angel Figure 9.5
Aliasing is a problem
Point sampling Area filtering
T h o m a s
F u n
k h o u s e r
2 0 0 0
Texture Mapping Scan conversion
Interpolate texture coordinates down/across scan linesDistortion due to bilinear interpolation approximation
Cut polygons into smaller ones, or Perspective divide at each pixel
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Texture Mapping
Linear interpolationof texture coordinates
Correct interpolationwith perspective divide
Hill Figure 8.42 T h o m a s
F u n
k h o
u s e r
2 0 0 0
Overview Texture mapping methods
MappingFilteringParameterization
Texture mapping applicationsModulation texturesIllumination mappingBump mappingEnvironment mapping
Image-based renderingNon-photorealistic rendering
T h o m a s
F u n
k h o u s e r
2 0 0 0
Texture Filtering
Angel Figure 9.4
Must sample texture to determine colorat each pixel in image
T h o m a s
F u n
k h o u s e r
2 0 0 0
Texture Filtering
Angel Figure 9.5
Aliasing is a problem
Point sampling Area filtering
-
7/27/2019 06b Rendering III
11/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Texture Filtering Ideally, use elliptically shaped convolution fil ters
In practice, use rectangles T h o m a s
F u n
k h o u s e r
2 0 0 0
Texture Filtering
Angel Figure 9.14
Size of fil ter depends on projective warpCan prefiltering images Mip maps
Summed area tables
Magnification Minification
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Mip Maps Keep textures prefiltered at multiple resolutions
For each pixel, linearly interpolate betweentwo closest levels (e.g., trilinear filtering)Fast, easy for hardware
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Summed-area tables At each texel keep sum of all values down&right
To compute sum of all values within a rectangle simplysubtract two entriesBetter ability to capture very oblique projectionsBut, cannot store values in a single byte
T h o m a s
F u n
k h o u s e r
2 0 0 0
Overview Texture mapping methods
MappingFilteringParameterization
Texture mapping applicationsModulation texturesIllumination mappingBump mappingEnvironment mappingImage-based renderingNon-photorealistic rendering
T h o m a s
F u n
k h o u s e r
2 0 0 0
Overview Texture mapping methods
MappingFilteringParameterization
Texture mapping applicationsModulation texturesIllumination mappingBump mappingEnvironment mappingImage-based renderingNon-photorealistic rendering
-
7/27/2019 06b Rendering III
12/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Modulation textures
)))()(((),( S S T T L L Ln
S D A A E I K I K I S RV K L N K I K I t sT I
Map texture values to scale factor
W o o
d t e x
t u r e
Texturevalue
T h o m a s
F u n
k h o u s e r
2 0 0 0
Illumination Mapping
S S T T L L L
n
S D A A E I K I K I S RV K L N K I K I I ))()((
Map texture values to surface material parameterKAKD
KSKTn
K T = T(s,t)
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Bump Mapping Map texture values to perturbations of surface
normals
T h o m a s
F u n
k h o
u s e r
2 0 0 0
Bump Mapping
H&B Figure 14.100
T h o m a s
F u n
k h o u s e r
2 0 0 0
Environment Mapping Map texture values to perturbations of surface
normals
H&B Figure 14.93 T h o m a s
F u n
k h o u s e r
2 0 0 0
Image-Based Rendering Map photographic textures to provide details for
coarsely detailed polygonal model
-
7/27/2019 06b Rendering III
13/13
T h o m a s
F u n
k h o u s e r
2 0 0 0
Solid Textures Texture values indexed by 3D location
Expensive storage, orCompute on the fly, E.g Perlin noise
T h o m a s
F u n
k h o u s e r
2 0 0 0
Solid Textures Texture values indexed by 3D location
Expensive storage, orCompute on the fly, E.g Perlin noise