12 Shading
12 Shading
12 Shading
Reading
Required
• Foley, Section16.1
Optional
• Hearn & Baker, sections 14.1,14.2,14.5
Introduction
• So far, we’ve talked exclusively about geometry.
– What is the shape of an object?
– How do I place it in a virtual 3D space?
– How do I know which pixels it covers?
– How do I know which of the pixels I should actually draw?
• Once we’ve answered all those, we have to ask one more
important question:
– What value do I set each pixel to?
• Answering this question is the job of the shading model.
• (Of course, people also call it a lighting model, a light reflection
model, a local illumination model, a reflectance model, etc.,
etc.)
Tedious Reality
• Properly determining the right color is really hard.
• Look around the room. Each light source has different
characteristics. Trillions of photons are pouring out every
second.
• These photons can:
– interact with the atmosphere, or with things in the
atmosphere
– strike a surface and
• be absorbed
• be reflected
• cause fluorescence or phosphorescence
• of course, none of the surfaces in here are perfect spheres or
cylinders. At some microscopic level (very important for
photons) they’re all really bumpy.
• also, everything depends on wavelength.
Our Problem
• We’re going to build up to an approximation of reality called the
Phong illumination model.
• It has the following characteristics:
– not physically based
– gives a first-order approximation to physical light reflection
– very fast
– widely used
Iteration Zero
• Given:
– a point P on a surface (P is determined by ray-object
intersection, for instance)
– visible through pixel p
• Assign each polygon a single color:
I = ke
where
– I is the resulting intensity
– ke is the intrinsic shade associated with the object
• This has some special-purpose uses, but not really good for
drawing a scene.
What will it like?
Iteration One
• Let’s make the color at least dependent on the overall quantity
of light available in the scene:
I = ka Ia
• ka is the ambient reflection coefficient.
– really the reflectance of ambient light
– “ambient” light is assumed to be equal in all directions
• Ia is the ambient intensity.
• Physically, what is “ambient” light?
– Answer on next page.
Indirect Illumination (Ambient)
• Some surfaces are illuminated even it is in shadow. Why?
• There is indirect lighting (background lighting) reflected from other
surfaces
1
2 3
4
5
• Note:
– Light may actually penetrate the surface, bounce around,
and then reflect back out.
– Accounts for colorization of diffusely reflected light by
plastics.
Diffuse Reflector
• The reflected intensity from a diffuse surface does not depend
on the direction of the viewer. The incoming light, though, does
depend on the direction of the light source.
I = ke + kaIa + kd Il cos η
= ke + kaIa + kd Il (N ·L)+
• where:
– kd is the diffuse reflection coefficient.
– Il is the intensity of the light source
– N is the normal to the surface (unit vector)
– L is the direction to the light source (unit vector)
– (x)+ means max {0,x}
• OpenGL supports different kinds of lights: point, directional, and
spot. How do these work?
Ideal Light Sources
Light Sources:
• In computer graphics, two types of light sources are commonly
used
• point source The light source is a zero-volume point
• directional source The point source that are infinite far away
P oint source
D irectional source
• Both types of light sources are ideal light sources (i.e. not realistic)
• But they are easy for computation.
Extended Light Sources
• One way to get this effect is to take (R·V), raised to a power ns.
• As ns gets larger,
– the dropoff becomes {more,less} gradual
– gives a {larger,smaller} highlight
– simulates a {more,less} shiny surface
Specular Reflection
Iteration Three
• Since light is additive, we can handle multiple lights by taking
the sum over every light.
• Our equation is now:
– polished copper?
– blue plastic?
– lunar dust?
Choosing the Parameters
• Ns in the range [0,100]
• Try Ka +Kd + Ks <= 1
• Use a small Ka (~0.1)
Appearance of a
diffuse (dull) sphere
n = 15
kd = 0.7
ks = 0.4
n = 15
kd = 0.85
ks = 0.25
n = 15
Choosing the Parameters
Summary
• The most important thing to take away from this lecture is the
final equation for the Phong model.
– What is the physical meaning of each variable?
– How are the terms computed?
– What effect does each term contribute to the image?
– What does varying the parameters do?