You are on page 1of 12

Phong

Illumination Model

EECS 487: Interactive A local illumination model


•  one bounce: light → surface → viewer

Computer Graphics Lighting a single point



At the point:
n: surface normal (orientation of surface)
Lecture 16: n
l: light vector (surface to light)
•  Phong Illumination Model v: viewing vector (surface to eye)
θ ϕ
•  Shading θ: light angle of incidence
l v
ϕ: viewing angle

Phong Illumination Model Surface Reflection Coefficients


Approximate surface color as Light sources:
sum of three components: Approximate BRDFs: not physically based
sd diffuse light intensity
•  an ideal diffuse component
ss specular light intensity
•  a glossy/blurred specular component
sa ambient light intensity
Modify surface color by changing reflection
•  an ambient term coefficients based on:
•  material type
ma ambient color reflection
•  surface finish
•  texture maps md diffuse color reflection
+ = •  what looks good ms specular color reflection
•  artistic license mshi shininess (blurriness)
•  trial and error me emissive color intensity
•  personal library

+ =
Diffuse Example Ideal Diffuse Reflectance
Ideal diffuse surface reflects light equally in all
directions, according to Lambert's cosine law:
•  amount of light energy that falls on surface and gets
Where is the light? reflected is proportional to the incidence angle, θ
•  perceived brightness (reflectance) is view independent
Where’s the normal
direction at the brightest
point? θ

Durand

Ideal Diffuse Reflectance Ideal Diffuse Model


Amount of light energy that falls
At the microscopic level, an ideal on surface is proportional to
diffuse surface is a very rough surface incidence angle, θ:
•  microfacets are oriented in any which way cd = sd md cos θ
•  examples: chalk, clay, surface of moon Curless
For normalized n and l:
cd = sd md max((n•l), 0) RTR2
• (n•l) < 0 cos θ < 0 θ > 90º,
light source is behind surface
• why must n and l be normalized? l
θ n
u·v
u·v = u v cosθ ⇒ cosθ =
u v

Durand
Diffuse Reflectance and Viewing Angle Ideal Specular/Mirror Reflectance
Lambert’s Cosine Law: amount of light energy that falls on
Accounts for highlight seen on objects
surface and gets reflected is proportional to incidence angle, θi
•  cos θi = dot product of light vector with normal (both normalized)
with smooth, shiny surfaces, such as:
•  metal
•  polished stone
Shouldn’t the amount of energy reflected also be proportional
•  plastics
to viewing angle, θr?
•  apples
•  no, whereas larger θi means
•  skin
energy arriving over area n
Recall:
dA cos θi is spread across the sin (π/2 – θ) = cos θ
larger area dA, larger θr simply
means collecting energy from n
the same area dA, but channelling
dA cos θ
it through the smaller area dA cos θr
θ
Surface 2 π/2 − θ Surface 1

dA
TP3, FvD94 Curless,Zhang

Ideal Specular/Mirror Reflectance Phong Specular Reflection n


r
l v
Reflection only at mirror angle Simulates a highlight θ θ φ
•  highlight intensity depends on
viewing direction Reflection angle = incidence angle = θ
Most intense specular reflection when v = r
Model: all microfacets of mirror
surface are oriented in the same
How to compute r?
direction as the surface itself
•  examples: mirrors, highly polished
r = −l + 2(n•l)n n
(in OpenGL, specular term is 0 if l • n = 0)
metals
r l
2(n ⋅ l)n (n ⋅ l)n

Durand
-l
Glossy Reflectors Glossy
Real materials tend to deviate significantly from ideal Reflectors
mirror reflectors ⇒ highlight and reflections are blurry
Simple empirical model:
Also known as: “rough specular”, “directional diffuse”, •  we expect most of the reflected light to travel in
or “glossy” reflection the direction of the ideal reflection ray
•  but due to variations in microfacet orientations,
(there are no ideal diffuse surfaces either …) some of the light will be reflected just slightly
off from the ideal reflected direction
•  as we angle away from the reflected ray, we
expect to see less light reflected

