Silicon Graphics

[Prev] [TOC] [Next]



(-) OpenGL Programming Guide
(-) Chapter 6Lighting

Defining Material Properties

You've seen how to create light sources with certain characteristics and how to define the desired lighting model. This section describes how to define the material properties of the objects in the scene: the ambient, diffuse, and specular colors, the shininess, and the color of any emitted light. The equations used in the lighting and material-property calculations are described in "The Mathematics of Lighting." Most of the material properties are conceptually similar to ones you've already used to create light sources. The mechanism for setting them is similar, except that the command used is called glMaterial*(). void glMaterial{if}[v](GLenum face, GLenum pname, TYPEparam);

Specifies a current material property for use in lighting calculations. The face parameter can be GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK to indicate which face of the object the material should be applied to. The particular material property being set is identified by pname and the desired values for that property are given by param, which is either a pointer to a group of values (if the vector version is used) or the actual value (if the nonvector version is used). The nonvector version works only for setting GL_SHININESS. The possible values for pname are shown in Table 6-2 . Note that GL_AMBIENT_AND_DIFFUSE allows you to set both the ambient and diffuse material colors simultaneously to the same RGBA value.

Parameter NameDefault ValueMeaning

GL_AMBIENT

(0.2, 0.2, 0.2, 1.0)

ambient color of material

GL_DIFFUSE

(0.8, 0.8, 0.8, 1.0)

diffuse color of material

GL_AMBIENT_AND_DIFFUSE



ambient and diffuse color of material

GL_SPECULAR

(0.0, 0.0, 0.0, 1.0)

specular color of material

GL_SHININESS

0.0

specular exponent

GL_EMISSION

(0.0, 0.0, 0.0, 1.0)

emissive color of material

GL_COLOR_INDEXES

(0,1,1)

ambient, diffuse, and specular color indices

Table 6-2 : Default Values for pname Parameter of glMaterial*()


As discussed in "Selecting a Lighting Model," you can choose to have lighting calculations performed differently for the front- and back-facing polygons of objects. If the back faces might indeed be seen, you can supply different material properties for the front and the back surfaces by using the face parameter of glMaterial*(). See Figure J-19 for an example of an object drawn with different inside and outside material properties.

To give you an idea of the possible effects you can achieve by manipulating material properties, see Figure J-21 . This figure shows the same object drawn with several different sets of material properties. The same light source and lighting model are used for the entire figure. The sections that follow discuss the specific properties used to draw each of these spheres.

Note that most of the material properties set with glMaterial*() are (R, G, B, A) colors. Regardless of what alpha values are supplied for other parameters, the alpha value at any particular vertex is the diffuse-material alpha value (that is, the alpha value given to GL_DIFFUSE with the glMaterial*() command, as described in the next section. (See "Blending" for a complete discussion of alpha values.) Also, none of the RGBA material properties apply in color-index mode; see "Lighting in Color-Index Mode" for more information about what parameters are relevant in color-index mode.


(+) Diffuse and Ambient Reflection
(+) Specular Reflection
(+) Emission
(+) Changing Material Properties

[Prev] [TOC] [Next]

OpenGL Programming Guide


Maintained by Maintainer: Send e-mail to .htm">name@address.