O'Reilly logo

OpenGL Insights by Christophe Riccio, Patrick Cozzi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Massive Number of
Shadow-Casting Lights with
Layered Rendering
Daniel R
´
akos
19.1 Introduction
Shadow map generation is one of the most time-consuming rendering tasks that to-
day’s graphics applications have to deal with due to the high number of dynamic light
sources used. Deferred rendering techniques have provided a reasonable answer for
handling a large number of dynamic light sources in linear time because they work
independently of the scene complexity. However, shadow map generation is still an
O(nm) time complexity task where n is the number of light sources and m is the
number of objects.
This chapter explores the possibility of taking advantage of some of the latest
GPU technologies to decrease this time complexity by using layered rendering to ren-
der multiple shadow maps at once using the same input geometry. Layered rendering
will enable us to decrease the vertex attribute–fetching bandwidth requirements and
the vertex processing time to O(m) time complexity.
While this approach will still require O(nm) time complexity for rasterizing and
fragment processing, this generally takes far less time in practice, as usually, the
light volumes dont overlap completely, so most of the geometric primitives will be
culled early by the rasterizer. We will also investigate whether the required rasterizer
throughput can be further decreased by doing view-fru stum culling in the geometry
shader performing the layered rendering.
I will present a reference implementation for both traditional and layered shadow
map rendering that enables us to provide performance comparison results for the two
approaches in different scenes with various scene complexities and various numbers
259
19
260 III Bending the Pipeline
of light sources and types. In addition, I will provide measurements about how the
shadow map resolution affects the performance of the traditional method and our
new technique.
Performance measurements are executed both for client-side and server-side work-
loads because, besides decreasing the geometry processing requirements of shadow
rendering, the technique also drastically decreases the number of necessary state
changes and draw commands to render multiple shadow maps, thus providing an
edge for CPU-bound applications.
While the technique primarily targets OpenGL 4.x–capable GPUs, we present
how the same technique can be implemented with some caveats for GPUs with only
OpenGL 3.x capabilities.
Further, I will present some special use cases of layered shadow map rendering
that can be used to render shadow cube maps and cascaded shadow maps with a single
draw call, and I will briefly present how the technique can be altered to accelerate the
generation of reflection maps and reflection cube maps in a similar fashion.
F inally, I will discuss the limitations of the presented algorithm, explicitly men-
tioning those imposed by hardware limitations of GPU implementations.
19.2 Traditional Shadow Map Rendering in
OpenGL
Shadow mapping or projective shadowing is an image-space rendering technique in-
troduced by [Williams 78] that became the de facto standard for performing shadow
rendering in real time and offline graphics applications.
The principle of shadow mapping is that if we view the scene from a light sources
position, all the object points we can see from there appear in light and anything
behind those is in shadow. Based on this, the algorithm works in the following way:
We render the scene from the light source’s point of view to a depth buffer
using the well-known z-buffer visibility algorithm.
When we render the scene from the cameras point of view, by comparing the
distance of the light source to any point of the surface with the sampled value
from the depth buffer corresponding to the point, we can decide whether the
given point is in light or in shadow. See Figure 19.1.
Modern graphics processors provide hardware support for this technique in the form
of two features:
Providing a mechanism to store depth-buffer images in textures.
Providing a mechanism to compare a reference depth value with a depth value
stored in a depth texture.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required