Polygon Rendering: COMP 175: Computer Graphics November 17, 2011
Polygon Rendering: COMP 175: Computer Graphics November 17, 2011
Lecture 19:
Polygon Rendering
COMP 175: Computer Graphics November 17, 2011
Remco Chang 19 Shading 1/34
How is Shading different from Lighting? Lighting evaluates the lighting equation at each point on the surface of an object Shading is kind of a hack that computes only lighting equations on the vertices, and interpolates the pixels in between
19 Shading 2/34
Remco Chang
We define a normal at each polygon (not at each vertex) Lighting: Evaluate the lighting equation at the center of each polygon using the associated normal Shading: Each sample point on the polygon is given the interpolated lighting value at the vertices (i.e. a total hack)
Remco Chang
19 Shading
3/34
We define a normal vector at each vertex Lighting: Evaluate the lighting equation at each vertex using the associated normal vector Shading: Each sample points color on the polygon is interpolated from the color values at the polygons vertices which were found in the lighting step
Remco Chang
19 Shading
4/34
Each vertex has an associated normal vector Lighting: Evaluate the lighting equation at each vertex using the associated normal vector Shading: For every sample point on the polygon we interpolate the normals at vertices of the polygon and compute the color using the lighting equation with the interpolated normal at each interior pixel
Remco Chang
19 Shading
5/34
Remco Chang
19 Shading
6/34
Constant Shading
Remco Chang 19 Shading 7/34
Flat Shading
Remco Chang 19 Shading 8/34
Gouraud Shading
Remco Chang 19 Shading 9/34
Phong Shading
Remco Chang 19 Shading 10/34
Faceted Shading:
Single illumination value per polygon (GL_FLAT) With many polygons approximating a curved surface, this creates an undesirable faceted look. Facets exaggerated by Mach banding effect
Remco Chang
19 Shading
11/34
Illumination values are computed at vertices, linearly interpolated across the pixels of the polygon Eliminates intensity discontinuities at polygon edges; still have gradient discontinuities, Mach banding is largely ameliorated, not eliminated Must differentiate desired creases from tesselation artifacts (edges of cube vs. edges on tesselated sphere) Step 1: Compute vertex normals by averaging surrounding polygon normals
Remco Chang
19 Shading
12/34
y1
ys Ia
I1
Ib
Ip
scan line
y2 y3
I2
I3
y s y2 I2 y1 y2 y y3 I b I1 s I3 y1 y3 xb x p I p Ia Ib xb xa I a I1
y1 ys y1 y2 y1 ys y1 y3 x p xa
xb xa
Remco Chang
13
13/34
Remco Chang
19 Shading
14/34
Gouraud shading can miss specular highlights because it interpolates vertex colors instead of calculating intensity directly at each point, or interpolating vertex normals Na and Nb would cause no appreciable specular component, whereas Nc would. Interpolating between Ia and Ib misses the highlight that evaluating I at c would catch
Phong shading:
Interpolated normal comes close to the actual normal of the true curved surface at a given point Reduces temporal jumping affect of highlight, e.g., when rotating sphere during animation (example on next slide)
19 Shading 15/34
Remco Chang
Phong Model: normal vector interpolation Interpolate N rather than I Always captures specular highlights, but computationally expensive At each pixel, N is recomputed and normalized (requires sq. root operation) Then I is computed at each pixel (lighting model is more expensive than interpolation algorithms) This is now implemented in hardware, very fast Looks much better than Gouraud, but still no global effects
Gouraud
Remco Chang
Phong
19 Shading
Gouraud
Phong
16/34
http://en.wikipedia.org/wiki/Gourad_shading
Remco Chang
19 Shading
17/34
Questions?
Remco Chang
19 Shading
18/34
Total hack: Project object on ground plane and render it as black polygon. Eye less sensitive to exact geometry than to contrast of shadow Projective shadows (shadow mapping)
Use orthographic or perspective matrix as CTM to project object (shadow caster) against another object; render the shadow object as another primitive Good for single light scenes with shadows cast on planes Extrude silhouette volume from object (shadow caster) to infinity in the direction opposite the light source Silhouette edge is made up of adjacent polygons, any point within the volume is in shadow
Shadow volumes
Implemented by former cs123 ta Kevin Egan and former PhD student and book co-auther Prof. Morgan McGuire, on nVidia chip
Remco Chang
19 Shading
19/34
Shadow Maps
Render the scene from the light source POV, keeping the same far clipping plane, update z-buffer only Read the z-buffer back and apply as a texture (shadow map) to the scene projected from the lights POV Render the scene from the eye point. At each pixel, if distance from light is greater than in the shadow map, the object is in shadow. Major aliasing problem, but implemented in hardware
Light
Shadow Map
By keeping the same far clipping plane, relative distances in Z are preserved
Remco Chang
20
20/34
Simulates reflections with a texture map applied to the enclosing sphere or cube of an object Texture map can either be an existing image or a rendering of the scene from the objects perspective
Cube environment map is created by stitching together 6 textures, each generated by rendering the scene from the objects POV Ray from eye is reflected over surface normal and intersected with the environment map to get texture coordinates.
19 Shading 21/34
Remco Chang
Overview: There are several hacks to approximate the lighting and shading of complex geometry without actually describing the geometry only used for fine detail
Desired Geometry
Remco Chang
19 Shading
22/34
Texture mapping a rough surface onto an object doesnt achieve desired effect. Illumination is too uniform Blinns technique: Use an array of values (stored in a texture called the bump map) to perturb the surface normals by calculating gradient of bump map and adding it to the surface normal Evaluate lighting model with perturbed normals Effect is convincing, but objects still look smooth at silhouette edges
Spherical Surface
Remco Chang 19 Shading
nVidia
23/34
Remco Chang
19 Shading
24/34
Remco Chang
Normal Mapping
Similar to bump mapping, but better for highly detailed surfaces with drastically varying normals
Bump mapping uses a single channel height field to perturb normals, while normal mapping uses a three channel map to actually replace existing surface normal x, y, and z components of the desired normal, stored in the r, g, and b channels of an image
Level of detail is now limited by normal map resolution, not number of triangles
Limitations:
Same as bump map, silhouette edges lack the added detail Though easy to use at runtime, normal maps are difficult to generate
19 Shading 26/34
Remco Chang
Normal mapping can completely alter the perceived geometry of a model Image courtesy of www.anticz.com
19 Shading 27/34
When a normal map is applied, there appears to be much more detail in the model than actually is
Remco Chang
While bump maps can be simply drawn, normal maps hold meaningful data in three overlapping channels
Normal map for a human face. Red, green, and blue channels correspond to x, y, and z normal components
www.bitmanagement.com
www3.telus.net
Normal maps are not visually intuitive like height maps. How are they created?
19 Shading 28/34
Remco Chang
Normal maps must be generated by specialized software, such as Pixologics Zbrush (www.pixologic.com)
A high resolution model is created by an artist and its normals are used to generate a normal map for a low resolution model.
3D geometry
Normal Map
Final render with normal map applied to low-res mesh (and lighting and texture maps). This is only 5,000 triangles!
Remco Chang
19 Shading
29/34
See SIGGRAPH paper: A general method for preserving attribute values on simplified meshes by Cignoni, Montani, Rocchini, Scopigno
Remco Chang
19 Shading
30/34
Displacement Map:
The actual geometric position of points over the surface are displaced along the surface normal according to the values in a texture
The displacement map used to render the scene. The intensity value indicates the height at a given point.
http://www.creativemac.com/2004/02_feb/tutorials/koc4ddisplace040224.htm
Remco Chang
19 Shading
31/34
Parallax Mapping:
Displaces texture coordinates of a surface point by a function of the view angle relative to the surface normal and the value on the height map at that point
Similar scheme to produce self-occlusion self-shadows of parallax mapped surface; More efficient and reduces swim effect for high frequency maps (Morgan McGuire Ph.D. 06 and Max McGuire)
Texture Mapped Texture and Parallax Mapped
Remco Chang
19 Shading
32/34
Texture Mapped Normal Mapped: Increased depth in rock wall Parallax Mapped: Increased depth of whole texture but unwanted swim Steep Parallax Mapped: Very realistic depth in effect. Textures look like they whole picture. Lion head, columns cast self should be 3D but they stay shadows embedded in surface, unsettling to the eye when moving http://graphics.cs.brown.edu/games/SteepParallax/index.h tml
Remco Chang
19 Shading
33/34
Questions?
Remco Chang
19 Shading
34/34