Lighting

advertisement
LIGHTING
JEFF CHASTINE
1
WHAT IS LIGHT?
•
A very complex process
• Find a dark area – how is it being lit?
• Light bounces (mirrors, shiny objects)
• Light refracts through other media (water, heat)
• Light comes from everywhere (Global Illumination)
• Light bounces off of lakes in weird ways (Fresnel effect)
•
http://en.wikipedia.org/wiki/File:Global_illumination.JPG
THUS
• We’re forced to make approximations
• Tradeoff between time and realism
• “If it looks good, it is good” – Michael Abrash
JEFF CHASTINE
http://darrentakenaga.com/3d.html
A BASIC LIGHTING CONCEPT
•
How can we determine how much light should be cast onto a triangle from a directional
light?
P0
Directional light
- position doesn’t matter
- triangle is almost fully lit
š‘
P1
P2
JEFF CHASTINE
3
A BASIC LIGHTING CONCEPT
•
How can we determine how much light should be cast onto a triangle from a directional
light?
P0
š‘
(Triangle less lit)
P1
P2
JEFF CHASTINE
4
A BASIC LIGHTING CONCEPT
•
How can we determine how much light should be cast onto a triangle from a directional
light?
P0
š‘
P1
P2
JEFF CHASTINE
(Little to no light hits the surface)
5
A BASIC LIGHTING CONCEPT
•
How can we determine how much light should be cast onto a triangle from a directional
light?
P0
š‘
(Directional light)
P1
P2
JEFF CHASTINE
6
A BASIC LIGHTING CONCEPT
•
How can we determine how much light should be cast onto a triangle from a directional
light?
P0
š‘
šæ
(Directional light)
P1
P2
JEFF CHASTINE
7
A BASIC LIGHTING CONCEPT
•
How can we determine how much light should be cast onto a triangle from a directional
light?
Lesson learned: Lighting depends on angles between vectors!
P0
š‘
šæ
(Directional light)
P1
P2
JEFF CHASTINE
8
A BASIC LIGHTING CONCEPT
•
How can we determine how much light should be cast onto a triangle from a directional
light?
intensity = acos(š‘ āˆ™ šæ)
P0
š‘
šæ
(Directional light)
P1
P2
JEFF CHASTINE
Assuming N and L are normalized, and Nāˆ™L isn’t negative
9
BASIC LIGHTING
•
Four independent components:
• Diffuse – the way light “falls off” of an object
• Specular – the “shininess” of the object
• Ambient – a minimum amount of light used to simulate “global illumination”
• Emit – a “glowing” effect
Only diffuse
JEFF CHASTINE
10
BASIC LIGHTING
•
Four independent components:
• Diffuse – the way light “falls off” of an object
• Specular – the “shininess” of the object
• Ambient – a minimum amount of light used to simulate “global illumination”
• Emit – a “glowing” effect
Diffuse+Specular
JEFF CHASTINE
11
BASIC LIGHTING
•
Four independent components:
• Diffuse – the way light “falls off” of an object
• Specular – the “shininess” of the object
• Ambient – a minimum amount of light used to simulate “global illumination”
• Emit – a “glowing” effect
Diffuse+Specular+Ambient
Ambient
JEFF CHASTINE
12
BASIC LIGHTING
•
Four independent components:
• Diffuse – the way light “falls off” of an object
• Specular – the “shininess” of the object
• Ambient – a minimum amount of light used to simulate “global illumination”
• Emit – a “glowing” effect
D+S+A+Emit
JEFF CHASTINE
Note: emit does not produce light!
13
INTERACTION BETWEEN MATERIAL AND LIGHTS
•
Final color of an object is comprised of many things:
• The base object color (called a “material”)
• The light color
• Example: a purple light on a white surface
• Any textures we apply (later)
•
Materials and lights have four individual components
• Diffuse color (cd and ld)
• Specular color (cs and ls)
• Ambient color (ca and la)
• Emit color (ce and le)
• cd * ld = [cd.r*ld.r , cd.g*ld.g , cd.b*ld.b] // R, G, B
JEFF CHASTINE
14
GENERAL LIGHTING
•
Primary vectors
• l – the incoming light vector
• n – the normal of the plane/vertex
• r – the reflection vector
• v – the viewpoint (camera)
v
n
l
r
θ
JEFF CHASTINE
θ
15
LAMBERTIAN REFLECTANCE
(DIFFUSE COMPONENT)
•
Light falling on an object is the same regardless of the observer’s viewpoint
•
Good for rough surfaces without specular highlights
•
š‘“š‘–š‘›š‘Žš‘™_š‘š‘œš‘™š‘œš‘Ÿš‘‘š‘–š‘“š‘“š‘¢š‘ š‘’ = š‘› āˆ™ š‘™ ∗ š‘š‘‘ ∗ š‘™š‘‘ where š‘› and š‘™ are normalized
n
l
θ
JEFF CHASTINE
16
LAMBERTIAN REFLECTANCE
(DIFFUSE COMPONENT)
•
Light falling on an object is the same regardless of the observer’s viewpoint
•
Good for rough surfaces without specular highlights
•
š‘“š‘–š‘›š‘Žš‘™_š‘š‘œš‘™š‘œš‘Ÿš‘‘š‘–š‘“š‘“š‘¢š‘ š‘’ = š‘› āˆ™ š‘™ ∗ š‘š‘‘ ∗ š‘™š‘‘ where š‘› and š‘™ are normalized
3 parts (R, G, B)
scalar
n
l
θ
Note: final_colordiffuse has R, G, B
JEFF CHASTINE
17
LAMBERTIAN REFLECTANCE
(DIFFUSE COMPONENT)
•
Technically, it should be:
š‘“š‘–š‘›š‘Žš‘™_š‘š‘œš‘™š‘œš‘Ÿš‘‘š‘–š‘“š‘“š‘¢š‘ š‘’ = max(š‘› āˆ™ š‘™, 0) ∗ š‘š‘‘ ∗ š‘™š‘‘
n
l
θ
JEFF CHASTINE
18
BLINN-PHONG REFLECTION
(SPECULAR COMPONENT)
•
Describes the specular highlight and is dependent on viewpoint v
•
Also describes a “half-vector” h that is halfway between v and l
h
v
n
r
l
θ
JEFF CHASTINE
θ
19
BLINN-PHONG REFLECTION
(SPECULAR COMPONENT)
•
ā„Ž = š‘£ + š‘™ - which is really Blinn’s contribution to the original Phong model
h
v
n
r
l
θ
θ
Note: vectors should be normalized
JEFF CHASTINE
20
BLINN-PHONG REFLECTION
(SPECULAR COMPONENT)
•
Our final specular equation is:
š‘“š‘–š‘›š‘Žš‘™_š‘š‘œš‘™š‘œš‘Ÿš‘  = (š‘› āˆ™ ā„Ž) š‘  ∗ š‘š‘  ∗ š‘™š‘ 
h
v
n
r
l
θ
JEFF CHASTINE
θ
21
DETERMINING š‘ 
š‘“š‘–š‘›š‘Žš‘™_š‘š‘œš‘™š‘œš‘Ÿš‘  = (š‘› āˆ™ ā„Ž)š‘  ∗ š‘š‘  ∗ š‘™š‘ 
•
Realize that š‘› āˆ™ ā„Ž will always be < 1.0, so raising it to a power will make it smaller
•
š‘  is the “shininess” factor
• It relates to the size of the specular highlight
s = ~1
JEFF CHASTINE
s = ~30
s = ~255
22
AMBIENT AND EMIT COMPONENTS
•
Ambient:
• Used to simulate light bouncing around the environment (global illumination)
• Real world is far too complex for real time, so just add a little light!
•
Emit:
• Used to make the object “glow”
• Does not emit light!!!
•
Both:
• Independent of viewpoint
• Super easy to calculate
š‘“š‘–š‘›š‘Žš‘™_š‘š‘œš‘™š‘œš‘Ÿš‘Žš‘šš‘š‘–š‘’š‘›š‘” = š‘™š‘Ž + š‘š‘Ž
š‘“š‘–š‘›š‘Žš‘™_š‘š‘œš‘™š‘œš‘Ÿš‘’š‘šš‘–š‘” = š‘™š‘’ + š‘š‘’
JEFF CHASTINE
23
FINAL COLOR
•
To determine the final color (excluding textures) we sum up all components:
+
final_colordiffuse
final_colorspecular
final_colorambient
final_coloremit
final_color
http://en.wikipedia.org/wiki/Phong_reflection_model
JEFF CHASTINE
24
WHAT ABOUT MULTIPLE LIGHTS?
•
Calculate final colors and sum them all together
•
Assuming results are in f [ ] and there are count number of lights
š‘š‘œš‘¢š‘›š‘”
š‘“š‘–š‘›š‘Žš‘™_š‘š‘œš‘™š‘œš‘Ÿ =
(š‘“ š‘– š‘‘ , š‘“ š‘– š‘  , š‘“ š‘– š‘Ž , š‘“[š‘–]š‘’ )
š‘–=1
JEFF CHASTINE
25
COMMON KINDS OF LIGHTS
•
Point light
•
Directional Light
•
Spot Light
•
Area Light
•
Interesting fact:
• Lights cannot be seen!
• Only their effects
• We can light per vertex (fast) or per fragment (slower)
JEFF CHASTINE
26
POINT LIGHTS
•
These lights have a position in 3D space
•
Sometimes called a “Lamp”
•
Light emanates from the light in all directions
•
Distance d determines brightness (“attenuation”):
š‘–š‘›š‘”š‘’š‘›š‘ š‘–š‘”š‘¦ = 1/š‘‘ 2
JEFF CHASTINE
Here, per fragment lighting used
27
POINT LIGHTS
•
These lights have a position in 3D space
•
Sometimes called a “Lamp”
•
Light emanates from the light in all directions
•
Distance d determines brightness (“attenuation”):
š‘–š‘›š‘”š‘’š‘›š‘ š‘–š‘”š‘¦ = 1/š‘‘ 2
JEFF CHASTINE
Here, per vertex lighting used
28
DIRECTIONAL LIGHTS
•
Are infinitely far away
• position in NO WAY matters
• Have only direction
•
All objects are lit evenly
•
Sometimes called a “Sun”
JEFF CHASTINE
29
SPOTLIGHTS
•
Point light source
•
Conical in shape
JEFF CHASTINE
30
SPOTLIGHTS
•
Point light source
•
Conical in shape
•
Have:
• An inner and outer cone angle
• Umbra – areas that are fully in shadow
• Penumbra – areas that are in partial shadow
•
Note: There’s an ambient light
JEFF CHASTINE
31
AREA LIGHTS
•
A “surface” lights objects
•
Has a position and direction
•
Provides for a smoother drop off than point
• Larger surface == smoother shadows
•
Expensive to calculate
JEFF CHASTINE
32
THE END!
What you’ll see if you don’t glEnable(GL_LIGHTING)
Download