Professional Documents
Culture Documents
16-Phong Shading PDF
16-Phong Shading PDF
Illumination Model
+ =
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
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
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
v
n
specular intensity
r
r
l
v
φ
angle
mshi:
RTR3
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)
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
can also be a function of height off the ground radial- or range-based,
not simply z-based
Akenine-Möller02
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
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 …
vertex colors
Primitive Processing interpolated
across polygon
(Gouraud shading)
Rasterization
Fragment Processing
per-pixel
Framebuffer Phong shading
(expensive)
Display