Title: Illumination, Lighting and Shading Model
1Illumination, Lighting and Shading Model
- Pradondet Nilagupta
- Dept. of Computer Engineering
- Kasetsart University
2Definitions (1/2)
- Illumination the transport of energy (in
particular, the luminous flux of visible light)
from light sources to surfaces points - Note includes direct and indirect illumination
- Lighting the process of computing the luminous
intensity (i.e., outgoing light) at a particular
3-D point, usually on a surface - Shading the process of assigning colors to pixels
3Definitions (2/2)
- Illumination models fall into two categories
- Empirical simple formulations that approximate
observed phenomenon - Physically-based models based on the actual
physics of light interacting with matter - We mostly use empirical models in interactive
graphics for simplicity - Increasingly, realistic graphics are using
physically-based models
4Lighting Model
- Many different models exist for simulating
lighting reflections - Most models break lighting into constituent parts
- ambient reflections
- diffuse reflections
- specular highlights
5Lighting Model Component
- Material Properties
- used to describe an objects reflected colors
- Surface Normals
- Light Properties
- used to describe a lights color emissions
- Light Model Properties
- global lighting parameters
6Components of Illumination
- Surface properties
- Reflectance spectrum (i.e., color of the surface)
- Geometric attributes
- Position
- Orientation
- Micro-structure
- Light sources (or emitters)
- Spectrum of emittance (i.e, color of the light)
- Geometric attributes
- Position
- Direction
- Shape
- Directional attenuation
7Ambient Light Sources
- Objects not directly lit are typically still
visible - E.g., the ceiling in this room, undersides of
desks - This is the result of indirect illumination from
emitters, bouncing off intermediate surfaces - Too expensive to calculate (in real time)
Ireflected kambient Iambient
8Directional Light Sources
- all rays of light from the source are parallel
- As if the source is infinitely far away from the
surfaces in the scene - A good approximation to sunlight
- direction is constant for all surfaces in the
scene
9Point Light Sources
- A point light source emits light equally in all
directions from a single point - The direction to the light from a point on a
surface thus differs for different points
10Other Light Sources
- Spotlights are point sources whose intensity
falls off directionally. - Supported by OpenGL
- Area light sources define a 2-D emissive surface
(usually a disc or polygon) - Good example fluorescent light panels
11Reflection
- Ambient Reflections
- Diffuse Reflection
- Specular Reflections
12Ambient Reflections
- Color of an object when not directly illuminated
- Think about walking into a room with the curtains
closed and lights off
13Diffuse Reflections
- Color of an object when directly illuminated
- often referred to as base color
- The angle between the surface normal and the
incoming light is the angle of incidence - Idiffuse kd Ilight cos ?
- In practice we use vector arithmetic
- Idiffuse kd Ilight (n l)
14Specular Reflections
- Shiny surfaces exhibit specular reflection
- Polished metal
- Glossy car finish
- A light shining on a specular surface causes a
bright spot known as a specular highlight
15Phong Lighting Model
- Using surface normal
- OpenGLs lighting model based on Phongs
16OpenGL Material Properties
- GL_AMBIENT
- GL_DIFFUSE
- GL_SPECULAR
- GL_SHININESS
- GL_EMISSION
17Computing Surface Normals
- Lighting needs to know how to reflect light off
the surface - Provide normals per
- face - flat shading
- vertex - Gouraud shading
- pixel - Phong shading
- OpenGL does not support Phong natively
18Face Normals
- Same normal for all vertices in a primitive
- results in flat shading for primitive
glNormal3f( nx, ny, nz ) glBegin( GL_TRIANGLES
) glVertex3fv( v1 ) glVetrex3fv( v2 )
glVertex3fv( v3 ) glEnd()
19Computing Face Normals ( Polygons )
- Were using only planar polygons
- Can easily compute the normal to a plane
- use a cross product
20Computing Face Normals ( Algebraic )
- For algebraic surfaces, compute
- where
21Vertex Normals
- Each vertex has its own normal
- primitive is Gouraud shaded basedon computed
colors
glBegin( GL_TRIANGLES ) glNormal3fv( n1 )
glVertex3fv( v1 ) glNormal3fv( n2 )
glVetrex3fv( v2 ) glNormal3fv( n3 )
glVertex3fv( v3 ) glEnd()
22Computing Vertex Normals (Algebraic )
- For algebraic surfaces, compute
23Computing Vertex Normals ( Polygons )
- Need two things
- face normals for all polygons
- know which polygons share a vertex
24Sending Normals to OpenGL
- glNormal3f( x, y, z )
- Use between glBegin() / glEnd()
- Use similar to glColor()
25Normals and Scale Transforms
- Normals must be normalized
- non-unit length skews colors
- Scales affect normal length
- rotates and translates do not
- glEnable( GL_NORMALIZE )
26Why?
- Lighting computations are really done in eye
coordinates - this is why there are the projection and
modelview matrix stacks - Lighting normals transformed by the inverse
transpose of the ModelView matrix
27Applying Illumination
- With polygonal/triangular models
- Each facet has a constant surface normal
- If the light is directional, the diffuse
reflectance is constant across the facet - If the eyepoint is infinitely far away (constant
V), the specular reflectance of a directional
light is constant across the facet
28Flat Shading
- The simplest approach, flat shading, calculates
illumination at a single point for each polygon
- If an object really is faceted, is this accurate?
- No
- For point sources, the direction to light varies
across the facet - For specular reflectance, direction to eye varies
across the facet
29Flat Shading
- We can refine it a bit by evaluating the Phong
lighting model at each pixel of each polygon, but
the result is still clearly faceted - To get smoother-looking surfaceswe introduce
vertex normals at eachvertex - Usually different from facet normal
- Used only for shading (as opposed to what?)
- Think of as a better approximation of the real
surface that the polygons approximate (draw it)
30Vertex Normals
- Vertex normals may be
- Provided with the model
- Computed from first principles
- Approximated by averaging the normals of the
facets that share the vertex
31Gouraud Shading
- This is the most common approach
- Perform Phong lighting at the vertices
- Linearly interpolate the resulting colors over
faces - This is what OpenGL does
- Demo at http//www.cs.virginia.edu/cs551/vrml/tpo
t.wrl - Does this eliminate the facets?
32Phong Shading
- Phong shading is not the same as Phong lighting,
though they are sometimes mixed up - Phong lighting the empirical model weve been
discussing to calculate illumination at a point
on a surface - Phong shading linearly interpolating the surface
normal across the facet, applying the Phong
lighting model at every pixel - Same input as Gouraud shading
- Usually very smooth-looking results
- But, considerably more expensive
33Texture Mapping Motivation
- Scenes created with diffuse lighting look
convincingly three-dimensional, but are flat,
chalky, and cartoonish - Phong lighting lets us simulate materials like
plastic and (to a lesser extent) metal, but
scenes still seem very cartoonish and unreal - Big problem polygons are too coarse-grained to
usefully model fine surface detail - Solution texture mapping
34Texture Mapping Motivation
- Adding surface detail helps keep CG images from
looking simple and sterile - Explicitly modeling this detail in geometry can
be very expensive - Zebra stripes, wood grain, writing on a
whiteboard - Texture mapping pastes images onto the surfaces
in the scene, adding realistic fine detail
without exploding the geometry
35Texture Mapping Examples
36Texture Mapping Fundamentals
- A texture is typically a 2-D image
- Image elements are called texels
- Value stored at a texel affects surface
appearance in some way - Example diffuse reflectance, shininess,
transparency - The mapping of the texture to the surface
determines the correspondence, i.e., how the
texture lies on the surface - Mapping a texture to a triangle is easy (why?)
- Mapping a texture to an arbitrary 3-D shape is
more complicated (why?)
37Texture Mapping Rendering
- Rendering uses the mapping
- Find the visible surface at a pixel
- Find the point on that surface corresponding to
that pixel - Find the point in the texture corresponding to
that point on the surface - Use the parameters associated with that point on
the texture to shade the pixel
38Texture Mapping Basics
- We typically parameterize the texture as a
function in (u, v) - For simplicity, normalize u v to 0, 1
- Associate each triangle with a texture
- Give each vertex of the triangle a texture
coordinate (u, v) - For other points on the triangle, interpolate
texture coordinate from the vertices - Much like interpolating color or depth
- But theres a catch...