Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
The Lighting ModelLecture 15Section 5.3
Robb T. Koether
Hampden-Sydney College
Mon, Oct 3, 2011
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 1 / 45
Outline
1 The Phong Lighting ModelAmbient ReflectionDiffuse ReflectionSpecular ReflectionEmissive Light
2 Assignment
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 2 / 45
Outline
1 The Phong Lighting ModelAmbient ReflectionDiffuse ReflectionSpecular ReflectionEmissive Light
2 Assignment
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 3 / 45
Shading Calculations
Example (The Material Properties)Let the position be P = (0,5,10).Let the surface normal be n = (0.8,0.6,0.0).Let us assume that the object has the following materialproperties.
Ambient reflection is (0.6,0.4,0.2).Diffuse reflection is (0.6,0.4,0.2).Specular reflection is (1.0,1.0,1.0).Shininess is 128.That is, the object is shiny brown.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 4 / 45
Shading Calculations
Example (The Light Source)Let us assume that general ambient light is (0.2,0.2,0.2).Let LIGHT0 have the following properties.
Position is L = (10,10,0).Ambient light is (0.3,0.3,0.3).Diffuse light is (0.8,0.8,0.8).Specular light is (1.0,1.0,1.0).
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 5 / 45
Shading Calculations
Example (The Viewer)Let us assume that the viewer is located at V = (5,10,15).
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 6 / 45
Outline
1 The Phong Lighting ModelAmbient ReflectionDiffuse ReflectionSpecular ReflectionEmissive Light
2 Assignment
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 7 / 45
Computing Ambient Reflection
The ambient reflection depends onThe general ambient light inherent in the scene.
0 ≤ sa ≤ 1.
The ambient light from the light source.
0 ≤ La ≤ 1.
The ambient property of the surface.
0 ≤ ka ≤ 1.
The ambient reflection is computed as
ra = saka + Laka
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 8 / 45
The Shading Calculations
Example (Calculating Ambient Reflection)We have
sa = 0.2La = 0.3ka = (0.6,0.4,0.2)
Therefore, the ambient reflection is
saka + Laka = (0.3,0.2,0.1).
Original Ambient
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 9 / 45
Outline
1 The Phong Lighting ModelAmbient ReflectionDiffuse ReflectionSpecular ReflectionEmissive Light
2 Assignment
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 10 / 45
Point and Directional Sources
At each point of a surface, the light from a light source has adirection.
Point source - direction varies with position on surface.Directional source - direction does not vary with position on surface.
With a point source, the intensity may also depend on distancefrom the source if we enable attenuation.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 11 / 45
Diffuse Relection
Intensity of reflected diffuse lightDepends on angle of incidence.Reflects equal in all directions. Therefore, it does not depend onthe viewer’s location.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 12 / 45
Computing Diffuse Reflection
Let P be a point on the surface.We need to know two geometric facts.
The location of light source, as a vector l from P to the light source.The orientation of the surface, as a vector n normal to the surface.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 13 / 45
Diffuse Reflection
Light Source n
lθ
P Surface
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 14 / 45
Lambert’s Law
Diffuse reflection is equal in intensity in all directions.However, the intensity depends on the angle of the incident light.Lambert’s law says that the intensity is proportional to the cosineof the angle of incidence (as measured down from the normal).
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 15 / 45
Lambert’s Law
nl
P Surface
θ
Small angle⇒ Large cosine⇒ Bright reflection
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 16 / 45
Lambert’s Law
n
l
P Surface
θ
Large angle⇒ Small cosine⇒ Dim reflection
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 16 / 45
Diffuse Reflection
If l and n are unit vectors, then the cosine of the angle betweenthem is
l · n = cos θ.
Two other factors are needed.Intensity of the incident light.
0 ≤ Ld ≤ 1.
Reflective property of the surface.
0 ≤ kd ≤ 1.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 17 / 45
Diffuse Reflection
The formula for diffuse reflection is
rd = Ldkd(l · n).
Of course, if l · n < 0, then rd = 0.Why?
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 18 / 45
The Shading Calculations
Example (Diffuse Reflection)We have
L− P = (10,5,−10)
l = (10,5,−10)/√
225= (2/3,1/3,−2/3)
n = (0.8,0.6,0.0)
l · n = 0.7333Ld = (0.8,0.8,0.8)
md = (0.6,0.4,0.2)
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 19 / 45
The Shading Calculations
Example (Diffuse Reflection)The diffuse reflection is
Ldkd(l · n) = (0.3520,0.2347,0.1173).
Original Diffuse
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 20 / 45
The Shading Calculations
Example (Ambient and Diffuse Reflection)Ambient and diffuse reflection combined is
(0.6520,0.4347,0.2173).
+
Ambient Diffuse
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 21 / 45
Outline
1 The Phong Lighting ModelAmbient ReflectionDiffuse ReflectionSpecular ReflectionEmissive Light
2 Assignment
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 22 / 45
Specular Reflection
The intensity of specular reflected light varies with viewingdirection as well as the direction of the light source.The maximum intensity is in the “ideal” direction, based on theprinciple that
Angle of reflection = Angle of incidence.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 23 / 45
Blinn and Phong Lighting
OpenGL uses the Blinn lighting model of specular reflection.However, we will first study the Phong lighting model since itseems more natural.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 24 / 45
Phong Lighting
The intensity of the reflection is a function of the angle betweenthe viewer and the ideal direction r of reflection of light from thelight source off the surface.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 25 / 45
Phong Lighting
Light Source
Eye
n
l
vϕ
P Surface
r
θθ
IdealDirection
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 26 / 45
Phong Lighting
To compute r, note that r + l equals twice the projection of l onto n.
n
l rθθ
r l
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 27 / 45
Phong Lighting
The projection of l onto n is(l · nn · n
)n = (l · n)n.
Therefore,r + l = 2(l · n)n
andr = −l + 2(l · n)n.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 28 / 45
Computing Specular Reflection
According to the Phong lighting model, the specular reflection isproportional to the cosine of the angle between v and r, raised tothe α power, where α is an integer between 0 and 128.This is calculated as
(cosϕ)α = (r · v)α.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 29 / 45
Computing Specular Reflection
Two other factors areIntensity of the incident light.
0 ≤ Ls ≤ 1.
Specular property of the surface.
0 ≤ ks ≤ 1.
Therefore, the formula for specular reflection is
rs = Lsks(r · v)α.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 30 / 45
Computing Specular Reflection
Of course, if l · n < 0 or if r · v < 0, then rs = 0.Why?
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 31 / 45
The Shading Calculations
Example (Specular Reflection)Now we have
l = (2/3,1/3,−2/3)
n = (0.8,0.6,0.0)
V − P = (5,5,5)
v = (5,5,5)/√
75 =
(1√3,
1√3,
1√3
)r = −l + 2(l · n)n
=
(3875,4175,5075
)= (0.5067,0.5467,0.6667)
r · v = 0.9930
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 32 / 45
The Shading Calculations
Example (Specular Reflection)And
α = 128Ls = 1.0ks = 1.0
Lsks(r · v)α = (0.4091,0.4091,0.4091)
Original Specular
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 33 / 45
The Shading Calculations
Example (Total Reflection)Ambient, diffuse, and specular combined is
(1.0,0.8438,0.6264).
Compared to the inherent material color
(0.6,0.4,0.2).
+
Ambient Diffuse
+
Specular
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 34 / 45
Blinn Lighting
A slightly more efficient method is the Blinn lighting model.Let h be the halfway vector, the unit vector halfway between l andv.Then use h · n instead of r · v.
rs = Lsks(h · n)α.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 35 / 45
Blinn Lighting
Light Source
Eye
n
l
v
P Surface
ωω
hζ
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 36 / 45
Blinn Lighting
How does h · n compare to l · v?If l, n, and v are coplanar, then the angle between h and n is halfof the angle between r and v.Why is Blinn lighting more efficient?h is computed as
h =l + v|l + v|
.
This is more efficient to compute than r.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 37 / 45
Outline
1 The Phong Lighting ModelAmbient ReflectionDiffuse ReflectionSpecular ReflectionEmissive Light
2 Assignment
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 38 / 45
Emissive Lighting
Emissive “lighting” is light that emitted by the surface itself.It is used for objects that are meant to glow.It is independent of all light sources and directions.Let me be the intensity of the emissive light.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 39 / 45
Computing the Shade of a Surface
The total reflection from a point is the sum of the ambient, diffuse,and specular reflections and the emissive light.
ke + saka + Laka + Ldkd(l · n) + Lsks(h · n)shiny .
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 40 / 45
Lighting in OpenGL
Since the ambient, diffuse, and specular reflections depend onlight sources, there is a separate contribution for each light source.OpenGL provides up to 8 light sources.Furthermore, there is a separate color component for each type oflight (red, green, blue).
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 41 / 45
The Lighting Model
The complete formula for the reflected shade (Ir , Ig , Ib) for 8 lightsis
Ir = ker + sar kar+
7∑i=0
(Lar kar + Ldr kdr (l · n) + Lsr ksr (h · n)shiny
)Ig = keg + sagkag+
7∑i=0
(Lagkag + Ldgkdg(l · n) + Lsgksg(h · n)shiny
)Ib = keb + sabkab+
7∑i=0
(Labkab + Ldbkdb(l · n) + Lsbksb(h · n)shiny
)
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 42 / 45
The Lighting Model
For each color, the computed value is “clamped” to the interval[0,1].If the value exceeds 1, then it is set to 1.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 43 / 45
Outline
1 The Phong Lighting ModelAmbient ReflectionDiffuse ReflectionSpecular ReflectionEmissive Light
2 Assignment
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 44 / 45
Homework
HomeworkRead Section 5.3 – the Phong lighting model.
Robb T. Koether (Hampden-Sydney College) The Lighting Model Mon, Oct 3, 2011 45 / 45