We have learned to build three-dimensional graphical models and to display them. However, if you render one of our models, you might be disappointed to see images that look flat and thus fail to show the three-dimensional nature of the model. This appearance is a consequence of our unnatural assumption that each surface is colored with a single color. Under this assumption, the orthographic projection of a sphere is rendered as a uniformly colored circle, and the rendering of a cube appears as a flat hexagon. If we look at a photograph of a lit sphere, we do not see a uniformly colored circle but rather a circular shape with many gradations or shades of color. It is these gradations that give two-dimensional images the appearance of being threedimensional. When we look at a point on an object, the color that we see is determined by multiple interactions among light sources and reflective surfaces. These interactions can be viewed as a recursive process. Consider the simple scene illustrated in Figure 10.1 Some light from the source that reaches surface A is scattered. Some of this reflected light reaches surface B, and some of it is then scattered back to A, where some of it is again reflected back to B, and so on. Figure 10.1 There are various approximate approaches, such as radiosity and ray tracing, each of which is an excellent approximation to the rendering equation for particular types of surfaces. We follow rays of light from light-emitting (or self-luminous) surfaces that we call light sources. There are two independent parts of the problem. First, we must model the light sources in the scene. Then we must build a reflection model that describes the
interactions between materials and light. To get an overview of the process, we can start following rays of light from a point source, as shown in Figure 10.2. Figure 10.2 Light and Surfaces Interactions : The interactions between light and materials can be classified into the three groups depicted in Figure 10.3. 1. Specular surfaces : appear shiny because most of the light that is reflected or scattered is in a narrow range of angles close to the angle of reflection. Mirrors are perfectly specular surfaces; the light from an incoming light ray may be partially absorbed, but all reflected light emerges at a single angle, obeying the rule that the angle of incidence is equal to the angle of reflection. 2. Diffuse surfaces : are characterized by reflected light being scattered in all directions. Walls painted with matte or flat paint are diffuse reflectors, as are many natural materials, such as terrain viewed from an airplane or a satellite. Perfectly diffuse surfaces scatter light equally in all directions and thus appear the same to all viewers. 3. Translucent surfaces : allow some light to penetrate the surface and to emerge from another location on the object. This process of refraction characterizes glass and water. Some incident light may also be reflected at the surface.
Figure 10.3 Light Sources : If we consider a source such as the one shown in Figure 10.4, we can look at it as an object with a surface. Each point (x, y, z) on the surface can emit light that is characterized by the direction of emission ( ) and the intensity of energy emitted at each wavelength. Thus, a general light source can be characterized by a six-variable illumination function I(x, y, z ), Figure 10.5. Figure 10.4 Figure 10.5 For most applications, we can thus model light sources as having three components red, green, and blue and can use each of the three color sources to obtain the corresponding color component that a human observer sees. Thus, we can describe a color source through a three-component intensity or illumination function:
1. Ambient Light In many situations, such as in classrooms or kitchens, the lights have been designed and positioned to provide uniform illumination throughout the room. Often such illumination is achieved through large sources that have diffusers whose purpose is to scatter light in all directions. We could create an accurate simulation of such illumination, at least in principle, by modeling all the distributed sources and then integrating the illumination from these sources at each point on a reflecting surface. We can look at the desired effect of the sources: to achieve a uniform light level in the room. This uniform lighting is called ambient light. Ambient light depends on the color of the light sources in the environment. For example, a red light bulb in a white room creates red ambient light. 2. Point Sources An ideal point source emits light equally in all directions. We can characterize a point source located at a point p0 by a three-component color function We use I (p0 ) to refer to any of the components. The intensity of illumination received from a point source located at p0 at a point p is proportional to the inverse square of the distance from the source. Hence, at a point p (Figure 10.6), any component of the intensity of light received from the point source is given by function of the form Figure 10.6
3. Spotlights Spotlights are characterized by a narrow range of angles through which light is emitted. We can construct a simple spotlight from a point source by limiting the angles at which light from the source can be seen. We can use a cone whose apex is at p s, which points in the direction Is, and whose width is determined by an angle, as shown in Figure 10.7. If = 180, the spotlight becomes a point source. Figure 10.6 4. Distant Light Sources Most shading calculations require the direction from the point on the surface to the light source position. As we move across a surface, calculating the intensity at each point, we should recompute this vector repeatedly a computation that is a significant part of the lighting calculation. However, if the light source is far from the surface, the vector does not change much as we move from point to point, just as the light from the sun strikes all objects that are in close proximity to one another at the same angle. Figure 10.7
LIGHT SOURCES IN OPENGL OpenGL supports the four types of light sources point, spotlight, ambient, and distant that we described previously and allows at least eight light sources in a program. Each must be individually specified and enabled. Although there are many parameters that must be specified, they are exactly the parameters required by the modified-phong lighting model. The OpenGL functions: Specify the required vector and scalar parameters, respectively. There are four vector parameters that we can set: the position (or direction) of the light source and the amount of ambient, diffuse, and specular light associated with the source. For example, suppose that we wish to specify the first source GL_LIGHTO and to locate it at the point (1.0, 2.0, 3.0). We specify its position as a point in homogeneous coordinates as follows : With the fourth component set to zero, the point source becomes a distant source with direction vector. For our single light source, if we want a white specular component and red ambient and diffuse components, we can use the following code:
Note that we must enable both lighting and the particular source. We can also add a global ambient term that is independent of any of the sources. For example, if we want a small amount of white light, even when all light sources are turned off or disabled, we can use the following code: