Virtual Shadow Maps for Many Lights
Total Page:16
File Type:pdf, Size:1020Kb
Efficient Virtual Shadow Maps for Many Lights Ola Olsson∗ Erik Sintorn∗ Viktor Kampe¨ ∗ Markus Billeter∗ Ulf Assarsson∗ Chalmers University of Technology Figure 1: Scenes rendered with many lights casting shadows at 1920×1080 resolution on an NVIDIA Geforce Titan. From the left: HOUSES with 1.01M triangles and 256 lights (23ms), NECROPOLIS with 2.58M triangles and 356 lights (34ms), CRYSPONZA with 302K triangles and 65 lights (16ms). Abstract details in geometry, but tend to yield a flat look. Moreover, ne- glecting shadowing makes them more difficult to use, as light may Recently, several algorithms have been introduced that enable real- leak through walls and similar occluding geometry, if care is not time performance for many lights in applications such as games. In taken when placing the lights. For dynamic effects in interactive this paper, we explore the use of hardware-supported virtual cube- environments, controlling this behaviour is even more problematic. map shadows to efficiently implement high-quality shadows from Shadowing is also highly important if we wish to employ the lights hundreds of light sources in real time and within a bounded memory to visualize the result of some light-transport simulation, for example footprint. In addition, we explore the utility of ray tracing for shad- as done in Instant Radiosity [Keller 1997]. ows from many lights and present a hybrid algorithm combining ray tracing with cube maps to exploit their respective strengths. Our This paper aims to compute shadows for use in real-time applications solution supports real-time performance with hundreds of lights in supporting several tens to hundreds of shadow-casting lights. The fully dynamic high-detail scenes. shadows are of high and uniform quality, while staying within a bounded memory footprint. CR Categories: I.3.3 [Computer Graphics]: Three-Dimensional As a starting point, we use Clustered Deferred Shading [Olsson et al. Graphics and Realism—Display Algorithms 2012], as this algorithm offers the highest light-culling efficiency among current real-time many-light algorithms and the most robust Keywords: real-time,shadows,virtual,cube map shading performance. This provides a good starting point when adding shadows, as the number of lights that require shadow com- putations is already close to the minimal set. Moreover, clustered 1 Introduction shading provides true 3D bounds around the samples in the frame buffer and therefore can be viewed as a fast voxelization of the In recent years, several techniques have been presented and refined visible geometry. Thus, as we will see, clusters provide opportuni- that enable real-time performance for applications such as games ties for efficient culling of shadow casters and allocation of shadow using hundreds to many thousands of lights. These techniques resolution. work by binning lights into tiles of various dimensionality [Olsson and Assarsson 2011; Harada 2012; Olsson et al. 2012]. Many simultaneous lights enable both a higher degree of visual quality and 1.1 Contributions greater artistic freedom, and these techniques are therefore directly applicable in the games industry [Swoboda 2009; Ferrier and Coffin We contribute an efficient culling scheme, based on clusters, which is 2011; Persson and Olsson 2013]. used to render shadow-casting geometry to many cube shadow maps. We demonstrate that this can enable real-time rendering performance However, this body of previous work on real-time many-light algo- using shadow maps for hundreds of lights, in dynamic scenes of rithms has studied almost exclusively lights that do not cast shadows. high complexity. While such lights enable impressive dynamic effects and more de- tailed lighting environments, they are not sufficient to capture the We also contribute a method for quickly determining the required resolution of the shadow maps. This is used to show how hardware- ∗e-mail:[email protected] supported virtual shadow maps may be efficiently implemented. To this end, we also introduce a very efficient way to determine the parts of the virtual shadow map that need physical backing. We demonstrate that these methods enable the memory requirements to stay within a limited range, while enabling uniform shadow quality. Additionally, we explore the performance of ray tracing for many lights. We demonstrate that a hybrid approach, combining ray trac- ing and cube maps, offers high efficiency, in many cases better than using either shadow maps or ray tracing individually. 2. Cluster assignment – calculating the cluster keys of each view sample. We also contribute implementation details of the discussed methods, showing that shadow maps indeed can be made to scale to many 3. Find unique clusters – finding the compact list of unique cluster lights. Thus, this paper provides an important benchmark for other keys. research into real-time shadow algorithms for many lights. 4. Assign lights to clusters. – creating a list of influencing lights for each cluster. 2 Previous Work 5. Select shadow map resolution for each light. Real Time Many Light Shading Tiled Shading is a recent tech- 6. Allocate shadow maps. nique that supports many thousands of lights in real-time applica- tions [Swoboda 2009; Olsson and Assarsson 2011; Harada 2012]. 7. Cull shadow casting geometry for each light. In this technique, lights are binned into 2D screen-space tiles that 8. Rasterize shadow maps. can then be queried for shading. This is a very efficient and sim- ple process, but the 2D nature of the algorithm creates a strong 9. Shade samples. view dependence, resulting in poor worst case performance and unpredictable frame times. 3.1 Clustered Shading Overview Clustered Shading extends the technique by considering 3D bins in- In clustered shading the view volume is subdivided into a grid of stead, which improves efficiency and robustness [Olsson et al. 2012]. self-similar sub-volumes (clusters), by starting from a regular 2D The clusters provide a three-dimensional subdivision of the view grid in screen space, e.g. using tiles of 32 × 32 pixels, and splitting frustum and, thus, sample groupings with predictable bounds. This exponentially along the depth direction. Next, all visible geometry provides a basic building block for many of the new techniques de- samples are used to determine which of the clusters contain visible scribed in this paper. See Section 3.1, for a more detailed overview. geometry. Once the set of occupied clusters has been found, the algo- rithm assigns lights to these, by intersecting the light volumes with Shadow Algorithms Studies on shadowing techniques generally the bounding box of each cluster. This yields a list of cluster/light present results using a single light source, usually with long or pairs, associating each cluster with all lights that may affect a sam- infinite range. Consequently, it is unclear how these techniques scale ple within (see Figure2). Finally, each visible sample is shaded by to many light sources, whereof a large proportion cover only a few looking up the lights for the cluster it is within and summing their samples. For a general review of shadow algorithms, see Eisemann contributions. et. al. [2011]. Geometry Occupied Cluster C0 Virtual Shadow Maps Software-based virtual shadow maps have been explored in several publications to achieve high quality shad- Y ows in bounded memory [Fernando et al. 2001; Lefohn et al. 2007]. C Eye 1 Recently, API and hardware extensions have been introduced that L0 -Z makes it possible to support virtual textures much more conveniently C2 and with performance equalling that of traditional textures [Sellers Near L1 et al. 2013]. C3 Cluster/Light Pairs: C L C L C L C L … Far Many light shadows There does exist a corpus of work in the 1 0 2 0 2 1 3 1 field of real-time global illumination, which explores using many Figure 2: Illustration of the depth subdivisions into clusters and Imperfect Shadow light sources with shadow casting, for example light assignment. Clusters containing some geometry are shown in Maps Many-LODs [Ritschel et al. 2008], and [Hollander et al. 2011]. blue. However, these techniques generally assume that a large number of lights affect each sample to conceal approximation artifacts. In other words, these approaches are unable to produce accurate shadows for The key pieces of information this process yields are a set of occu- samples lit by only a few lights. pied clusters with associated bounding volumes (that approximate the visible geometry), and the near-minimal set of lights for each cluster. Intuitively, this information should be possible to exploit for Ray Traced Shadows Recently, Harada et. al. [2013] described efficient shadow computations, and this is exactly what we aim to ray traced lights in conjunction with Tiled Forward Shading. They do in the following sections. demonstrate that it can be feasible to ray trace shadows for many lights but do not report any analysis or comparison to other tech- niques. 3.2 Shadow Map Resolution Selection One way to calculate the required resolution for each shadow map 3 Basic Algorithm is to use the screen-space coverage of the light-bounding sphere. However, this produces vast overestimates whenever the camera Our basic algorithm is shown below. The algorithm is constructed is near, or within, the light volume. To calculate a more precisely from clustered deferred shading, with shadow maps added. Steps matching resolution, one might follow the approach in Resolution that are inherited from ordinary clustered deferred shading are shown Matched Shadow Maps (RMSM) [Lefohn et al. 2007], using shadow- in gray. map space derivatives for each view sample. However, applying this na¨ıvely would be expensive, as the calculations must be repeated for 1. Render scene to G-Buffers. each sample/light pair, and would require derivatives to be stored Cluster the shadow map we must commit physical memory for those pages that will be sampled during shading.