CSCE 441 Lecture 18
« previous | Monday, February 24, 2014 | next »
Shading / Texturing
Algorithms
Flat shading
Apply same color across entire polygon
- calculate color once per polygon
- center is typically used.
Not very expensive computation
Gouraud Shading
- calculate normals at vertices of polygon
- average the normals of the surrounding polygons
- weight averages with area of function
- If all normals are the same, then the result is same as flat shading
- Determine color at each vertex and interpolate across polygon.
Good for diffuse lighting
Moderately expensive computation
Phong Shading
- Assume normals at vertices of polygon
- Interpolate normals from vertices across polygo n
- Determine color at each pixel in polygon
Lot more expensive computation
Interpolating Over Polygons
Given numeric values at vertices of polygon, how do we interpolate data over the interior?
Augment scan conversion algorithm from before:
New Edge data structure:
maxY = max(y[i], y[i+1])currentX = y[i] == min(y[i] + y[i+1]) ? x[i] : x[i+1]xIncr = (x[i+1]-x[i]) / (y[i+1] - y[i])currentF = y[i] == min(y[i] + y[i+1]) ? f[i] : f[i+1]fIncr = (f[i+1]-f[i]) / (y[i+1] - y[i])
When computing entries active edge list,
currentF += fIncr
When drawing pixels
- calculate value
dF = (currentF[i+1] - currentF[i]) / (x[i+1] - x[i] F = currentF[i]- If
xis not an integer, multiplyFby(1 + (1-x)) - Add
dFtoxfor each step in pixels.
Interpolating Normals
Spherical Linear Interpolation (SLERP)
We want a parameterized normal equation between Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle n_0} and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle n_1} such that Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle n(t)} gives the normal with angles Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \mathrm{angle}{(n_0, n(t))} = \theta \, t} and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \mathrm{angle}{(n_1, n(t))} = \theta \, (1-t)} for Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle t \in [0,1]} .
Length of all vectors are the same (i.e. 1).
We want an equation of the form Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle n(t) = \alpha \, n_0 + \beta \, n_1}
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \begin{align} n_0 \times n(t) &= \beta \, ( n_0 \times n_1 ) & n_1 \times n(t) &= \alpha \, ( n_1 \times n_0 ) \\ \left| n_0 \times n(t) \right| &= \beta \, \left| n_0 \times n_1 \right| & \left| n_1 \times n(t) \right| &= \alpha \, \left| n_1 \times n_1 \right| \\ n(t) &= \frac{\sin{(\theta \, (1-t))} \, n_0 + \sin{(\theta \, t)} \, n_1}{\sin{\theta}} \end{align}}
Linear interpolation not correct over perspective projections
Equidistant objects appear closer together as they get farther away in the Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle z} -direction.
To fix this, we need rational interpolation
Texture Mapping
- Geometry and lighting don't provide sufficient visible detail
- Map a 2D image onto 3D surface.
- 2D image chopped into "charts" to minimize distortion
3D coordinates have corresponding Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle u} and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle v} coordinates in image.
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle u,v \in [0,1]}
During polygon drawing, look up color from images and multiply by shading value.
- Nearest neighboring pixel: blocky results
- Linear blending (interpolate value of coordinate from surrounding pixels): smooth appearance
- Can be much more complicated
Other Uses
- Environment Mapping
- Bump/Normal Mapping
- Displacement Mapping
- ...
Any attribute of surface position, normal, color, etc. can be placed in a texture.