Download Lighting - FarinHansford.com

Document related concepts

Color temperature wikipedia , lookup

Color wikipedia , lookup

Holiday lighting technology wikipedia , lookup

Gravitational lens wikipedia , lookup

Photoelectric effect wikipedia , lookup

Grow light wikipedia , lookup

Light pollution wikipedia , lookup

Bicycle lighting wikipedia , lookup

Doctor Light (Kimiyo Hoshi) wikipedia , lookup

Bioluminescence wikipedia , lookup

Doctor Light (Arthur Light) wikipedia , lookup

Lighting wikipedia , lookup

Daylighting wikipedia , lookup

Architectural lighting design wikipedia , lookup

Photopolymer wikipedia , lookup

Transcript
Illumination
Lighting
and Shading
CSE 470/598
Introduction to Computer Graphics
Arizona State University
Terminology
• Illumination:
1. luminous flux at any point on a surface
exposed to incident light (direct or indirect)
2. A light source
3. Spiritual or intellectual enlightenment
Terminology
• Illumination:
1. luminous flux at any point on a surface exposed to incident light
(direct or indirect)
2. A light source
3. Spiritual or intellectual enlightenment
• Lighting:
1. Method to provide artificial illumination
2. Illumination
3. The act of igniting
Terminology
• Illumination:
1. luminous flux at any point on a surface exposed to incident
light (direct or indirect)
2. A light source
3. Spiritual or intellectual enlightenment
• Lighting:
1. Method to provide artificial illumination
2. Illumination
3. The act of igniting
• Shading:
1. produce gradations of light or color
2. process of assigning colors to pixels
Terminology
• Illumination:
1. luminous flux at any point on a surface exposed to
incident light (direct or indirect)
2. A light source
• Lighting:
1. The method used to provide artificial illumination
2. Illumination
• Shading:
1. produce gradations of light or color
2. process of assigning colors to pixels
But you’ll hear them interchanged frequently!
Lighting Overview
•
•
•
•
CG lighting models
Elements of a lighting model
The Phong illumination model
Application of the Phong model
Shading methods: flat, Gouraud, Phong
• OpenGL aspects
CG Lighting Models: Global
Multiple interaction
of light & objects
Not real-time (yet)
Examples:
Raytracing, radiosity,
photon mapping …
From:
http://jedi.ks.uiuc.edu/~johns/raytracer/rayga
llery/stills.html
CG Lighting Models: Local
Single interaction
of light & objects
Real-time
Supported by OGL
Example:
Phong illumination
model
Elements of a Lighting Model:
• light sources:
number, type (desk lamp vs sun), color
Elements of a Lighting Model:
• light sources:
number, type, color
• reflections
Elements of a Lighting Model:
• light sources:
number, type, color
• reflections
• material properties:
reflection & absorption of light
Elements of a Lighting Model:
• light sources:
number, type, color
• reflections
• material properties:
reflection & absorption
of light
3D feel,
depth perception
lighting model == approximation of real-world lighting!
Elements of the Phong Model
Light Source Properties
All calculations
based on idea that
RGB calculated
independently
Elements of the Phong Model
Light Source Properties
1. ambient light
>
>
>
>
scattered
no detectable direction
backlighting in a room
can use to give a feel for the main
color in a room
> not dependent on viewpoint
Elements of the Phong Model
Light Source Properties
1. ambient light
2. diffuse light
>
>
>
>
directional
scatters equally in all directions once hits object
closest to the color of light
not dependent on eye position
Elements of the Phong Model
Light Source Properties
1. ambient light
2. diffuse light
3. specular light
>
>
>
>
comes from a detectable direction
bounces off object in preferred direction
plays a role in shininess
dependent on viewpoint
diffuse and specular normally set the same
Elements of the Phong Model
Light Source Properties
1.
2.
3.
4.
ambient light
diffuse light
specular light
point source vs spotlight
> point source: light emitted in all directions
> spotlight: cone-shaped
Elements of the Phong Model
Light Source Properties
1.
2.
3.
4.
5.
ambient light
diffuse light
specular light
point source vs spotlight
positional vs directional
> positional: like a desk lamp
> directional: like the sun
all rays parallel when reach object
> homogeneous coordinate to distinguish
> location transformed by modelview matrix
x
y
z
w
Elements of the Phong Model
Material properties
Elements of the Phong Model
Material properties
1. reflectance of light
a. ambient
> amount of ambient light
> most visible where no direct light hits
Elements of the Phong Model
Material properties
1. reflectance of light
a. ambient
b. diffuse
> degree of scattering of light on surface
> matte vs flat paint finish
Color of object == ambient and diffuse
(typically set the same)
Elements of the Phong Model
Material properties
1. reflectance of light
a. ambient
b. diffuse
c. specular
> degree of mirror-like quality
> typically set to white so highlights
produced are color of light
Elements of the Phong Model
Material properties
1. reflectance of light
a. ambient
b. diffuse
c. specular
d. translucent (opaque)
Elements of the Phong Model
Material properties
1. reflectance of light
a. ambient
b. diffuse
c. specular
d. translucent (opaque)
2. surface normals (unit length!)
Elements of the Phong Model
Material properties
1. reflectance of light
a. ambient
b. diffuse
c. specular
d. translucent (opaque)
2. surface normals
3. emissive color
Light & Material Properties
Examples
increasing diffuse
increasing ambient
increasing specular
Light & Material Properties
absorption/reflectance influence on color
Example:
red box will reflect red light
absorb green and blue light
Notation: Light Properties
Model is computed independently for
red, green, blue components
Light’s luminance
represented by boldface vectors:
La =
r
g
b
:= ambient
0 <= r,g,b <= 1
Ld := diffuse
Ls := specular
 % of full intensity
