SLIDE 1 Computer Graphics Course Computer Graphics Course 2006 2006
Basic Lighting and Shading Basic Lighting and Shading
Based on slides by: Based on slides by:
David Brogan David Brogan Raanan Raanan Fattal Fattal Ravi Ravi Rammamoorthi Rammamoorthi
SLIDE 2 Introduction Introduction
Remember, we know how to Remember, we know how to rasterize rasterize
– – Given a 3 Given a 3-
D triangle and a 3-
D viewpoint, we know which pixels represent the triangle know which pixels represent the triangle
But what color should those pixels be? But what color should those pixels be?
SLIDE 3 Introduction Introduction
If we If we’ ’re attempting to create a realistic re attempting to create a realistic image, we need to simulate the image, we need to simulate the lighting lighting of
the surfaces in the scene the surfaces in the scene
– – Fundamentally simulation of Fundamentally simulation of physics physics and and optics
– – As you As you’ ’ll see, we use a lot of approximations ll see, we use a lot of approximations ( (a.k.a a.k.a perceptually based hacks) to do this perceptually based hacks) to do this simulation fast enough simulation fast enough
SLIDE 4 Definitions Definitions
Illumination Illumination: the transport of energy from : the transport of energy from light sources to surfaces & points light sources to surfaces & points
– – Note: includes Note: includes direct direct and and indirect indirect illumination illumination
Images by Henrik Wann Jensen
SLIDE 5
Definitions Definitions
Irradiance Irradiance
Light falling on an object has a direction and Light falling on an object has a direction and intensity. intensity.
Radiance Radiance
Light then interacts with the object and is emitted Light then interacts with the object and is emitted with a new direction(s) and intensity. with a new direction(s) and intensity.
SLIDE 6 Definitions Definitions
Lighting Lighting: :
– – the process of computing the luminous intensity the process of computing the luminous intensity (i.e., outgoing light) at a particular 3 (i.e., outgoing light) at a particular 3-
D point, usually on a surface usually on a surface
Shading Shading: :
– – Shading does not mean calculating shadows. Shading does not mean calculating shadows. – – the process of assigning colors to pixels the process of assigning colors to pixels (why the distinction?) (why the distinction?)
SLIDE 7 Definitions Definitions
Illumination models fall into two categories Illumination models fall into two categories:
:
– – Empirical Empirical: simple formulations that approximate : simple formulations that approximate
- bserved phenomenon
- bserved phenomenon
– – Physically based Physically based: models based on the actual physics : models based on the actual physics
- f light interacting with matter
- f light interacting with matter
We mostly use empirical models in We mostly use empirical models in interactive graphics for simplicity interactive graphics for simplicity Increasingly, realistic graphics are using Increasingly, realistic graphics are using physically based models physically based models
SLIDE 8 Components of Illumination Components of Illumination
Two components of illumination: Two components of illumination: light light sources sources and and surface properties surface properties Light sources (or Light sources (or emitters emitters) )
– – Spectrum of Spectrum of emittance emittance (i.e., color of the light) (i.e., color of the light) – – Geometric attributes Geometric attributes
Position Position Direction Direction Shape Shape
– – Directional attenuation Directional attenuation – – More More… …
SLIDE 9 Components of Illumination Components of Illumination
Surface properties Surface properties
– – Reflectance spectrum (i.e., color of the surface) Reflectance spectrum (i.e., color of the surface) – – Subsurface reflectance Subsurface reflectance – – Geometric attributes Geometric attributes
Position Position Orientation Orientation Micro Micro-
structure
SLIDE 10
Simplifications for Interactive Simplifications for Interactive Graphics Graphics
– – Only Only direct direct illumination illumination from emitters to surfaces from emitters to surfaces – – Simplify geometry of emitters to trivial cases Simplify geometry of emitters to trivial cases
SLIDE 11 Linear Relationship of Light Linear Relationship of Light
Light energy is simply the sum of all the Light energy is simply the sum of all the contributions contributions Terms that can be calculated separately Terms that can be calculated separately and later added together: and later added together:
– – multiple light sources multiple light sources – – multiple interactions multiple interactions (diffuse,
(diffuse, specular specular, more later) , more later)
– – multiple colors (R multiple colors (R-
G-
B, or per wavelength)
k k
I I =∑
SLIDE 12 Ambient Light Sources Ambient Light Sources
Objects not directly lit are typically still visible Objects not directly lit are typically still visible
– – e.g., the ceiling in this room, undersides of desks e.g., the ceiling in this room, undersides of desks
This is the result of This is the result of indirect illumination indirect illumination from from emitters, bouncing off intermediate surfaces emitters, bouncing off intermediate surfaces Too expensive to calculate (in real time), so we Too expensive to calculate (in real time), so we use a hack called an use a hack called an ambient light source ambient light source
– – No spatial or directional characteristics; illuminates all No spatial or directional characteristics; illuminates all surfaces equally surfaces equally – – Amount reflected depends on surface properties Amount reflected depends on surface properties
SLIDE 13 Ambient Light Sources Ambient Light Sources
For each sampled wavelength (R, G, B), For each sampled wavelength (R, G, B), the ambient light reflected from a surface the ambient light reflected from a surface depends on depends on
– – The surface properties, The surface properties, k kambient
ambient
– – The intensity, The intensity, I Iambient
ambient, , of the ambient light source
- f the ambient light source
(constant for all points on all surfaces ) (constant for all points on all surfaces )
I Ireflected
reflected =
= k kambient
ambient I
Iambient
ambient
SLIDE 14 Ambient Light Sources Ambient Light Sources
A scene lit only with an ambient light A scene lit only with an ambient light source: source:
Light Position Not Important Viewer Position Not Important Surface Angle Not Important
SLIDE 15 Directional Light Sources Directional Light Sources
For a For a directional light source directional light source we make we make simplifying assumptions simplifying assumptions
– – Direction is constant for all surfaces in the scene Direction is constant for all surfaces in the scene – – All rays of light from the source are parallel All rays of light from the source are parallel
As if the source were infinitely far away As if the source were infinitely far away from the surfaces in the scene from the surfaces in the scene A good approximation to sunlight A good approximation to sunlight
The direction from a surface to the light source is The direction from a surface to the light source is important in lighting the surface important in lighting the surface
SLIDE 16
Point Light Sources Point Light Sources
A A point light source point light source emits light equally in emits light equally in all directions from a single point all directions from a single point The direction to the light from a point on a The direction to the light from a point on a surface thus differs for different points: surface thus differs for different points:
– – So we need to calculate a So we need to calculate a normalized vector to the light normalized vector to the light source for every point we light: source for every point we light:
p l
SLIDE 17 Point Light Sources Point Light Sources
Using an ambient and a point light source: Using an ambient and a point light source:
Light Position Important Viewer Position Important Surface Angle Important
SLIDE 18
Other Light Sources Other Light Sources
Spotlights Spotlights are point sources whose are point sources whose intensity falls off directionally. intensity falls off directionally.
– – Requires color, point Requires color, point direction, falloff direction, falloff parameters parameters – – BTW:Supported BTW:Supported by by OpenGL OpenGL
SLIDE 19 Other Light Sources Other Light Sources
Area light sources Area light sources define a 2 define a 2-
D emissive surface (usually a disc or polygon) surface (usually a disc or polygon)
– – Good example: fluorescent light panels Good example: fluorescent light panels – – Capable of generating Capable of generating soft shadows soft shadows ( (why? why? ) )
SLIDE 20 Ideal diffuse reflection Ideal diffuse reflection
– – An An ideal diffuse reflector ideal diffuse reflector, at the microscopic level, is , at the microscopic level, is a very rough surface (real a very rough surface (real-
world example: chalk) – – Because of these microscopic variations, an Because of these microscopic variations, an incoming ray of light is equally likely to be reflected incoming ray of light is equally likely to be reflected in any direction over the hemisphere: in any direction over the hemisphere: – – What does the reflected intensity depend on? What does the reflected intensity depend on?
The Physics of Reflection The Physics of Reflection
SLIDE 21 Lambert Lambert’ ’s Cosine Law s Cosine Law
Ideal diffuse surfaces reflect according to Ideal diffuse surfaces reflect according to Lambert Lambert’ ’s cosine law s cosine law: :
The energy reflected by a small portion of a surface from a The energy reflected by a small portion of a surface from a light source in a given direction is proportional to the cosine light source in a given direction is proportional to the cosine
- f the angle between that direction and the surface normal
- f the angle between that direction and the surface normal
These are often called These are often called Lambertian Lambertian surfaces surfaces
Note that the Note that the reflected reflected intensity is independent intensity is independent
viewing direction, but does depend on the direction, but does depend on the surface orientation with regard to the light source surface orientation with regard to the light source
SLIDE 22
Lambert Lambert’ ’s Law s Law
SLIDE 23 Computing Diffuse Reflection Computing Diffuse Reflection
The angle between the surface normal and The angle between the surface normal and the incoming light is the the incoming light is the angle of incidence: angle of incidence: I Idiffuse
diffuse = k
= kd
d I
Ilight
light cos
cos θ θ In practice we use vector arithmetic: In practice we use vector arithmetic: I Idiffuse
diffuse = k
= kd
d I
Ilight
light (
(n n •
l) )
n l θ
SLIDE 24 Diffuse Lighting Examples Diffuse Lighting Examples
We need only consider angles from 0 We need only consider angles from 0° ° to to 90 90° ° ( (Why? How Why? How I Idiffuse
diffuse should really look
should really look like? like?) ) A A Lambertian Lambertian sphere seen at several sphere seen at several different lighting angles: different lighting angles:
SLIDE 25 Specular Reflection Specular Reflection
Shiny surfaces exhibit Shiny surfaces exhibit specular reflection specular reflection
– – Polished metal Polished metal – – Glossy car finish Glossy car finish
A light shining on a specular surface causes a A light shining on a specular surface causes a bright spot known as a bright spot known as a specular highlight specular highlight Where these highlights appear is a function of the Where these highlights appear is a function of the viewer viewer’ ’s position, so specular reflectance is view s position, so specular reflectance is view dependent dependent
SLIDE 26 The Physics of Reflection The Physics of Reflection
At the microscopic level a specular At the microscopic level a specular reflecting surface is very smooth reflecting surface is very smooth Thus rays of light are likely to bounce off Thus rays of light are likely to bounce off the microgeometry in a mirror the microgeometry in a mirror-
like fashion The smoother the surface, the closer it The smoother the surface, the closer it becomes to a perfect mirror becomes to a perfect mirror
SLIDE 27
The Optics of Reflection The Optics of Reflection
Reflection follows Reflection follows Snell Snell’ ’s Laws: s Laws:
– – The incoming ray and reflected ray lie in a plane The incoming ray and reflected ray lie in a plane with the surface normal with the surface normal – – The angle that the reflected ray forms with the The angle that the reflected ray forms with the surface normal equals the angle formed by the surface normal equals the angle formed by the incoming ray and the surface normal: incoming ray and the surface normal:
θ(l)ight = θ(r)eflection
SLIDE 28 Non Non-
- Ideal Specular Reflectance
Ideal Specular Reflectance
Snell Snell’ ’s law applies to perfect mirror s law applies to perfect mirror-
like surfaces, but aside from mirrors (and chrome) few surfaces exhibit aside from mirrors (and chrome) few surfaces exhibit perfect perfect specularity specularity How can we capture the How can we capture the “ “softer softer” ” reflections of surface that are glossy reflections of surface that are glossy rather than mirror rather than mirror-
like? One option: model the microgeometry of the surface One option: model the microgeometry of the surface and explicitly bounce rays off of it and explicitly bounce rays off of it Or Or… …
SLIDE 29 Non Non-
- Ideal Specular Reflectance:
Ideal Specular Reflectance: An Empirical Approximation An Empirical Approximation
In general, we expect most reflected light to In general, we expect most reflected light to travel in direction predicted by Snell travel in direction predicted by Snell’ ’s Law s Law But because of microscopic surface variations, But because of microscopic surface variations, some light may be reflected in a direction slightly some light may be reflected in a direction slightly
- ff the ideal reflected ray
- ff the ideal reflected ray
As the angle from the ideal reflected ray As the angle from the ideal reflected ray increases, we expect less light to be reflected increases, we expect less light to be reflected
SLIDE 30 Non Non-
- Ideal Specular Reflectance:
Ideal Specular Reflectance: An Empirical Approximation An Empirical Approximation
An illustration of this angular falloff: An illustration of this angular falloff: How might we model this falloff? How might we model this falloff?
SLIDE 31 Phong Lighting Phong Lighting
The most common lighting model in computer The most common lighting model in computer graphics was suggested by Phong: graphics was suggested by Phong:
( )
shiny
n light s specular
I k I φ cos =
The The n nshiny
shiny term is a purely
term is a purely empirical constant that empirical constant that varies the rate of falloff varies the rate of falloff Though this model has no Though this model has no physical basis, it works physical basis, it works (sort of) in practice (sort of) in practice
v
SLIDE 32 Phong Lighting: The Phong Lighting: The n nshiny
shiny Term
Term
This diagram shows how the Phong reflectance This diagram shows how the Phong reflectance term drops off with divergence of the viewing term drops off with divergence of the viewing angle from the ideal reflected ray: angle from the ideal reflected ray: What does this term control, visually? What does this term control, visually?
Viewing angle – reflected angle
SLIDE 33 Calculating Phong Lighting Calculating Phong Lighting
The The cos cos term of Phong lighting can be computed term of Phong lighting can be computed using vector arithmetic: using vector arithmetic:
– – V V is the unit vector towards the viewer is the unit vector towards the viewer – – R R is the ideal reflectance direction is the ideal reflectance direction
An aside: we can efficiently calculate r? An aside: we can efficiently calculate r?
( )
shiny
n light s specular
r v I k I ⋅ =
( ) ( )
l n l n r − ⋅ = 2
v
SLIDE 34
Calculating The Calculating The R R Vector Vector
This is illustrated below: This is illustrated below:
( ) ( )n
l n l r ⋅ = + 2
( ) ( )
l n l n r − ⋅ = 2
SLIDE 35 Blinn Blinn-
Phong Model
Popular variation of Phong Popular variation of Phong model. model. Uses the Uses the halfway vector halfway vector, , H H. . H = L+V / | L+V | H = L+V / | L+V |
I Is
s
= = k ks
s I
Iincident
incident (
(N N· ·H H) )n
n
Faster to compute than Faster to compute than reflection vector. reflection vector. Still view Still view-
dependent since H H depends on depends on V V. .
SLIDE 36 Phong Examples Phong Examples
These spheres illustrate the Phong model These spheres illustrate the Phong model as as l l and and n nshiny
shiny are varied:
are varied:
SLIDE 37 The Phong Lighting Model The Phong Lighting Model
Let Let’ ’s combine ambient, diffuse, and specular s combine ambient, diffuse, and specular components: components: Commonly called Commonly called Phong lighting Phong lighting
– – Note: once per light Note: once per light – – Note: once per color component Note: once per color component – – Do Do k ka
a,
, k kd
d, and
, and k ks
s vary with color component?
vary with color component?
( )
( )
( )
∑
=
⋅ + ⋅ + =
lights i n i s i d i ambient a total
shiny
r v k l n k I I k I
# 1
SLIDE 38 Polygon Shading Polygon Shading
Flat (constant) shading Flat (constant) shading
– – Evaluate the shading model once per polygon, use resulting Evaluate the shading model once per polygon, use resulting color for all of its pixels. color for all of its pixels.
Gouraud Gouraud shading shading
– – Evaluate the shading model at each vertex, and linearly Evaluate the shading model at each vertex, and linearly interpolate resulting values inside the polygon interpolate resulting values inside the polygon
Phong Phong shading shading
– – Besides the Besides the Phong Phong Reflectance model Reflectance model (
(cos cosn
n),
), there is a
there is a Phong Phong Shading model. Shading model. – – Evaluate the normal at each vertex, and linearly interpolate it Evaluate the normal at each vertex, and linearly interpolate it inside the polygon. Having the interpolated normal at each point inside the polygon. Having the interpolated normal at each point inside the polygon, we can use it to calculate the shading model inside the polygon, we can use it to calculate the shading model in each point. in each point.
SLIDE 39
Gouraud Gouraud shading shading
Smooth surfaces are commonly represented as a Smooth surfaces are commonly represented as a collection of polygonal facets for the purposes of collection of polygonal facets for the purposes of interactive display. interactive display. If each facet is shaded individually, it is easy to see the If each facet is shaded individually, it is easy to see the shading discontinuities, which result in faceted shading discontinuities, which result in faceted appearance appearance
SLIDE 40
Gouraud Gouraud shading shading
To eliminate faceted appearance we can use To eliminate faceted appearance we can use Gouraud Gouraud shading (linearly interpolated shading). For the resulting shading (linearly interpolated shading). For the resulting shading to be continuous we need each vertex in the shading to be continuous we need each vertex in the polygon mesh to have the same normal for all faces polygon mesh to have the same normal for all faces incident on it. incident on it.
SLIDE 41
Gouraud Gouraud shading shading
Calculate normals on each vertex of the polygon
SLIDE 42
Gouraud Gouraud shading shading
Caculate shading model on each vertex and interpolate it along the edges.
SLIDE 43
Gouraud Gouraud shading shading
Interpolate shading model along the scanlines
SLIDE 44
Gouraud Gouraud shading shading
Result, smooth shading with slow (linear) specular effect
SLIDE 45 Phong Phong Shading Shading
Better results can be obtained by linearly Better results can be obtained by linearly interpolating the interpolating the normals normals between the vertices, between the vertices, and and recomputing recomputing the shading at every pixel: the shading at every pixel:
Gouraud shading Phong shading
SLIDE 46
Phong Phong Shading Shading
Evaluate the normals at each vertex
SLIDE 47
Phong Phong Shading Shading
Interpolate normals on the polygon’s edges
SLIDE 48
Phong Phong Shading Shading
Interpolate normals on each pixel on the scanline
SLIDE 49
Phong Phong Shading Shading
Calculate shading model on each pixel of the scanline
SLIDE 50
Phong Phong Shading Shading
Result, shows specular highlight clearly.
SLIDE 51
SLIDE 52
Comparisons Comparisons
Specular highlights are different, linear and exponential
SLIDE 53
Comparisons Comparisons
Specular highlight completely missing since it didn’t occur close enough to any of the vertices
SLIDE 54
Comparisons Comparisons
Normals estimation, should not be based only on the polygon’s plane. Neighboring polygons should be taken in to account.
SLIDE 55
Lighting Review Lighting Review
Lighting Models Lighting Models
– – Ambient Ambient
Normals don Normals don’ ’t matter t matter
– – Lambert/Diffuse Lambert/Diffuse
Angle between surface normal and light Angle between surface normal and light
– – Phong/Specular Phong/Specular
Surface normal, light, and viewpoint Surface normal, light, and viewpoint
Next Class, OpenGL Next Class, OpenGL Lighting&Shading Lighting&Shading