Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lighting – Material Properties

Similar presentations


Presentation on theme: "Lighting – Material Properties"— Presentation transcript:

1 Lighting – Material Properties
Lecture 13 Mon, Sep 24, 2007

2 Material Properties The surface “interacts” with the light as determined by the material properties: Reflection: ambient, diffuse, specular, shininess. Color: red, green, blue. Use the function glMaterial*() to specify the amount of red, green, and blue reflection of each type.

3 Example // A shiny red object
float mat_ambient[] = {1.0, 0.0, 0.0, 1.0}; float mat_diffuse[] = {1.0, 0.0, 0.0, 1.0}; float mat_specular[] = {1.0, 1.0, 1.0, 1.0}; float mat_shininess = 64.0; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialf(GL_FRONT, GL_SHININESS, mat_shininess);

4 Material Properties Usually we use
The ambient and diffuse material properties to determine the color and brightness of the object. The specular material properties to determine the shininess of the object.

5 glEnable(GL_COLOR_MATERIAL)
Material Properties OpenGL allows the programmer to make an automatic connection between the glColor() function and the material color. glEnable(GL_COLOR_MATERIAL) The default sets the material ambient and diffuse reflections to the values given in glColor().

6 Material Properties Use glColorMaterial() to specify which material property will track the current color. GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_AMBIENT_AND_DIFFUSE (default) Only one mode is active at a time.

7 Material Properties Typically, we want only ambient and diffuse properties to track the current color. Specular material properties are usually set to (1.0, 1.0, 1.0) regardless of the surface color.

8 Material Properties Read Run

9 Material Emissive Light
In a similar way, we can set the amount of emissive light emitted by an object. The following code will make an object glow a bit reddish. float mat_emissive[] = {0.5, 0.0, 0.0, 1.0}; glMaterialfv(GL_FRONT, GL_EMISSION, mat_emissive);

10 Material Emissive Red Light
Read Run

11 Viewer Location The viewer can be either local or at infinity.
The default is at infinity. This setting can be changed by using glLightModel*(). glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

12 Infinite Viewer Read Run

13 Local Viewer Read Run

14 A Metallic Effect Read Run

15 Calculating the Lighting Effect
The light contributions for each color (red, green, and blue) are summed over All light sources (LIGHT0, …, LIGHT8) All types of light (ambient, diffuse, specular, emissive). Each total is clamped to 1.0. These color levels determine the shading of the vertex.

16 Lighting and Meshes The lighting effects are calculated only at the vertices, then interpolated across the polygon. Suppose the brightest point of reflection should be in the center of a square. The center will have an interpolated shading derived from the corners; the center will be no brighter than the corners.

17 Lighting and Meshes Rather than use one large rectangle, with only 4 vertices, it is better to use a mesh of smaller rectangles, with many vertices. The lighting will be calculated at each vertex and interpolated across a small rectangle.

18 Lighting and Meshes Read Run


Download ppt "Lighting – Material Properties"

Similar presentations


Ads by Google