Notation: Material Properties
Material’s properties represented by boldface vectors:
ka := ambient
kd := diffuse
ks := specular
Each vector takes form
r
g
b
0 <= r,g,b <= 1
Represents % of reflection of light source’s
corresponding property
Notation: Material Properties
Example material properties:
Geometry of the Phong Model
v
p
l
n
r
v
theta
phi
point on surface
(light – p) vector
normal to surface
reflection vector
(viewpoint – p) vector
angle of incidence
angle between v and r
All vectors normalized
p
Recall: angle of incidence
equals angle of reflection
Phong Model in OGL
vertex color =
material emission‡
+ (global ambient light scaled by material
ambient property)
+ (ambient, diffuse, specular of lights,
attenuated by material properties, viewer
location and light position) for all lights
‡ at vertex
Diffuse Intensity Calculation
Lambert’s
Law:
light reflected is proportional to the
cosine of the angle (theta) between
surface normal n and light vector l
theta is called the angle of incidence
Diffuse Intensity Calculation
Lambert’s
Law:
light reflected is proportional to the
cosine of the angle (theta) between
surface normal n and light vector l
theta is called the angle of incidence
theta=0
theta=60
Diffuse Intensity Calculation
Id := intensity of reflected diffuse light
Id = kd x Ld x cos(theta)
cos(theta) = l • n
theta in [-90,90°] are of interest
Id = kd x Ld x (max{l • n, 0})
Note: independent of viewer
“x” is not cross product
3 separate scalar products
Specular Intensity Calculation
Is := intensity of reflected specular light
Basic idea: Is = ks x Ls x cos^s(phi)
cos(phi) = v • r
r = [2(l•n)]n - l
phi = 0°  full specular
|phi| > 90°  no specular
(never compute angle directly)
Focus of specular influenced by s
Note: depends on viewpoint
Specular Intensity Calculation
s: Phong constant or “shininess” coefficient
cos^s(phi)
s=1
s=10
focus
- 90°
s=0.1
spread
90°
Specular Intensity Calculation
Blinn-Torrence modification –
simplification for faster computation
h = (l + v) / || l + v ||
“halfway” vector
cos(alpha) = h • n
alpha ~ ½ phi
so good approximation
Specular Intensity Calculation
Blinn-Torrence specular is implemented in OGL
Is = ks x Ls x [max{h • n, 0}]^s
if l • n < 0 then Is = 0
(no diffuse, no specular)
Attenuation Function
For a positional light ...
d := distance of light source to vertex
ogl choices for functions
f(d) = 1/a
f(d) = 1/(a + b*d)
f(d) = 1/(a + b*d + c*d^2)
constant
linear
quadratic
inverse distance functions  diminish intensity d increases
for directional light, f(d) = 1
Spotlight Effect
Cone-shaped spotlight
defined by:
c
position
gamma “cut-off” angle
d
direction
c
gamma
d
sp := spotlight effect for a light source
defined by angle between -l and d : cos(delta) = -l • d
if delta > gamma sp = 0
else sp = (max{-l • d, 0})^p
p influence similar to
Phong constant;
focus of intensity
Recall:
Phong Model in OGL
vertex color =
material emission‡
+ (global ambient light scaled by material
ambient property)
+ (ambient, diffuse, specular of lights,
attenuated by material properties, viewer
location and light position) for all lights
‡ at vertex
Putting It All Together
Phong Model in OGL
I := intensity at a vertex
e := emission intensity at a vertex
Ma := ambient intensity for the entire model
I = e + (ka x Ma)
+ for each light { [f(d) * spot * (Ia + Id + Is)] }
Remember: boldface indicates r,g,b values
Shading Methods
Phong model  color of vertex
Shading methods  color of triangle
Methods:
1. Flat shading
2. Gouraud (smooth) shading
3. Phong‡ Shading
Recall: triangle normal .vs.
averaged vertex normal
in ogl
‡ confusing, but different from
Phong illumination model
Flat Shading
One normal per triangle
Simulates viewer and light source distant
then v, n, l same over triangle
 one shading calculation