Durand Durand

Surface Roughness Phong “Glossy” Reflection Model


Schlick As v angles away from r, specular reflection falls
specular diffuse off, simulating “glossy” reflection:



Perfect Mirror Glossy Surface Less Shiny Surface Diffuse Surface v
v
increasing roughness

TP3

less glossy/ more glossy/blurry


more specular
Phong “Glossy” Reflection Model Material Glossiness
Phong specular model: To account for the shininess of different material:
cs = ss ms max((r • v), 0) shi
m
cs = ss ms cos φ = ss ms max((r • v), 0)
larger mshi gives tighter and shinier highlight, with
sudden dropoff, simulating a more mirror-like surface
cos φ

v
n

specular intensity
r
r
l
v
φ

angle

mshi:
RTR3

Phong Specular Reflection Blinn-Phong (Blinn-Torrance) Model


larger mshi , tighter highlight Back to micro facets:
•  model surface by a collection of tiny mirrors

•  specular reflectance comes from mirrors oriented


larger ms , shinier

halfway between l and v, in direction of h

l n h

v
ω ω

TP3 Manocha
Blinn-Phong Illumination Models
h A rendering process can be modeled as an integral
Model specular reflection with “halfway” l l equation representing the transport of light through
vector (h) instead of r v the environment the rendering equation
•  consider the microfacet through point p that p Local illumination: an approx. of the rendering eqn.
reflects light perfectly to the viewer •  assumes light is scattered only once: light from light source
is reflected by a surface and modulated on its way towards
•  h is the normal of this plane, it is halfway l+v
h= the eye
between l and v (by definition), h normalized l+v
Global illumination:
•  angle between h and n is β; v = r when h = n
n h •  light rays traveling from light to surface may be
(β is not the angle between v and r) l r •  blocked by intervening surfaces (shadows) or
•  specular reflection modeled as: β •  bent or scattered by intervening material (refraction and atmospheric
v
effects) or
cs = ss ms (n • h) 4mshi
= ss ms (cos β) 4mshi
p •  light arriving at a surface may come indirectly via another
surface (reflection and color bleed)

Phong Ambient Term Putting It All Together


Phong Illumination Model
“Approximates” the contribution of all indirect
ct = ma sa + (md (n ⋅ l) + ms (r ⋅ v)mshi ) f (d)s
illumination
Phong ρa ρd ρs ρtotal

Surface uniformly lit


θ = 60º
•  areas with no direct
illumination are not
completely dark
•  independent of: θ = 25º
•  light direction
•  surface normal
•  viewing angle

