Shading and lighting models aim to make 3D objects appear realistic by simulating how light interacts with surfaces. The Phong lighting model approximates these interactions using components for ambient, diffuse, and specular reflection. It calculates the color and brightness at each point based on material properties, light sources, and the viewer's position. The modified Phong or Blinn model improves efficiency by using the halfway vector between the light and view directions for the specular calculation. Ray tracing provides a more physically accurate solution by simulating the paths of light in a scene.
1. Shading and Lighting
Why we need shading
• Shade objects so their images • Suppose we build a model of a
appear three-dimensional sphere using many polygons and
• Light-material interactions color it with glColor. We get
• Phong model something like
• But we want
Shading Scattering
• Why does the image of a real sphere look • Light strikes A
like – Some scattered
– Some absorbed
• Some of scattered light strikes B
– Some scattered
• Light-material interactions cause each
– Some absorbed
point to have a different color or shade
• Need to consider • Some of this scattered
– Light sources light strikes A
– Material properties and so on
– Location of viewer
– Surface orientation
1
2. Rendering Equation Global Effects
• The infinite scattering and absorption shadow
of light can be described by the
rendering equation
– Cannot be solved in general
– Ray tracing is a special case for
perfectly reflecting surfaces
multiple reflection
• Rendering equation is global and translucent surface
includes
– Shadows
– Multiple scattering from object to object
Ray Tracing Scene Local vs Global Rendering
• Correct shading requires a global
calculation involving all objects and
light sources
– Incompatible with pipeline model which
shades each polygon independently
(local rendering)
• However, in computer graphics,
especially real time graphics, we are
happy if things “look right”
– Exist many techniques for
approximating global effects
2
3. Light-Material Interaction
Light Sources
• Light that strikes an object is partially
absorbed and partially scattered General light sources are difficult to
(reflected) or refracted work with because we must integrate
• The amount reflected determines the light coming from all points on the
color and brightness of the object source
– A surface appears red under white light
because the red component of the light is
reflected and the rest is absorbed
• The reflected light is scattered in a
manner that depends on the
smoothness and orientation of the
surface
Simple Light Sources Surface Types
• Point source • The smoother a surface, the more
– Model with position and color reflected light is concentrated in the
– Distant source = infinite distance away direction a perfect mirror would reflected
(parallel) the light
• Spotlight • A very rough surface scatters light in all
directions
– Restrict light from ideal point source
• Ambient light
– Same amount of light everywhere in
scene
– Can model contribution of many sources smooth surface rough surface
and reflecting surfaces
3
4. Phong Model Ideal Reflector
• A simple model that can be computed • Normal is determined by local
rapidly
orientation
• Has three components
– Diffuse • Angle of incidence = angle of
– Specular reflection
– Ambient • The three vectors must be coplanar
• Uses four vectors r = 2 (l · n ) n - l
– To source
– To viewer
– Normal
– Perfect reflector
Lambertian Surface
• Perfectly diffuse reflector Specular Surfaces
• Light scattered equally in all • Most surfaces are neither ideal diffusers
directions nor perfectly specular (ideal reflectors)
• Amount of light reflected is • Smooth surfaces show specular highlights
due to incoming light being reflected in
proportional to the vertical
directions concentrated close to the
component of incoming light direction of a perfect reflection
– reflected light ~cos θi
– cos θi = l · n if vectors normalized
– There are also three coefficients, kr, kb, kg
specular
that show how much of each color highlight
component is reflected
4
5. Modeling Specular
Reflections The Shininess Coefficient
• Phong proposed using a term that • Values of α between 100 and 200
dropped off as the angle between the correspond to metals
viewer and the ideal reflection • Values between 5 and 10 give surface that
increased look like plastic
Ir ~ ks I cosαφ
cosα φ
φ
reflected shininess coef
intensity incoming intensity
absorption coef
-90 φ 90
Ambient Light Light Sources
• Ambient light is the result of multiple • In the Phong Model, we add the
interactions between (large) light results from each light source
sources and the objects in the
• Each light source has separate
environment
diffuse, specular, and ambient
• Amount and color depend on both terms to allow for maximum
the color of the light(s) and the flexibility even though this form
material properties of the object does not have a physical
• Add ka Ia to diffuse and specular justification
terms • Separate red, green and blue
reflection coef intensity of ambient light components
5
6. Adding up the Components
Material Properties For each light source and each color
• Hence, 9 coefficients for each point component, the Phong model can be
source written as
– Idr, Idg, Idb, Isr, Isg, Isb, Iar, Iag, Iab I =kd Id l · n + ks Is (v · r )α + ka Ia
For each color component
• Material properties match light
source properties
we add contributions from
– Nine absorbtion coefficients all sources
• kdr, kdg, kdb, ksr, ksg, ksb, kar, kag, kab
– Shininess coefficient α
Modified Phong Model The Halfway Vector
• The specular term in the Phong • h is normalized vector halfway
model is problematic because it between l and v
requires the calculation of a new h = ( l + v )/ | l + v |
reflection vector and view vector for
each vertex
• Blinn suggested an approximation
using the halfway vector that is more
efficient
6
7. Using the halfway angle Example
• Replace (v · r )α by (n · h )β
• β is chosen to match shineness
• Note that halfway angle is half of Only differences in
angle between r and v if vectors are these teapots are
the parameters
coplanar in the modified
• Resulting model is known as the Phong model
modified Phong or Blinn lighting
model
– Specified in OpenGL standard
Computation of Vectors Ray Tracing Algorithm
• l and v are specified by the application • References
• Can compute r from l and n – Glassner, Andrew (Ed.) (1989). An Introduction to Ray
Tracing. Academic Press
• Problem is determining n – Shirley, Peter and Morley Keith, R. (2001) Realistic Ray
• For simple surfaces n is can be determined Tracing,2nd edition. A.K. Peters
– Free ray tracing program POV-Ray at
but how we determine n differs depending http://www.povray.org
on underlying representation of surface – Siggraph 2005 course notes
• OpenGL leaves determination of normal to • Introduction to Real-Time Ray Tracing
application – Many graphics books…
– Exception for GLU quadrics and Bezier surfaces
7