Learn something new every day
More Info... by email
OpenGL® lighting is one of the most complex, and sometimes least understood, aspects of three-dimensional (3D) computer graphics programming. It can be used to add the necessary, realistic finishing touches to a rendered scene, but it also can be computationally demanding and ultimately confusing when effects are not readily achieved. Certain elements, such as defining surface normals, can be easily understood while other parts of the lighting model, such as the division of the different light types, might require more study to fully grasp. Two concerns are usually present when working with OpenGL® lighting: render speed and quality. There are some tips that can help to achieve an acceptable proportion of both, but trade-offs between quality and speed will ultimately need to be made.
One problem commonly encountered, especially for those new to OpenGL® lighting, is that every vertex in a scene needs to have its surface normal defined. Without the normals, the renderer will instead use a single constant, effectively causing everything in a scene to appear flat and unshaded. One trick when defining normals is to use values that are not perpendicular to the surface but instead face a different direction. This will change how the light is rendered on the surface and can be used to easily create noise or rocky textures, a process known as bump mapping.
To get good, and potentially unique, effects in a scene using OpenGL® lighting, it is necessary to fully understand what ambient, specular, diffuse and emitting light sources entail. A scene full of fog can be made to appear more realistic with a high, gray ambient value. Similarly, special effects such as fire or exposed lights can be done with emitting materials and light sources. The layering and combination of the four basic models are what can make a scene appear more realistic.
It is important to understand that OpenGL® lighting requires a large amount of processor power for each rendered frame. This means that optimizing a scene can help to achieve a better frame rate. Some things that can reduce the rendering time are to use as few light sources as possible, minimize the amount of surfaces being illuminated, and avoid algorithms or extensions that process the final framebuffer multiple times. Moving the lighting in a scene also can have some detrimental effects on performance and should be avoided when the speed of rendering is becoming problematic.
One final tip about using OpenGL® lighting is to know when not to use OpenGL® lighting. It can be easy to think of placing emitting objects and lights in a scene at every point where one would be in reality, but this can quickly become impractical. Instead, many lighting tricks can be done through illusions using well-made texture images that have the lighting already drawn on the surface. In the same way, arranging the geometry of a scene can sometimes eliminate the need for multiple light sources by disguising some problem areas or by allowing a single source inside a hollow compound object to shine out through multiple planned openings.
One of our editors will review your suggestion and make changes if warranted. Note that depending on the number of suggestions we receive, this can take anywhere from a few hours to a few days. Thank you for helping to improve wiseGEEK!