Category: 

What Is an OpenGL® Shadow?

Article Details
  • Written By: Eugene P.
  • Edited By: Angela B.
  • Last Modified Date: 06 September 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
The atmosphere of Jupiter's moon Io collapses every time it is eclipsed by the planet.   more...

September 29 ,  2008 :  The Dow Jones Industrial Average experienced its largest one-day drop in history.  more...

An Open Graphics Library® (OpenGL®) shadow is a visual approximation in a three-dimensional (3D) OpenGL® scene of how a shadow would be cast in real life under similar lighting conditions. Shadows are a complex visual feature to implement in OpenGL®, largely because there is no innate support for casting shadows in a scene. There are instead a variety of techniques that can be used to create shadows from the objects and geometry within a scene using various tools, such as the various available buffers, shaders and, in some cases, extensions that give access to special features on certain graphics cards. In most cases, the quality, accuracy and speed of OpenGL® shadow rendering is directly related to the processing power and memory of the graphics hardware present in a computer or device. Some of the more popular methods of implementing an OpenGL® shadow include shadow volumes, shadow mapping and ray tracing.

Ad

Creating an application that has OpenGL® shadow support requires mathematical knowledge and a deep understanding of how OpenGL® works. OpenGL® is largely used to create 3D scenes that are dynamic and rendered in real time, so the algorithms that are used to create shadows must not only be optimized for speed, but also must be carefully measured for their consumption of resources and any disruptions that could be caused in the graphics pipeline used for rendering. For these reasons, the most basic method of creating a shadow, called ray tracing, often is impractical for full 3D scenes, because it can take a very long time.

Ray tracing basically follows an imaginary line, or ray, from the viewing plane or position of the camera through a scene to an object’s surface and then calculates the color of the surface based on the position of one or more light sources and other factors. During the process of rasterization, where the 3D scene is drawn to a two-dimensional (2D) surface so it can be displayed, the process of ray tracing has to be performed on every pixel that is being drawn and, especially with textures or other surface properties, might need to assess the same pixels several times. This means real-time ray tracing, although it would accurately render shadows, usually is not practical.

Another method that can be used to create an OpenGL® shadow is known as shadow mapping. This method uses the depth or stencil buffer to render a scene from the angle of the light source as a series of distances from the light source to the surfaces of different objects within the scene. The scene is then rendered a second time from the correct viewing angle, checking to see whether each pixel falls within a certain distance range within the buffer, indicating whether the pixel is lit or shadowed. Using shadow mapping can be memory intensive and, with scenes that have more than one light source, can involve making multiple maps from multiple angles.

Shadow volumes are a way to create an OpenGL® shadow that is more accurate than some other methods, but it presents its own problems. A shadow volume essentially is an invisible piece of geometry in a scene that expands from the lit surface of an object away from the light source. This volume can be checked against other objects to see if they are falling into the shadow of the surface from which the volume originated. This procedure can be very complex and ultimately create visual artifacts when optimized for speed.

Ad

You might also Like

Recommended

Discuss this Article

Post your comments

exception 'Exception' with message 'error writing captcha: Duplicate entry '2147483647' for key 'PRIMARY'' in /ssd/www/wisegeek/public_html/_core/classes/public/Captcha.php:44
Stack trace:
#0 /ssd/www/wisegeek/public_html/_core/controls/public/ControlDiscussionPostBox.php(324): Captcha->createCaptcha()
#1 /ssd/www/wisegeek/public_html/framework/classes/Control.php(104): ControlDiscussionPostBox->preRender(false)
#2 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): Control->render()
#3 /ssd/www/wisegeek/public_html/tpl/default-nocustom-lu/pages/public/article/article.htm(526): Control->__toString()
#4 /ssd/www/wisegeek/public_html/framework/classes/Control.php(300): require('/ssd/www/wisege...')
#5 /ssd/www/wisegeek/public_html/framework/classes/Control.php(309): Control->requireTpl('pages/public/ar...', Object(PageArticleCom), true)
#6 /ssd/www/wisegeek/public_html/framework/classes/Control.php(131): Control->renderTpl('pages/public/ar...', Object(PageArticleCom))
#7 /ssd/www/wisegeek/public_html/framework/classes/FormDataControl.php(87): Control->renderTemplate()
#8 /ssd/www/wisegeek/public_html/framework/classes/Control.php(109): FormDataControl->renderTemplate()
#9 /ssd/www/wisegeek/public_html/framework/classes/ScriptPage.php(50): Control->render(false)
#10 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): ScriptPage->render()
#11 /ssd/www/wisegeek/public_html/framework/classes/Page.php(97): Control->__toString()
#12 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(443): Page->processRequest()
#13 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(7): PublicFrontController->renderPage()
#14 /ssd/www/wisegeek/public_html/index.php(11): PublicFrontController::run()
#15 {main}