Chapter 4. Lighting


The earliest lighting algorithms used simple equations to render perfect Lambertian diffuse reflective surfaces and specular highlights. Complex illumination models such as ray tracing and radiosity, and programmable fragment shaders that simulate complex material reflectance properties, employ these simple diffuse and specular lighting equations as building blocks. In fact, simple diffuse and specular lighting suffice for the vast majority of nonphotorealistic interactive computer graphics applications today.

As a low-level graphics API, OpenGL has no direct support for ray tracing and radiosity. It does support ambient, diffuse, and specular lighting, however. This chapter describes how to set OpenGL lighting parameters and coefficients for the typical lighting requirements of most applications. Chapter 6, "Texture Mapping," demonstrates enhanced lighting effects using texture mapping.

If your application requires advanced lighting effects beyond the capabilities of OpenGL lighting and texture mapping, such as per-pixel lighting or bidirectional reflectance distribution functions, you should consider using OpenGL vertex and fragment shaders. appendix A, "Other Features," discusses this feature briefly. For more in-depth treatment, see OpenGL® Shading Language.

What You'll Learn

The following aspects of OpenGL lighting are covered in this chapter:

  • Specifying normalsHow to keep normals unit length in the presence of uniform and nonuniform scaling. (You already know how to specify normals from Chapter 2, "Drawing Primitives.")

  • Configuring light propertiesHow to enable OpenGL light sources and set their intensity and color.

  • Specifying material parametersHow to specify material colors and force material colors to track changes to the primary color.

  • Controlling positional and directional lightsHow to set the light-source position and direction parameters.

  • DebuggingHow to resolve common problems you might encounter while adding support for OpenGL lighting to your application.

What You Won't Learn

The following aspects of OpenGL lighting are not covered in this chapter:

  • SpotlightsThe chapter doesn't cover how to restrict a positional light source to emit a cone or beam of light.

  • AttenuationThe chapter doesn't cover how to reduce light intensity as a function of distance.

  • Lighting model parametersThis chapter doesn't cover OpenGL's light model parameters, such as global ambient light, local viewer, and color control. The chapter provides some information on two-sided lighting as an explanation for parameters to glMaterial*(), however.

  • Emissive lightThe chapter doesn't show how to render geometry that appears to emit light.

  • Ambient lightThe default ambient light setting is adequate for most rendering. This chapter discusses ambient light but doesn't provide full details on controlling it completely.

  • Lighting in color index modeColor index mode is rarely used in modern OpenGL applications.

  • Specific light equationsThe exact mathematical equations used by OpenGL to compute light values aren't covered.

Though useful in some rendering circumstances, these features are outside the scope of this book. If your application requires this functionality, see OpenGL® Programming Guide and OpenGL® Reference Manual.




OpenGL Distilled
OpenGL Distilled
ISBN: 0321336798
EAN: 2147483647
Year: 2007
Pages: 123
Authors: Paul Martz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net