Lighting and Shading
Lighting and Shading
Properties of Light
Light Sources
Phong Illumination Model
Normal Vectors
[Angel, Ch. 6.1-6.4]
Announcements
• Written assignment #1 due Thursday
– Handin at beginning of class
• Programming assignment #2 out Thursday
1
The Rendering Equation
• (Angel, Ch 13)
Outline
• Lighting models (OpenGL oriented)
• Reflection models (Phong shading)
• Normals
• Color
2
Common Types of Light Sources
• Ambient light: no identifiable source or direction
• Point source: given only by point
• Distant light: given only by direction
• Spotlight: from source in direction
– Cut-off angle defines a cone of light
– Attenuation function (brighter in center)
• Light source described by a luminance
– Each color is described separately
– I = [Ir Ig Ib]T (I for intensity)
– Sometimes calculate generically (applies to r, g, b)
Ambient Light
• Intensity is the same at all points
• This light does not have a direction (or .. it is
the same in all directions)
3
Point Source
• Given by a point p0
• Light emitted from that point equally in all
directions
4
Distant Light Source
• Given by a vector v
• Intensity does not vary with distance (all
distances are the same .. infinite!)
Spotlight
• Most complex light source in OpenGL
• Light still emanates from point
• Cut-off by cone determined by angle T
5
Spotlight Attenuation
• Spotlight is brightest along ls
• Vector v with angle I from p to point on surface
• Intensity determined by cos I
• Corresponds to projection of v onto Is
• Spotlight exponent e determines rate
for e = 1
for e > 1
curve narrows
6
Now we can think about how the
incoming light is reflected by a surface
Surface Reflection
• When light hits an opaque surface some is absorbed, the rest is
reflected (some can be transmitted too--but never mind for now)
• The reflected light is what we see
• Reflection is not simple and varies with material
– the surface’s micro structure define the details of reflection
– variations produce anything from bright specular reflection
(mirrors) to dull matte finish (chalk)
Surface
7
Phong Illumination Model
• Calculate color for arbitrary point on surface
• Basic inputs are material properties and l, n, v:
Basic Calculation
• Calculate each primary color separately
• Start with global ambient light
• Add reflections from each light source
• Clamp to [0, 1]
• Reflection decomposed into
– Ambient reflection
– Diffuse reflection
– Specular reflection
• Based on ambient, diffuse, and specular
lighting and material properties
8
Ambient Reflection
• Intensity of ambient light uniform at every point
• Ambient reflection coefficient ka, 0 w ka w 1
• May be different for every surface and r,g,b
• Determines reflected fraction of ambient light
• La = ambient component of light source
• Ambient intensity Ia = ka La
• Note: La is not a physically meaningful quantity
Diffuse Reflection
• Diffuse reflector scatters light
• Assume equally all direction
• Called Lambertian surface
• Diffuse reflection coefficient kd, 0 w kd w 1
• Angle of incoming light still critical
9
Lambert’s Law
• Intensity depends on angle of incoming light
• Recall
l = unit vector to light
n = unit surface normal
T = angle to normal
• cos T = l d n
• Id = kn (l d n) Ld
• With attenuation:
q = distance to light source,
Ld = diffuse component of light
Specular Reflection
• Specular reflection coefficient ks, 0 w ks w 1
• Shiny surfaces have high specular coefficient
• Used to model specular highlights
• Do not get mirror effect (need other techniques)
10
Shininess Coefficient
• Ls is specular component of light
• r is vector of perfect reflection of l about n
• v is vector to viewer
• I is angle between v and r
• Is = ks Ls cosD I
• D is shininess coefficient
• Compute cos I = r d v
• Requires |r| = |v| = 1
• Multiply distance term Higher D is narrower
11
Comparison of Phong model to the
rendering equation
Raytracing Example
Martin Moeck,
Siemens Lighting
12
Radiosity Example
BRDF
• Bidirectional Reflection Distribution Function
• Measure for
materials
• Isotropic vs.
anisotropic
• Mathematically
complex
13
Accurate normal vectors are important
for modeling surface reflection
Normal Vectors
• Summarize Phong
14
Normals of a Plane, Method I
• Method I: given by ax + by + cz + d = 0
• Let p0 be a known point on the plane
• Let p be an arbitrary point on the plane
• Recall: u d v = 0 iff u orthogonal v
• n d (p – p0) = nd p – nd p0 = 0
• We know that [a b c 0] Td p0 = -d (because p0
satisfies the plane equation)
• Consequently n0 must be [a b c 0]T
• Normalize to n = n0/|n0|
15
Normals of Sphere
• Implicit Equation f(x, y, z) = x2 + y2 + z2 –1 = 0
• Vector form: f(p) = p d p – 1 = 0
• Normal given by gradient vector
Angle of Reflection
• Perfect reflection: angle of incident equals
angle of reflection
• Also: l, n, and r lie in the same plane
• Assume |l| = |n| = 1, guarantee |r| = 1
Solution: D = -1 and
E = 2 (l d n)
16
Summary: Normal Vectors
• Critical for Phong model (diffuse and specular)
• Must calculate accurately (even in OpenGL)
• Pitfalls
– Not unit length
– How to set at surface boundary?
17
Physics of Light and Color
• It’s all electromagnetic (EM) radiation
– Different colors correspond to different wavelengths O
– Intensity of each wavelength specified by amplitude
– Frequency Q SO
• long wavelength is low frequency
• short wavelength is high frequency
We perceive EM
UDGLDWLRQZLWK LQWKH
400-700 nm range
Amplitude
Wavelength O
UV Visible IR
18
The Eye
The Fovea
19
Color Filters
• Rods and cones can be thought of as filters
– Cones detect red, green or blue parts of spectrum
– Rods detect average intensity across spectrum
• To get the output of a filter
– Multiply its response curve by the spectrum, integrate over all wavelengths
• A physical spectrum is a complex function of wavelength
– But what we see can be described by just 3 numbers—the color filter outputs
– How can we encode a whole function with just 3 numbers?
• A: we can’t! We can’t distinguish certain colors--metamers
G R
Amplitude
Wavelength
Color Models
• Okay, so our visual system is quite limited
• But maybe this is good news. . .
• We can avoid computing and reproducing the full color
spectrum since people only have 3 color channels
–TV would be much more complex if we perceived the
full spectrum
• transmission would require much higher bandwidths
• display would require much more complex methods
–real-time color 3D graphics is feasible
–any scheme for describing color requires only three
values
–lots of different color spaces--related by 3x3 matrix
transformations
20
Color Spaces
• There are many ways to describe color
–Spectrum
• allows any radiation (visible or invisible) to be described
• usually unnecessary and impractical
–RGB
• convenient for display (CRT uses red, green, and blue
phosphors)
• not very intuitive
–HSV
• an intuitive color space
• H is hue - what color is it? S is saturation or purity - how non-
gray is it? V is value - how bright is it?
• H is cyclic therefore it is a non-linear transformation of RGB
–CIE XYZ
• a linear transform of RGB used by color scientists
HSV
From mathworks
B G V
G
R
R
B
G H
R B S
21
Additive vs. Subtractive Color
• Working with light: additive primaries
– Red, green and blue components are added by the superposition
property of electromagnetism
– Conceptually: start with black, primaries add light
• Working with pigments: subtractive primaries
– Typical inks (CMYK): cyan, magenta, yellow, black
– Conceptually: start with white, pigments filter out light
– The pigments remove parts of the spectrum
dye color absorbs reflects
cyan red blue and green
magenta green blue and red
yellow blue red and green
black all none
• What’s Color?
– Refers to radiance or irradiance measured at 3 wavelengths
– Scene color: radiance coming off of surface (for illumination)
– Image color: irradiance (for rendering)
– These quantities have different units and should not be confused
22
Units of Light and Color
Quantity Dimension Units .
Announcements
• Written assignment #1 due Thursday
– Handin at beginning of class
• Programming assignment #2 out Thursday
23
24