06 lighting
TRANSCRIPT
-
8/6/2019 06 Lighting
1/58
Lighting
Aaron Bloomfield
CS 445: Introduction to Graphics
Fall 2006
-
8/6/2019 06 Lighting
2/58
2
Lighting Sogiven a 3-D triangle and a 3-D viewpoint,
we can set the right pixels
But what color should those pixels be?
If were attempting to create a realistic image, we
need to simulate the lighting of the surfaces inthe scene
Fundamentally simulation of physicsand optics
As youll see, we use a lot of approximations (a.k.ahacks) to do this simulation fast enough
-
8/6/2019 06 Lighting
3/58
3
Definitions Illumination: the transport of energy (in particular,
the luminous flux of visible light) from light sourcesto surfaces & points
Note: includes directand indirect illumination
Lighting: the process of computing the luminousintensity (i.e., outgoing light) at a particular 3-D
point, usually on a surface
Shading: the process of assigning colors to pixels
-
8/6/2019 06 Lighting
4/58
4
Definitions Illumination models fall into two categories:
Empirical: simple formulations that approximateobserved phenomenon
Physically-based: models based on the actual physicsof light interacting with matter
We mostly use empirical models in interactivegraphics for simplicity
Increasingly, realistic graphics are using
physically-based models
-
8/6/2019 06 Lighting
5/58
5
Components of Illumination Two components of illumination: light sources and
surface properties
Light sources (or emitters)
Brightness
Spectrum of emittance (i.e, color of the light) Geometric attributes
Position
Direction
Shape
Directional attenuation
-
8/6/2019 06 Lighting
6/58
6
Components of Illumination Surface properties
Reflectance spectrum (i.e., color of the surface)
Geometric attributes
Position
Orientation
Micro-structure
Common simplifications in interactive graphics
Only direct illuminationfrom emitters to surfaces
Simplify geometry of emitters to trivial case
-
8/6/2019 06 Lighting
7/58
7
Types of lights and light sources Ambient
Diffuse Directional
Point
Area Spot
Specular
Phong
and then onto shading
-
8/6/2019 06 Lighting
8/58
8
Ambient Light Sources Objects not directly lit are typically still visible
E.g., the ceiling in this room, undersides of desks
This is the result of indirect illumination fromemitters, bouncing off intermediate surfaces
Too expensive to calculate (in real time), so weuse a hack called an ambient light source
No spatial or directional characteristics; illuminates allsurfaces equally
Amount reflected depends on surface properties
-
8/6/2019 06 Lighting
9/58
9
Ambient Light Sources For each sampled wavelength, the ambient light
reflected from a surface depends on
The surface properties
The intensity of the ambient light source (constant for allpoints on all surfaces )
Ireflected= kambientIambient
-
8/6/2019 06 Lighting
10/58
10
Ambient Light Sources A scene lit only with an ambient light source:
-
8/6/2019 06 Lighting
11/58
11
Types of lights and light sources Ambient
Diffuse Directional
Point
Area Spot
Specular
Phong
and then onto shading
-
8/6/2019 06 Lighting
12/58
12
Diffuse lighting types There are a number of diffuse lighting models
Minnaert
Toon
Oren-Nayar
Lambert
Etc.
Well belooking onlyat Lambert
-
8/6/2019 06 Lighting
13/58
13
-
8/6/2019 06 Lighting
14/58
14
The Physics of Reflection Ideal diffuse reflection
An ideal diffuse reflector, at the microscopic level, isa very rough surface (real-world example: chalk)
Because of these microscopic variations, anincoming ray of light is equally likely to be reflected
in any direction over the hemisphere:
What does the reflected intensity depend on?
-
8/6/2019 06 Lighting
15/58
15
Lamberts Cosine Law Ideal diffuse surfaces reflect according to
Lamberts cosine law:
The energy reflected by a small portion of a surface froma light source in a given direction is proportional to thecosine of the angle between that direction and the
surface normal These are often called Lambertian surfaces
Note that the reflected intensity is independent of
the viewing direction, but does depend on thesurface orientation with regard to the light source
-
8/6/2019 06 Lighting
16/58
16
Lamberts Law
-
8/6/2019 06 Lighting
17/58
17
Computing Diffuse Reflection The angle between the surface normal and the
incoming light is the angle of incidence:
Idiffuse= kd Ilightcos
In practice we use vector arithmetic:
Idiffuse= kd Ilight (n l)
nl
-
8/6/2019 06 Lighting
18/58
18
Diffuse Lighting Examples We need only consider angles from 0 to 90
(Why?)
A Lambertian sphere seen at several differentlighting angles:
An animated gif
-
8/6/2019 06 Lighting
19/58
19
Types of lights and light sources Ambient
Diffuse Directional
Point
Area Spot
Specular
Phong
and then onto shading
-
8/6/2019 06 Lighting
20/58
20
Directional Light Sources For a directional light source we make the
simplifying assumption that all rays of light fromthe source are parallel
As if the source is infinitely far awayfrom the surfaces in the scene
A good approximation to sunlight
The direction from a surface to the light source isimportant in lighting the surface
With a directional light source, this direction isconstant for all surfaces in the scene
-
8/6/2019 06 Lighting
21/58
21
Directional Light Sources The same scene lit with a directional light source
-
8/6/2019 06 Lighting
22/58
22
Types of lights and light sources Ambient
Diffuse Directional
Point
Area Spot
Specular
Phong
and then onto shading
-
8/6/2019 06 Lighting
23/58
23
Point Light Sources A point light source emits light equally in all
directions from a single point
The direction to the light from a point on a surfacethus differs for different points:
So we need to calculate anormalized vector to the lightsource for every point we light:
lplpd
=
-
8/6/2019 06 Lighting
24/58
24
Point Light Sources Using an ambient and a point light source:
How can we tellthe differencebetween a point
light source anda directionallight source ona sphere?
-
8/6/2019 06 Lighting
25/58
25
Point light vs. directional light
-
8/6/2019 06 Lighting
26/58
26
Types of lights and light sources Ambient
Diffuse
Directional
Point
Area Spot
Specular
Phong
and then onto shading
-
8/6/2019 06 Lighting
27/58
27
Area light sources Area light sourcesdefine a 2-D emissive surface (usually a
disc or polygon)
Good example: fluorescent light panels Capable of generating soft shadows(why?)
From http://web.cs.wpi.edu/~emmanuel/courses/cs563/write_ups/zackw/realistic_raytracing.html
-
8/6/2019 06 Lighting
28/58
28
Types of lights and light sources Ambient
Diffuse
Directional
Point
Area Spot
Specular
Phong
and then onto shading
-
8/6/2019 06 Lighting
29/58
29
Spot lights Spotlights are point sources whose intensity falls off
directionally.
Spotlight isjust in frontof the camera
Supported byOpenGL
-
8/6/2019 06 Lighting
30/58
30
Types of lights and light sources Ambient
Diffuse
Directional
Point
Area Spot
Specular
Phong
and then onto shading
-
8/6/2019 06 Lighting
31/58
31
Specular lighting types There are a number of specular lighting models
WardIso
Toon
Blinn
Phong
CookTorr
Etc.
Well be
looking onlyat Phong
-
8/6/2019 06 Lighting
32/58
32
-
8/6/2019 06 Lighting
33/58
33
Specular Reflection Shiny surfaces exhibit specular reflection
Polished metal
Glossy car finish
A light shining on a specular surface causes abright spot known as a specular highlight
Where these highlights appear is a function of theviewers position, so specular reflectance is view-dependent
-
8/6/2019 06 Lighting
34/58
34
The Physics of Reflection
At the microscopic level a specular reflectingsurface is very smooth
Thus rays of light are likely to bounce off themicro-geometry in a mirror-like fashion
The smoother the surface, the closer it becomes toa perfect mirror
Polishing metal example (draw it)
-
8/6/2019 06 Lighting
35/58
35
The Optics of Reflection
Reflection follows Snells Laws:
The incoming ray and reflected ray lie in a plane with the
surface normal
The angle that the reflected ray forms with the surfacenormal equals the angle formed by the incoming ray and
the surface normal:
l=
r
-
8/6/2019 06 Lighting
36/58
36
Non-Ideal Specular Reflectance
Snells law applies to perfect mirror-likesurfaces, but aside from mirrors (and chrome)
few surfaces exhibit perfect specularity
How can we capture the softer reflections of
surface that are glossy rather than mirror-like?
One option: model the micro-geometry of thesurface and explicitly bounce rays off of it
Or
-
8/6/2019 06 Lighting
37/58
37
Types of lights and light sources
Ambient
Diffuse
Directional
Point
Area Spot
Specular
Phong
and then onto shading
-
8/6/2019 06 Lighting
38/58
38
An Empirical Approximation
In general, we expect most reflected light to travelin direction predicted by Snells Law
But because of microscopic surface variations,some light may be reflected in a direction slightly
off the ideal reflected ray
As the angle from the ideal reflected ray increases,we expect less light to be reflected
-
8/6/2019 06 Lighting
39/58
39
An Empirical Approximation
An illustration of this angular falloff:
How might we model this falloff?
-
8/6/2019 06 Lighting
40/58
40
Phong Lighting
The most common lighting model in computergraphics was suggested by Phong:
( ) shinynlightsspecular IkI = cos
The nshiny term is a purelyempirical constant thatvaries the rate of falloff
Though this model has nophysical basis, it works(sort of) in practice
-
8/6/2019 06 Lighting
41/58
41
Phong Lighting: The nshiny
Term
This diagram shows how the Phong reflectanceterm drops off with divergence of the viewing angle
from the ideal reflected ray:
What does this term control, visually?
-
8/6/2019 06 Lighting
42/58
42
Calculating Phong Lighting
The cos term of Phong lighting can be computedusing vector arithmetic:
Vis the unit vector towards the viewer
Common simplification: Vis constant (implying what?)
Ris the ideal reflectance direction
An aside: we can efficiently calculate R
( ) shinynlightsspecular RVIkI =
LNLNR 2 =
-
8/6/2019 06 Lighting
43/58
43
Calculating TheR Vector
This is illustrated below:
LNLNR 2 =
NLNLR 2 =+
-
8/6/2019 06 Lighting
44/58
44
Phong Examples
These spheres illustrate the Phong model as L andnshinyare varied:
-
8/6/2019 06 Lighting
45/58
45
The Phong Lighting Model
Our final empirically-motivated model for theillumination at a surface includes ambient, diffuse,
and specular components:
Commonly called Phong lighting
Note: once per light Note: once per color component
Do ka, kd, and ksvary with color component?
( ) ( )=
++=lights
i
n
sdiambientatotal
shiny
RVkLNkIIkI#
1
-
8/6/2019 06 Lighting
46/58
46
Phong Lighting: Intensity Plots
-
8/6/2019 06 Lighting
47/58
47
Phong Lighting in OpenGL
The final Phong model as we studied it:
OpenGL variations: Every light has an ambient component
Surfaces can have emissive component to simulateglow Added directly to the visible reflected intensity
Not actually a light source (does not illuminate other surfaces)
See Nate Robins OpenGL Lighting tutors
( ) ( )=
++=
lights
i
n
sdiambientatotal
shiny
RVkLNkIIkI
#
1
( ) ( )#
1
shiny
lights n
total e a a d d s s
i
I k I k I k N L I k V R=
= + + + +
-
8/6/2019 06 Lighting
48/58
48
Types of lights and light sources
Ambient
Diffuse
Directional
Point
Area Spot
Specular
Phong
and then onto shading
-
8/6/2019 06 Lighting
49/58
49
Applying Illumination
We now have an illumination model for a point ona surface
Assuming that our surface is defined as a mesh ofpolygonal facets, which points should we use?
Keep in mind:
Its a fairly expensive calculation
Several possible answers, each with differentimplications for the visual quality of the result
-
8/6/2019 06 Lighting
50/58
50
Applying Illumination
With polygonal/triangular models:
Each facet has a constant surface normal
If the light is directional, the diffuse reflectance isconstant across the facet
If the eyepoint is infinitely far away (constant V), the
specular reflectance of a directional light is constantacross the facet
-
8/6/2019 06 Lighting
51/58
51
Flat Shading
The simplest approach, flat shading, calculatesillumination at a single point for each polygon:
If an object really is faceted, is this accurate?
No:
For point sources, the direction to light variesacross the facet
For specular reflectance, direction to eye variesacross the facet
-
8/6/2019 06 Lighting
52/58
52
Flat Shading
We can refine it a bit by evaluating the Phonglighting model at each pixel of each polygon, but
the result is still clearly faceted: To get smoother-looking surfaces
we introduce vertex normalsat each
vertex Usually different from facet normal
Used onlyfor shading (as opposed to what?)
Think of as a better approximation of the real surfacethat the polygons approximate (draw it)
V N l
-
8/6/2019 06 Lighting
53/58
53
Vertex Normals
Vertex normals may be
Provided with the model
Computed from first principles
Approximated by averaging the normals of the facetsthat share the vertex
F l i Bl d
-
8/6/2019 06 Lighting
54/58
54
Face normals in Blender
G d Sh di
-
8/6/2019 06 Lighting
55/58
55
Gouraud Shading
This is the most common approach
Perform Phong lighting at the vertices
Linearly interpolate the resulting colors over faces
This is what OpenGL does
Demo at:
http://www.cs.virginia.edu/~gfx/Courses/2000/intro.spring00.html/vrml/tpot.wrl
Requires a VRML browser or plug-in
Does this eliminate the facets? No: were still subsamplingthe lighting parameters
(normal, view vector, light vector)
Ph Sh di
-
8/6/2019 06 Lighting
56/58
56
Phong Shading
Phong shadingis not the same as Phong lighting,though they are sometimes mixed up
Phong lighting: the empirical model weve beendiscussing to calculate illumination at a point on asurface
Phong shading: linearly interpolating the surface normalacross the facet, applying the Phong lighting model atevery pixel
Same input as Gouraud shading
Usually very smooth-looking results: But, considerably more expensive
A A id T f i N l
-
8/6/2019 06 Lighting
57/58
57
An Aside: Transforming Normals
Irritatingly, the matrix for transforming a normalvector is not the same as the matrix for the
corresponding transformation on points In other words, dont just treat normals as points:
Transforming Normals
-
8/6/2019 06 Lighting
58/58
58
Transforming Normals
Some not-too-complicated affine analysis shows:
If A is a matrix for transforming points, then (AT)-1 is the
matrix for transforming normals
When is this the same matrix?
What is the homogeneous representation of a
vector (as opposed to a point?)
Can use this to simplify the problem: only upper3x3 matrix matters, so use only it