Lighting Calculations Lecture 27 Wed, Oct 31, 2007
Types of Light Source Ambient Point Source Directional Source No position in space. Illuminates objects equally from all directions. Point Source At a point in space. Equal intensity in all directions. Directional Source Source is “at infinity.” Has direction only.
Types of Light Source Ambient Point Source Directional Source
Example – The Light Source Suppose General ambient light is (0.2, 0.2, 0.2). Light source 0 properties are 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). The light’s position is L = (10, 10, 0).
Example – The Material Suppose Material properties are 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. The object is brown: The position is P = (0, 5, 10). The surface normal is n = (0.8, 0.6, 0.0).
Example – The Viewer Suppose The viewer is located at V = (5, 10, 15).
Computing Ambient Reflection The ambient reflection depends on The 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 ma 1. The ambient reflection is computed as ra = sama + Lama
Example In the example, sa = 0.2, La = 0.3, and ma = (0.6, 0.4, 0.2). The ambient reflection is sama + Lama = (0.3, 0.2, 0.1).
Point and Directional Sources At each point of a surface, the light from a light source has a direction. 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 distance from the source if we enable attenuation.
Diffuse Relection Intensity of reflected diffuse light Depends on angle of incidence. Reflects equal in all directions. Therefore, it does not depend on the viewer’s location.
Computing Diffuse Reflection Let P be a point on the surface. We need to know two geometric facts. Location of light source. Vector s from P to the light source. Orientation of the surface. Vector n normal to the surface.
Diffuse Reflection Light Source Eye n s v P Surface
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 cosine of the angle of incidence (as measured down from the normal).
Lambert’s Law s n s n s n s n
Angle small cosine big Lambert’s Law s n s n Angle small cosine big s n s n
Angle big cosine small Lambert’s Law s n s n s n s n Angle big cosine small
Diffuse Reflection If s and n are unit vectors, then the cosine of the angle between them is s n. Two other factors. Intensity of the incident light. 0 Ld 1. Reflective property of the surface. 0 md 1.
Diffuse Reflection The formula for diffuse reflection is rd = Ldmd(s n). Of course, if s n < 0, then rd = 0. Why?
The Example – Diffuse Reflection L – P = (10, 5, -10). s = (10, 5, -10)/225 = (2/3, 1/3, -2/3). n = (0.8, 0.6, 0.0). s n = 0.7333. Ld= (0.8, 0.8, 0.8). md= (0.6, 0.4, 0.2).
The Example – Diffuse Reflection The diffuse reflection is Ldmd(s n) = (0.3520, 0.2347, 0.1173).
The Example – Ambient + Diffuse Ambient and diffuse reflection combined is (0.6520, 0.4347, 0.2173).
Specular Reflection The intensity of specular reflected light varies with viewing direction as well as the direction of the light source. The maximum intensity is in the “ideal” direction. Angle of reflection = angle of incidence.
Specular Reflection Specular reflection creates the appearance of “shininess.” Surfaces with a high specular reflection appear very shiny. Surfaces with a low specular reflection appear matte.
Blinn and Phong Lighting OpenGL uses the Blinn lighting model of specular reflection. However, we will first study the Phong lighting model since it seems more natural.
Phong Lighting The intensity of the reflection is a function of the angle between the viewer and the ideal direction r of reflection of light from the light source off the surface.
Phong Lighting Light Source Eye Ideal Direction n r s v P Surface
Phong Lighting To compute r, note that r + s equals twice the projection of s onto n. s n r
[(s n)/(n n)]n = (s n)n Phong Lighting The projection of s onto n is [(s n)/(n n)]n = (s n)n Therefore, r + s = 2(s n)n and r = -s + 2(s n)n
Computing Specular Reflection According to the Phong lighting model, the specular reflection is proportional to the cosine of the angle between v and r, raised to the “shiny” power. This is calculated as (r v)shiny
Computing Specular Reflection Two other factors are Intensity of the incident light. 0 Ls 1. Specular property of the surface. 0 ms 1. The formula for specular reflection is rs = Lsms(r v)shiny
Computing Specular Reflection Of course, if s n < 0 or if r v < 0, then rs = 0. Why?
The Example – Specular Reflection V – P = (5, 5, 5). v = (5, 5, 5)/75 = (1, 1, 1)/3. r = -s + 2(s n)n = (0.5067, 0.5467, 0.6667) = (38, 41, 50)/75. r v = 0.9930.
The Example – Specular Reflection shiny = 128. Ls = 1.0. ms = 1.0. Lsms(r v)shiny = 0.4091.
The Example – Total Reflection Ambient, diffuse, and specular combined is (1.0, 0.8438, 0.6264). Compared to the material color (0.6, 0.4, 0.2).
Blinn Lighting A slightly more efficient method is the Blinn lighting model. Let h be the halfway vector, the unit vector halfway between s and v. Then use h n instead of r v. rs = Lsms(h n)shiny
Blinn Lighting Light Source Eye Halfway n h s v P Surface
Blinn Lighting Light Source Eye Halfway n h s v P Surface
Blinn Lighting How does h n compare to s v? If s, n, and v are coplanar, then the angle between h and n is half of the angle between r and v. Why is Blinn lighting more efficient? h is computed as h = (s + v)/|s + v|. This is more efficient to compute than r.
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.
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. sama + Lama + Ldmd(s n) + Lsms(h n)shiny + me
Lighting in OpenGL Since the ambient, diffuse, and specular reflections depend on light 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 of light. Red, green, blue.
The Lighting Model The complete formula for the reflected shade (Ir, Ig, Ib) for n lights is
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.
Gouraud Shading Gouraud shading computes the specular reflection only at the vertices and then interpolates. This guarantees that the brightest reflection will be at a vertex (or along an edge). Why?
Gouraud Shading dim dim interpolated dim reflection reflection surface
Gouraud Shading dim dim interpolated dim reflection reflection computed shades
Gouraud Shading dim dim interpolated dim reflection reflection interpolated shades
Phong Shading Phong shading interpolates (and normalizes) the normal vectors and then uses them to compute the specular reflection at each vertex. Phong shading is much more realistic. much less efficient.
Phong Shading bright reflection dim dim reflection reflection interpolated vectors
Phong Shading bright reflection dim dim reflection reflection computed shades
Phong Shading bright reflection dim dim reflection reflection computed shades