θ = 0º
Spheres rendered with ambient reflection only
Durand
OpenGL Light Sources OpenGL Lighting and Reflectance
glLightfv(lightname,param,value)
/* Initialize material property, light source,
•  parameters lighting model, and depth buffer. */
•  GL_AMBIENT void init(void)
•  GL_DIFFUSE {
•  GL_SPECULAR GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
•  GL_POSITION GLfloat mat_shininess[] = { 50.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
•  GL_SPOT_DIRECTION
glClearColor(0.0, 0.0, 0.0, 0.0);
•  GL_SPOT_CUTOFF
glShadeModel(GL_SMOOTH);
•  GL_SPOT_EXPONENT
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
•  GL_CONSTANT_ATTENUATION glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
•  GL_LINEAR_ATTENUATION
•  GL_QUADRATIC_ATTENUATION glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
Turning on the lights: glEnable(GL_LIGHT0);
•  glEnable(GL_LIGHTING) glEnable(GL_DEPTH_TEST);
}
•  glEnable(GL_LIGHT0)

OpenGL Material Properties Choosing the Parameters


glMaterial(face,param,value)
•  face
Experiment with different parameter settings
•  GL_FRONT A few suggestions:
•  GL_BACK • ma + md + ms < 1
•  GL_FRONT_AND_BACK
•  parameters • use a small ma (~0.1)
•  GL_AMBIENT • try mshi ∈ [0, 100]
•  GL_DIFFUSE
•  GL_AMBIENT_AND_DIFFUSE TP3
•  GL_SPECULAR
•  GL_SHININESS
•  GL_EMISSION
material md ms mshi
See Redbook Chapter 5 for
techniques to minimize metal small, color of metal large, color of metal large
performance costs associated medium, color of medium, color of
with changing material plastic medium
object light (or white)
properties
planet varying 0 0

Curless
Highlight Color Emissive Term
For non-metals, e.g., plastics, highlight color is color Material’s emissive parameter me
of light (plastics has a transparent/white coating) •  assumed not lighting other objects
For metals, e.g., brass, highlight depends on surface ct = me + ma sa + (md (n ⋅ l) + ms (v ⋅ r)mshi ) f (d)s
color





Surface

plastic metal clay
Apodaca&Gritz Funkhouser

Attenuation Model Global Ambient and Multiple Lights


Whereas the ambient term simulates indirect lighting,
attenuation model and fog simulate scattering effect Global ambient light source: cg = sg ma
•  sg set with:
Intensity attenuation: light falls off the further away glLightModel*(GL_LIGHT_MODEL_AMBIENT,ambient_light)
one gets from the source
•  distinguishes overlapping surfaces Multiple lights:
having the same reflection parameters n
2 ct = c g + me + ∑ c(ka ) + f (d (k ) )(c(kd ) + c(ks ) ),
•  radiant energy disperses as 1/d d1 k=1
•  d is the distance from the light source to surface
•  reason for the inverse square falloff? d2 !k:!light!number,!not!exponentiation
2
•  attenuation function f (d) = 1/(a0+a1d+a2d )
•  user defined constants a0 , a1 , a2
•  since we’re not modeling atmospheric scattering,
1/d 2 often appears too harsh
•  instead, we use f (d) = 1/(a0+a1d) or no attenuation
Lighting with attenuation: c’ = f (d )c
Fog Fog
Simple atmospheric effect color of fog: cf f p :!fog!factor!at!point!p
•  a little better realism color of surface: cs zend − zstart : the!foggy!range
fog effect:
•  help to convey distances d f : fog!density
cp = f cs + (1 − f ) cf , f ∈ [0,1] !
•  2 forms of depth cueing (ignoring scattering)
•  light-to-object distance conveyed by light attenuation How to compute f ?
•  object-to-viewer atmospheric scattering simulated by fog
zend − z p
•  linear: fp =
zend − zstart

− d f zp
•  exponential: f p =e
RTR3

•  exponential-squared:
fp = e
−(d f z p )2


can also be a function of height off the ground radial- or range-based,
not simply z-based
Akenine-Möller02

Fog in OpenGL Lighting and Shading


Lighting: computing interaction between light and surfaces of
glEnable(GL_FOG); different materials, and interaction with the geometry of
glHint(GL_FOG_HINT,GL_[NICEST|FASTEST]); objects to determine the luminous intensity reflected from a
// per fragment or per vertex
specified 3D point
glFog*(GL_FOG_MODE, GL_[LINEAR|EXP|EXP2]); Shading: performing the lighting computations on polygonal
glFog*(GL_FOG_[START|END|DENSITY], param); objects and coloring the pixels
glFog*(GL_FOG_COLOR, param); flat shading Gouraud shading Phong shading

To specify a fog depth for a given vertex:


glFog*(GL_FOG_COORD_SRC, GL_FOG_COORD);
glFogCoord*(z);
glVertex(…);

RTR3
Problem with Flat Shading:
Flat Shading
Mach Band Illusion
Entire polygon displayed with the same intensity
•  calculate intensity from the reflection model In 1865, Mach discovered that
•  use the surface normal (for triangles) human eyes perceive a surface
•  compute an average normal (for >3 vertex polygons) with flat shading of different
hues as having a “fluted” aspect
Is a valid shading model when: due to the abrupt change in
•  object is truly planar shades of color (discontinuity in Mach Bands
(not an approximation of a curved surface) the first derivative of the
•  all k light sources are far enough away that shading function)
measured signal
n • l(k) is constant over the polygon surface
•  viewing position is far enough away that
n • h is constant over the polygon surface perceived signal

Riesenfeld06

Gouraud Shading
Lateral Inhibition
Match intensity across polygon edges
Mach Band Illusion is due to lateral inhibition of
Linear interpolation of color across polygon surface
the human visual system:
•  neighboring receptors are connected Gouraud shading algorithm:
•  when one fires, it inhibits its neighbors from firing
• determine average normal at each vertex (averaged over the
normals of all polygons that share the vertex)
• compute color at each vertex using the average normal
Effect: • linearly interpolate color across a single polygon surface
•  eye sensitive to difference from surrounding area (GL_SMOOTH does only the last step! GL_FLAT colors polygon with the
•  good for edge and motion detection color of the last vertex) n

∑n i
n avg = i=1
n

∑n i
i=1

n = all polygons that


share the vertex

Riesenfeld06
Gouraud Shading Example Mach Band not Eliminated
when there’s an abrupt change in the orientation of two
1.  Compute average normal at each vertex (1, 2, 3)
polygons and there’s discontinuity in the 1st derivative of
2.  Compute colors c1, c2, c3
the shading function
3.  Compute colors c4, c5 3

y -y y -y
c 4 = 4 2 c1 + 1 4 c 2
y1 - y2 y1 - y2
1

4.  Compute color cp p scanline

c = x5 - x p x p - x4 4 5
c + c 2
p x5 - x 4 4 x5 - x 4 5


Or use barycentric coordinates!
Steps 2-4 were cheap enough to be implemented in
hardware even for fixed pipeline GPU
effect can be ameliorated with increased polygon count or
Phong shading …

Limitation: Wrong Highlights Limitation: Wrong Highlights


Highlights depend on polygonal shape Why does Gouraud give inaccurate simulation of highlights?
•  color at vertex may not be (highlight) color inside the polygon
Does not capture highlight in the
middle of polygon
•  c1 = 0 because (n•h) < 0 What would give the most accurate simulation of highlights?
•  c2 = 0 because (n•l) < 0 •  compute normal of actual surface (not polygon-approximated
•  any interpolation of c1 and c2 will be 0 surface) at each pixel and color accordingly very expensive!




c1 = 0 c2 = 0
area of desired Phong shading: interpolate normal of vertices across polygon
highlight
surface and color each pixel according to interpolated normals
Shows up in animation as flashing highlights
between frames as orientation of polygons change
n3
Phong Shading OpenGL Lighting and Reflectance
n1
Algorithm: scanline /* Initialize material property, light source,
• determine average normal at each vertex n n2 lighting model, and depth buffer. */
void init(void)
• linearly interpolate per-pixel normal y - y2 y -y {
n = n1 + 1 n2
across surface y1 - y2 y1 - y2 GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 50.0 };
• compute color for each pixel using the GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
value of the approximated per-pixel normal
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH); // or GL_FLAT
// interpolate color of vertices, but does not
// average normals at the vertices

glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

Phong illumination model ≠ glLightfv(GL_LIGHT0, GL_POSITION, light_position);

Phong specular reflection ≠ c1 = 0 c2 = 0 glEnable(GL_LIGHTING);


Phong shading area of desired
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
highlight }

Where in the Pipeline?


Application vertex colors
computed
Vertex Processing

vertex colors
Primitive Processing interpolated
across polygon
(Gouraud shading)
Rasterization

Fragment Processing

per-pixel
Framebuffer Phong shading
(expensive)

Display

You might also like