Title: Shading
1Shading
2Contents
- Definition
- Light sources
- Phong reflection model
- Polygonal shading
- Shading in OpenGL
- Global rendering
3Shading
- Determine a color for each filled pixel
- How to choose a color
- the color of the light source and of the surfaces
determines the color of one or more pixels in the
frame buffer
4Light and Matter
- Color is determined by multiple interactions
among light sources and reflective surfaces - recursive reflection of light between surfaces
accounts for subtle shading
Rendering Equation
5Light-Material Interactions
- Specular surfaces mirror
- scatter reflected light in a narrow range of
angle - Diffuse surfaces chalk, clay
- scatter reflected light all directions
- Translucent surfaces glass, water
- refraction
specular surface
diffuse surface
translucent surface
6Light Sources
- Illumination function I (x, y, z, ?, f, ?)
- each point (x, y, z) on the surface
- direction of emission (?, f)
- wavelength ?
light source
7Modeling Light Sources
- Simple mathematical models
- ambient light
- point light
- directional light
- spot light
8Color Sources
- Three-color theory
- human perceive three primary colors red, green,
and blue - three-component intensity or luminance function
- independent calculations
9Ambient Light
- Uniform lighting
- identical at every point in the scene
10Point Sources (1/2)
- Emit light equally in all directions
- p0 point source location
- proportional to the inverse square distance
point source illuminating a surface
11Point Sources (2/2)
- Large finite size of most light sources
- umbra full shadow
- penumbra partial shadow
- Attenuation
shadows created by finite-size light source
12Spotlights
- Characterized by a narrow range of angle through
which light is emitted - ps apex of a cone
- ls direction of pointing
- ? angle to determine width
- Distribution of light
- concentrate in the center
- light intensity drop off
spotlight
attenuation
exponent
13Distant Light Sources
- far from the surface ? vector does not change
- location ? direction
parallel light source
14Phong Reflection Model
- Efficient and close enough approximation to
physical reality to produce good renderings - Use 4 vectors
- n normal at p
- v direction from p to the viewer or COP
- l direction from light source
- r direction of reflectance
- 3 types of material-light
- interactions
- ambient, diffuse, and specular
vectors used by the Phong model
15Computation
- Light source and reflection term
- Ex. red intensity
- Total Intensity
16Ambient Reflection
- Same at every point on the surface
- Ambient reflection coefficient
- amount reflected
- some of light source is absorbed and some is
reflected - three ambient coefficients , , and
- Ambient reflection term
- can be any of the individual light sources
- can be a global ambient term
17Diffuse Reflection (1/2)
- Characterized by rough surfaces
- perfectly diffuse surface
- ? so rough that there is no preferred
- angle of reflection
- Lamberts law
- only the vertical component of light source
rough surface
at noon
in the afternoon
Lamberts law
18Diffuse Reflection (2/2)
- Lamberts law (cont)
- Diffuse reflection term
- incorporate a distance term
Lamberts law
19Specular Reflection
- Specular surface is smooth
- highlight in the direction of the viewer
- Specular reflection term
- shininess coefficient
- a ? infinite mirror
- 100 lt a lt 500 metal
- a lt 100 broad highlight
specular highlights
specular surface
effect of shininess coefficient
20Phong Model
- Including the distance term
21Utha Teapots with Different Material Properties
22Computation of Vectors (1/2)
- Normal vectors
- in OpenGL
- Angle of reflection
n
glNormal3f(nx, ny, nz) glNormal3fv(pointer_to_nor
mal)
coplanar condition
?
?
by ? and ?
mirror
23Computation of Vectors (2/2)
- Halfway vector
- half-angle 2?f
- Transmitted light
- Snells law
halfway vector
perfect light transmission
24Polygonal Shading
- Shade a polygonal mesh
- flat shading
- interpolative or Gouraud shading
- Phong shading
polygonal mesh
25Flat Shading (1/2)
- Constant shading
- flat polygon
- ? n constant
- distant light source
- ? l constant
- distant viewer
- ? v constant
- One shading calculation for each polygon
- In OpenGL
distant source and viewer
glShadeModel(GL_FLAT)
26Flat Shading (2/2)
- Always be disappointing for a smooth surface
- lateral inhibition
- human visual system has a remarkable sensitivity
- Mach bands
- perceive the increases in brightness along the
edges
flat shading of polygonal mesh
perceived and actual intensities at an edge
We need smoother shading techniques to avoid it!!
27Interpolative and Gouraud Shading
- In OpenGL
- One lighting calculation for each vertex
- bilinearly interpolate colors
- Vertex normal could be defined through
interpolation
glShadeModel(GL_SMOOTH)
normals near interior vertex
28Wireframe
29Flat Shading
30Gouraud Shading
31Phong Shading
- May not prevent the appearance of Mach bands
- What if polygonal mesh is too coarse to capture
illumination effects in polygon interiors? - One shading calculation for each pixel ? off-line
- Compute vertex normal at each point
interpolate normals across each polygon
interpolation of normals
edge normals
32Visible-Line Determination
33Visible-Surface Determination with Ambient
Illumination Only
34Flat Shaded Polygons with Diffuse Reflection
35Gouraud Shaded Polygons with Diffuse Reflection
36Gouraud Shaded Polygons with Specular Reflection
37Phong Shaded Polygons with Specular Reflection
38Phong Shading of Curved Surfaces with Specular
Reflection
39Improved Illumination Model and Multiple Lights
40Texture Mapping