glShadeModel(GL_FLAT)
Gouraud (smooth) Shading
One normal per vertex
Lighting calculation made at each vertex  I1, I2, I3
Lighting at any point p within triangle v1, v2, v3
I = b1*I1 + b2*I2 + b3* I3
where b1, b2, b3 are the
barycentric coordinates
of p wrt v1, v2, v3
p = b1*v1 + b2*v2 + b3*v3
(b1 + b2 + b3 = 1)
Phong Shading
One normal per vertex ... however
a normal is calculated for each rendered point p in triangle
vertex normals n1, n2, n3
p = b1*v1 + b2*v2 + b3*v3
n = b1*n1 + b2*n2 + b3*n3
+ normalize n!
Calculate intensity at p wrt n
Not considered a real-time algorithm
therefore, not in ogl
Setting up the Lighting Model
OGL’s glLightModel has four settings …
1. local vs infinite viewer
affects highlights of specular
infinite: v vector for all vertices the same
2. one-sided vs two-sided
default: infinite
default: one-sided
front-facing triangle: on screen counterclockwise orientation
one-sided = just shade front-facing
two-sided = shade front and back-facing triangles
nice for inside and outside color effect
3. global ambient intensity
4. specular and texture interaction
default: none
let’s revisit when we
discuss texture
OGL Calls
Basic steps ...
1.
2.
3.
4.
create, position & enable lights
viewer local or infinite?
front and back polygon shading?
set material properties
Keep in mind that local viewer and lights require more computation
Default camera: eye at origin and looking down –z axis
(This is eye coordinates.)
Reading: Chapter 5 !!
Controlling the Light’s Position
Light stationary:
glModelMatrixMode(GL_MODELVIEW)
glLoadIdentity();
modeling and viewing here
glLightfv(GL_LIGHT0, GL_POSITION, position)
Controlling the Light’s Position
Rotate light about stationary object:
glPushMatrix();
gluLookAt(…);
glPushMatrix();
glRotate*(…);
glLightfv(GL_LIGHT0, GL_POSITION,
position)
glPopMatrix();
draw_object();
glPopMatrix();
Controlling the Light’s Position
Move light with viewpoint:
aka: minor’s hat
key: specify light position in eye coordinates before viewing transf.
GLfloat position[] = {0, 0, 0, 1}
…
glModelMatrixMode(GL_MODELVIEW)
glLoadIdentity();
glLightfv(GL_LIGHT0, GL_POSITION, position)
glPushMatrix()
gluLookAt( …)
draw object()
glPopMatrix()
Resources
Many figures for these slides were taken from Pascal
Vuytsteker’s website:
http://escience.anu.edu.au/lecture/cg/Illumination/ind
ex.en.html
Of course, OGL Red book Chapter 5
Material
Properties
r,g,b,alpha 
Material
Properties