Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lighting Calculations

Similar presentations


Presentation on theme: "Lighting Calculations"— Presentation transcript:

1 Lighting Calculations
Lecture 27 Wed, Oct 31, 2007

2 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.

3 Types of Light Source Ambient Point Source Directional Source

4 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).

5 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).

6 Example – The Viewer Suppose The viewer is located at V = (5, 10, 15).

7 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

8 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).

9 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.

10 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.

11 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.

12 Diffuse Reflection Light Source Eye n s v P Surface

13 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).

14 Lambert’s Law s n s n s n s n

15 Angle small  cosine big
Lambert’s Law s n s n Angle small  cosine big s n s n

16 Angle big  cosine small
Lambert’s Law s n s n s n s n Angle big  cosine small

17 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.

18 Diffuse Reflection The formula for diffuse reflection is
rd = Ldmd(s  n). Of course, if s  n < 0, then rd = 0. Why?

19 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 = Ld= (0.8, 0.8, 0.8). md= (0.6, 0.4, 0.2).

20 The Example – Diffuse Reflection
The diffuse reflection is Ldmd(s  n) = (0.3520, , ).

21 The Example – Ambient + Diffuse
Ambient and diffuse reflection combined is (0.6520, , ).

22 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.

23 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.

24 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.

25 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.

26 Phong Lighting Light Source Eye Ideal Direction n r s   v  P
Surface

27 Phong Lighting To compute r, note that r + s equals twice the projection of s onto n. s n r

28 [(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

29 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

30 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

31 Computing Specular Reflection
Of course, if s  n < 0 or if r  v < 0, then rs = 0. Why?

32 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, , ) = (38, 41, 50)/75. r  v =

33 The Example – Specular Reflection
shiny = 128. Ls = 1.0. ms = 1.0. Lsms(r  v)shiny =

34 The Example – Total Reflection
Ambient, diffuse, and specular combined is (1.0, , ). Compared to the material color (0.6, 0.4, 0.2).

35 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

36 Blinn Lighting Light Source Eye Halfway n h s v P Surface

37 Blinn Lighting Light Source Eye Halfway n h s v P Surface

38 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.

39 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.

40 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

41 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.

42 The Lighting Model The complete formula for the reflected shade (Ir, Ig, Ib) for n lights is

43 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.

44 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?

45 Gouraud Shading dim dim interpolated dim reflection reflection
surface

46 Gouraud Shading dim dim interpolated dim reflection reflection
computed shades

47 Gouraud Shading dim dim interpolated dim reflection reflection
interpolated shades

48 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.

49 Phong Shading bright reflection dim dim reflection reflection
interpolated vectors

50 Phong Shading bright reflection dim dim reflection reflection
computed shades

51 Phong Shading bright reflection dim dim reflection reflection
computed shades


Download ppt "Lighting Calculations"

Similar presentations


Ads by Google