Lighting
•
The other side of rendering
•
Computing the light
– How much
– Which colour
arriving
– From a point in the scene
– To the eye
Lighting: relevant factors
light
eye
object
Trasmission (with rifraction)
absorption
Inner reflection
Absorption by the environment
(e.g. fog)
Sub-surface scattering
Additional light
blo
ck
er
shade
reflection
Lighting: relevant factors
Multiple reflections
(indirect Lighting)
light
Lighting: global VS local
– Only takes into account:
• Light conditions
– N. lights
– their position
– Their color
• Surface area to lite
– orientation (normal)
– Optical charcateristics
» E.g, color
– Anything else is ignored
– Multiple reflections
– shadows
– Sub-surface scattering
– refraction
– ...
Local lighting
Global lighting
Much easier
to do on our
Local lighting
light
eye
object
reflection
What can be easily accomplished
•
Local lighting:
– Light reflections on objects
• Using simplified optical properties
– wiht multiple light sources
• But simplifies: point-sized
•
Global lighting:
– Multiple reflections
• VERY simplified
– Absorption by the environment
• Simplified case (uniform fog)
– Everything else only “ad-hoc"
The 3 factors we take into account
total light
=
ambient
+
reflection
+
emission
For any factor we have the
R, G and B components.
Defined for both the
object
,
(vertex attributes)
And for each
light
used
The optical properties of the
object
,
(usually vertex attributes)
Collected together form the
"
material
"
Component
emission
•
LEDs, light bulbs...
•
Not related to the lights
– Only to the object
•
It is only an addittive Component
– costant for R, G and B
•
Note: it does not send light to nearby objects
– It isn’t Global lighting
The 3 factors we take into account
total light
=
ambient
+
reflection
+
Component
ambient
•
It models (very approximately) the light hitting
the object after multiple reflections
•
Assumption:
“a small amount of light hits any surface from
every direction"
– Even surfaces in shadow
•
Small additive
constant
Component
ambient
•
Product of:
– “
ambient
” color of the material ( R
M
G
M
B
M
)
– “
ambient
” color of the light ( R
L
G
L
B
L
)
•
Note: the RGB colors can be different
Component
ambient
•
It models (very approximately) the light hitting
the object after multiple reflections
without
The 3 factors we take into account
total light
=
ambient
+
reflection
+
emission
diffuse reflection
+
specular reflection
only
Component
The 4 factors we take into account
total light
=
ambient
+
diffuse reflection
+
specular reflection
+
Component
diffuse reflection
•
Effect shown by a few materiale (e.g.):
– chalk
– wood (almost)
– Very opaque materials(not shiny)
•
Also known as
– diffuse reflection
– Lambertian reflection
Component
diffuse reflection
The light hitting a lambertian
surface is reflected in all
directions (in the half-sphere)
Component
diffuse reflection
The light hitting a lambertian
surface is reflected in all
directions (in the half-sphere)
Component
diffuse reflection
The light hitting a lambertian
surface is reflected in all
directions (in the half-sphere)
Component
diffuse reflection
•
It only depends on:
– Surface orientation
• (the "normal")
– Light direction
Component
diffuse reflection
•
It only depends on:
– Surface orientation
N
• (the "normal")
– Light direction
L
• (Light ray)
cos
light
diff
material
diff
diff
I
k
I
R, G, B
(usually white: 1,1,1)
R, G, B
(the "color" of the object)
property of the
"material"
(associated to
the object)
Component
diffuse reflection
•
It only depends on:
– Surface orientation
N
• (the "normal")
– Light direction
L
• (Light ray)
cos
light
diff
material
diff
diff
I
k
Component
diffuse reflection
•
It only depends on:
– Surface orientation
N
• (the "normal")
– Light direction
L
• (Light ray)
cos
light
diff
material
diff
diff
I
k
Component
diffuse reflection
•
It only depends on:
– Surface orientation
N
• (the "normal")
– Light direction
L
• (Light ray)
)
Lˆ
Nˆ
(
I
light
diff
k
material
diff
Angle between
0⁰ and 90⁰
,
otherwise 0,
(object in its own shadow)
cos
light
diff
material
diff
diff
I
k
Component
diffuse reflection
L
N
Component
diffuse
small
⍬
=70⁰
L
N
Component
diffuse
large
⍬
=35⁰
L
N
Component
diffuse
largest
Component
diffuse reflection
L
N
Component
diffuse
ZERO
⍬
=90⁰
L
N
Component
diffuse
ZERO
⍬
>90⁰
Component
diffuse reflection
•
Properties
– Accurate model of the optical characteristics
of a number of real materials
– But only a small number
– The model is physically coherent
• As an example, energy is conserved
The 4 factors we take into account
total light
=
ambient
+
diffuse reflection
+
specular reflection
+
Component
specular reflection
•
"Specular" reflection
•
For shiny materials
– With bright reflections
– ("highlights")
Component
specular reflection
•
Basic idea:
light
is not
reflected
by
shiny materiale
Component
specular reflection
L: light ray
N: normal
R: reflected ray
V: view direction
N
L
R
V
Component
specular reflection
•
Phong light model
– by Bui-Tuong Phong, 1975
in 3D
cos
light
spec
material
spec
spec
I
k
Component
specular reflection
•
By using higher exponents for the cosine, we can
Component
specular reflection
•
Phong light model
– by Bui-Tuong Phong, 1975
in 3D
Belong to the "material"
(properties of the object)
n
spec
material
spec
light
spec
I
k
I
cos
cos
light
spec
material
spec
spec
I
k
Component
specular reflection
•
Phong light model
– by Bui-Tuong Phong, 1975
in 3D
cos
light
spec
material
spec
spec
I
k
I
n
spec
material
spec
light
k
R
V
I
(
ˆ
ˆ
)
n
spec
material
spec
light
spec
I
k
Component
specular reflection
1
n
n
5
n
10
n
100
Component
specular reflection
• Blinn-Phong light model:
• Simplification of the Phong light model
• Similar results, different formula:
n
spec
material
spec
light
spec
I
k
R
V
I
(
ˆ
ˆ
)
phong:
blinn-phong:
I
spec
I
light
spec
k
material
spec
(
H
ˆ
N
ˆ
)
n
N
L
R
V
Component
specular reflection
• Blinn-Phong light model:
• Simplification of the Phong light model
• Similar results, different formula:
Jim Blinn
(MEGA-MEGA-GURU)
phong:
blinn-phong:
n
spec
material
spec
light
spec
I
k
R
V
I
(
ˆ
ˆ
)
n
spec
material
spec
light
spec
I
k
H
N
The 4 factors we take into account
total light
=
ambient
+
diffuse reflection
+
specular reflection
+
Complete lighting equation
n
specular
material
specular
light
k
H
N
I
(
)
k
(
L
N
)
I
light
diffuse
material
diffuse
material
ambient
ambient
light
k
I
emission
material
k
tot
I
property of the
Lighting equation: lights modeling
emission
materiale
k
tot
I
property of the light
L
V
V
L
ˆ
ˆ
)
ˆ
ˆ
(
n
specular
material
specular
light
k
H
N
I
(
)
k
(
L
N
)
I
light
diffuse
material
diffuse
material
ambient
ambient
light
k
Lights modeling
•
How does L change ?
– constant in the scene: "
directional
" light sources
• Used for light sources very far away, e.g. the sun
– Variable in the scene: "
positional
" light sources
Lights modeling: positional lights
•
The positional lights, have their
intensity
dimmed according to the
distance
•
In theory (according to physics)
intensity = 1 / distance
2
2
L
1
d
c
Lights modeling: positional lights
•
In practice, it leads to light attenuations that are
too quick
•
We rather use:
min
1
2
,
1
L
3
L
2
1
c
d
c
d
Lighting equation
tot
I
f
light
attenuatio
n
min
1
2
,
1
L
3
L
2
1
c
d
c
d
c
f
light
attenuatio
n
n
specular
material
specular
light
k
H
N
I
(
)
k
(
L
N
)
I
light
diffuse
material
diffuse
material
ambient
Kind of lights
•
Kind of lights:
Spotlights
Lighting equation
effect
spotlight
f
direction
cutoff
Angle
beam
width
effect
spotlight
L
spot
spot
spot
f
f
,
,
,
tot
I
light
attenuatio
n
f
n
specular
material
specular
light
k
H
N
I
(
)
k
(
L
N
)
I
light
diffuse
material
diffuse
material
ambient
ambient
light
k
I
emission
material
k
min
1
2
,
1
L
3
L
2
1
c
d
c
d
Lighting: Where?
Lighting & Shading
Computer Graphics Pagina 49
y
z
v
0v
1v
2v
0v
1v
2Final pixels
The 4 factors we take into account
total light
=
ambient
+
diffuse reflection
+
specular reflection
+
Lighting equation
n
specular
material
specular
light
k
H
N
I
(
ˆ
ˆ
)
k
(
L
ˆ
N
ˆ
)
I
luight
diffuse
material
diffuse
material
ambient
ambient
light
k
I
emission
material
k
tot
I
f
light
attenuatio
n
min
1
2
,
1
L
3
L
2
1
c
d
c
d
c
f
light
attenuatio
n
effect
spotlight
f
direction
cutoff
Angle
beam
width
effect
spotlight
L
spot
spot
spot
f
f
,
,
,
properties of the light
properties of the
material
^
Normal of a triangle
•
That is its orientation in space
N
v
0
v
2
v
1
)
(
)
(
v
1
v
0
v
2
v
0
N
|
|
ˆ
Lighting face by face
"flat shading"
1.
Initial geometry
2.
For each face,
Compute the normal
3.
Definition
•
Shading
:
–
Recipe to apply
lighting
•
As an example:
flatshading
1. Apply lighting to each face normal
- (obtaining a color)
Flat shading: problem
When we approximate curved surfaces with
triangles and apply flat shading the result is:
– Edges very visible on curved surfaces
bad
artifact
!
Flat shading: problem
Flat shading: problem
•
Increasing the number
of faces, makes the
problem less visible
>10.000 faces,
and we still see
the artifact
edges
Flat shading: problem
To make things worse:
the
Mach-band optical effect
The contrast between different
uniform areas catches our eye.
(even when areas are a lot,
and their difference is small).
The brain increases the
contrast between uniform
areas.
Idea
"Gouraud" Shading
To apply the lighting, I need to have the
normal!
The normal is defined for a face, not for a
vertex
by Henri Gouraud,
1971
Idea
•
Use color interpolation within a face
1- Apply lighting to the 3 vertices of each triangle
• (obtain a color)
Vertex normals
•
In many cases, the vertex normals are defined
at the same time of the 3D model.
– As an example,
• When we model a sphere, a cylinder, a cone...
• When we compute the surface of a volume
• When we a triangulated surface sampling a parametric surface
• ...
Vertex normals
Normal of a triangle:
v
1
v
2
v
1
×
v
2
v
N
ˆ
1ˆ
N
2ˆ
N
3ˆ
N
4ˆ
N
5ˆ
N
6ˆ
N
Normal of a vertex
Shared by
n
triangles:
n
N
N
N
N
ˆ
1
ˆ
2
...
ˆ
Where do we compute lighting?
x
y
z
v
0v
1v
2v
0v
1v
2Final pixels
Fundamental decision
•
In our rendering paradigm, the (vertex) normal:
• Is NOT
computed in the pipeline
• Is introduced as an
ATTRIBUTE
of each
VERTEX
•
The normale “is in the model"
• Exactly similar to vertex position
• When necessary, the normals computation is tipically a
pre-processing
Final pixels
Gouraud shading
How to improve the result
•
Rather than interpolating the
color
after the
lighting
, we interpolate the
normal
before of the
lighting
!
•
Be careful:
interpolating two normal vectors, the result is
not always a normal:
How to improve the result
•
Rather than interpolating the
color
after the
lighting
, we interpolate the
normal
before of the
lighting
!
"Phong" Shading
by Bui-Tuong Phong ,
1973
1- Interpolate the normal in the face
2- Normalize
3- Compute lighting
* Do not confuse Phong Shading with the Phong Lighting Model
Final pixels
(filling of the screen-buffer)