• No results found

ANALYTIC METHOD

Part III Image Space

ANALYTIC METHOD

In this method, the derivative is no longer computed in the split-specific texture space because it will cause the wrong LOD selection, as previously explained. The idea of this method is based on the observation that there’s obviously no problem for hardware to compute derivatives when using a single shadow map texture. For a given shadow map in CSMs, as long as we can find the relationship between the derivatives in standard shadow mapping (for the whole view frustum) and the derivatives in the texture space of the given shadow map (for a split), the correct split-specific derivatives should be derivable from the former. This idea is illustrated by Figure 4.1.14. On the other hand, it’s very easy to tell there’s only a scale difference between the derivatives in the two texture spaces. In Figure 4.1.14, you can easily tell there’s a difference of translation and scale between the texture coordinates

(for the whole view frustum) and u (for the split only).

Therefore, the difference between the derivatives and

(remember this is what we want) is a scale ratio. The corresponding pseudo code is illustrated in Listing 4.1.7.

FIGURE 4.1.14 Analytic method to compute derivatives.

Listing 4.1.7 Analytic method for computing derivatives

// CONS TANTS

// Refer to [Zhang07], transforming from the texture space for the whole view frustum to the texture space for a specific split only requires a S CALE transformation and a TRANS LATION transformation.

float2 scale; //scale values in x and y dimensions float2 translate; //translation values in x and y dimensions // P IX E L S HADE R

// S tep 1: Take derivatives in standard shadow mapping // NOTE : 'P osLight' stands for the position in light's clip space for the whole view frustum!

float2 LightTexCoord = P S Input.P osLight.xy / P S Input.P osLight.w; //

project texture coordinates

float2 dtdx = ddx(LightTexCoord); //take derivative float2 dtdy = ddy(LightTexCoord); //take derivative

// S tep 2: Apply split-specific scale/translate to texture coordinates and derivatives

scale = scale * float2(0.5, -0.5);

translate = translate * float2(0.5, -0.5) + 0.5;

LightTexCoord = scale * LightTexCoord + translate; //NDC to texture space dtdx *= S cale;

dtdy *= S cale;

Finally, as an optional improvement when you combine CSMs and filtering techniques, you can use a self-adjusting filtering kernel size when using filtering. Ideally, generating a consistent blurring effect over all splits needs a varying kernel size due to the foreshortening effect. Although a small and constant filtering width (e.g., 2×2) can still blur shadows well, a self-adjusted filtering size is necessary in some cases such as when applying warping algorithms into each shadow map. It’s actually very easy to provide such a varying kernel. We just need to scale the original constant filtering width by the ratio of the size of the current split and to the size of whole view frustum from the light’s point of view, as shown inListing 4.1.8.

Listing 4.1.8 Self-adjusted filtering kernel size

// S cale v alues for x and y respectiv ely float scaleX , scaleY ;

// Compute the required scale for the current split in light's postperspectiv e space

// 'maxX ' and 'minX ' stand for the maximum and minimum x v alues respectiv ely.

// 'maxY ' and 'minY ' stand for the maximum and minimum y v alues respectiv ely.

scaleX = 2.0f / (maxX - minX );

scaleY = 2.0f / (maxY - minY );

// Assume the original constant filtering siz e is 2x2 float2 v FilteringKenerlS iz e(2.0f, 2.0f);

// Update the filtering siz e v FilteringKenerlS iz e.x *= scaleX ; v FilteringKenerlS iz e.y *= scaleY ;

CONCLUSION

This chapter has discussed a few practical issues in cascaded shadow maps (CSMs). For each of these issues, we have analyzed the cause and subsequently presented the solutions. We hope the methods presented in this article can help developers improve their CSM implementations and motivate further research on this topic.

ACKNOWLEDGMENTS

Thanks to Sam Martin for his valuable review comments. Thanks to David Lam, Andrew Lauritzen, Adrian Egli, Oskari Nyman, and Marco Salvi for their early reviews. Special thanks to David Lam for his patient and careful proofreading, and to Andrew Lauritzen for insightful suggestions and sample code and for inspiring the second method for the filtering issue.

REFERENCES

[Akenine02] Thomas Akenine-Moller and Eric Haines. Real-Time Rendering (2nd Edition). A. K. Peters Limited, 2002.

[Annen07] Thomas Annen, Tom Mertens, Philippe Bekaert, Hans-Peter Seidel, and Jan Kautz. “Convolution Shadow Maps.” In Proceedings of the Eurographics Symposium on Rendering 2007, pp. 51–60.

[Annen08] Thomas Annen, Tom Mertens, Hans-Peter Seidel, Eddy Flerackers, and Jan Kautz. “Convolution Shadow Maps.” In Proceedings of Graphics Interface 2008, pp. 155–161.

[Donnelly06] William Donnelly and Andrew Lauritzen. 2006. “Variance Shadow Maps.” In Proceedings of the Symposium on Interactive 3D Graphics and Games 2006, pp. 161–165.

[Engel06] Wolfgang Engel. “Cascaded Shadow Maps.” ShaderX5, edited by Wolfgang Engel. Charles River Media, 2006, pp. 197–206.

[Forsyth05] Tom Forsyth. “Shadowbuffer Frustum Partitioning,” ShaderX4, edited by Wolfgang Engel. Charles River Media, 2005, pp.

289–297.

[Isidoro05] John R. Isidoro. “ Filtering Cubemaps - Angular Extent Filtering and Edge Seam Fixup Methods,” Siggraph’05 Sketch Presentation, 2005. (also available at http://ati.amd.com/developer/SIGGRAPH05/Isidoro-CubeMapFiltering.pdf).

[Lauritzen07a] Andrew Lauritzen. “Parallel-Split Variance Shadow Maps,” In Proceedings of Graphics Interface 2007 (poster).

[Lauritzen07b] Andrew Lauritzen. “Summed-Area Variance Shadow Maps.” GPU Gems3, edited by Hubert Nguyen. Addison Wesley.

2007, pp. 157–182.

[Lauritzen08] Andrew Lauritzen and Michael McCool. “Layered Variance Shadow Maps,” In Proceedings of Graphics Interface 2008, pp. 139–146.

[Lloyd06] Brandon Lloyd, David Tuft, Sung-Eui Yoon, and Dinesh Manocha. 2006. “Warping and Partitioning for Low Error Shadow Maps.” In Proceedings of the Eurographics Symposium on Rendering 2006, pp. 215–226.

[Martin04] Tobias Martin and Tiow-Seng Tan. “Anti-Aliasing and Continuity with Trapezoidal Shadow Maps.” In Proceedings of the Eurographics Symposium on Rendering 2004, 2004, pp. 153–160.

[Reeves87] William Reeves, David Salesin, and Robert Cook. “Rendering Antialiased Shadows with Depth Maps.” In Computer Graphics (Proceedings of SIGGRAPH 1987), 1987, 21(3), pp. 283–291.

[Salvi07] Marco Salvi. “Rendering Filtered Shadows with Exponential Shadow Maps.” ShaderX6, edited by Wolfgang Engel. Charles River Media, 2007, pp. 257–274.

[Stamminger02] Marc Stamminger and George Drettakis. “Perspective Shadow Maps.” In Proceedings of SIGGRAPH 2002, 2002, pp.

557–562.

[Valient07] Michal Valient. “Stable Rendering of Cascaded Shadow Maps,” ShaderX6, edited by Wolfgang Engel. Charles River Media, 2007, pp. 231–238.

[Williams78] Lance Williams. “Casting Curved Shadows on Curved Surfaces.” In Computer Graphics (Proceedings of SIGGRAPH 1978) 12(3), 1978, pp. 270–274.

[Wimmer04] Michael Wimmer, Daniel Scherzer, and Werner Purgathofer. “Light Space Perspective Shadow Maps.” In Proceedings of the Eurographics Symposium on Rendering 2004, pp. 143–152.

[Zhang06] Fan Zhang, Hanqiu Sun, Leilei Xu, and Lee Kit Lun. “Parallel-Split Shadow Maps for Largescale Virtual Environments,” In Proceedings of the 2006 ACM International Conference on Virtual Reality Continuum and Its Applications (VRCIA’2006), 2006, pp.

311–318.

[Zhang07] Fan Zhang, Hanqiu Sun, and Oskari Nyman. “Parallel-Split Shadow Maps on Programmable GPUs.” GPU Gems3, edited by Hubert Nguyen. Addison Wesley. 2007, pp. 203–237.

4.2 A Hybrid Method for Interactive Shadows in Homogeneous Media

CHRIS WYMAN AND SHAUN RAMSEY

INTRODUCTION

For many applications both realism and interactivity are vital, yet attempts to improve one often come at the cost of the other. To make interactive realism tractable, a variety of simplifications are commonplace. For instance, materials are often assumed to be ideally diffuse, light emission only occurs from idealized point lights, and this light only interacts on the surface of scene geometry.

Clearly, these simplifications rule out many common environments, and recent research and development has focused on identifying other, less severe approximations that would allow interactive rendering in more complex scenes.

In the case of participating media, where light interacts not only with surfaces but also with particles inside a volume, rendering APIs such as OpenGL and DirectX have long included ad hoc approximations that fade geometry as a function of distance. This approach is amenable to hardware acceleration, allowing the rendering of reasonably plausible fog at virtually no cost. Unfortunately, this method lacks many behaviors of participating media, as computations still occur only at surfaces. In particular, the glow around light sources and the ubiquitous light shafts, or “god rays,” that appear on cloudy days are not possible.

Recent research has developed additional techniques that solve some of these problems. Work in cloud rendering has long considered a variety of scattering effects, though these approaches typically consider only this special case of participating media.

Another avenue of research has developed participating media models largely independent of illumination or visibility concerns. Two examples of this are the Hoffman and Preetham [Hoffman03] and Sun et al. [Sun05] models, which provide much more realistic scattering than the DirectX and OpenGL vertex fog approximations yet come at only a small additional cost. While models such as these capture scattering effects such as glows near light sources, they generally assume that lights are always visible throughout the volume and thus cannot generate light shafts.

This article proposes a method to augment these models to allow light shafts, or alternatively their inverse, shadow shafts. Our approach uses a hybrid GPU ray-marching technique augmented by shadow volumes to accelerate ray marching and eliminate aliasing inherent in sampling light along a ray. The idea is to combine two techniques used to render realistic shadow shafts: ray marching [Imagire07] and shadow volumes [Biri06, James03]. Our results, shown in Figure 4.2.1, give real-time believable volumetric shafts from complex objects.

In the rest of this article, we first give a brief overview of participating media and existing single-scattering models used in interactive rendering. We then introduce our hybrid in a simplified environment using point light sources, followed by an extension to allow the use of textured spotlights. Implementation details and a discussion of the results round out the chapter.

FIGURE 4.2.1 Interactive volumetric light shafts and shadows rendered at up to 80 frames per second using our hybrid approach. The fairy forest uses a white point light. The other two scenes use textured lights where the inset shows the texture

used.

PARTICIPATING MEDIA REVIEW

To understand the rationale for our hybrid, we first review single-scattering approximations for participating media, such as Sun et al.

[Sun05], and then discuss how these models interact with ray marching and shadow volume techniques.

When light interacts with volumetric media, multiple particles of different sizes, orientations, and material properties may absorb, scatter, or reflect the light before it reaches our eyes. In many environments these particles can be safely ignored, effectively assuming the media has no effect on transient light. While this is a reasonable assumption in some settings, the increasing desire to render scenes with complex atmospheric effects and to include depth cues gained by accounting for scattering suggests more complex models are necessary. To relax this approximation without excessive additional computation, people often restrict light to scatter no more than once along its path. With this approach, the paths of light look similar to the dark path shown in Figure 4.2.2.

From the eye to point S, at every distance x there is some probability that light scatters toward the eye from the direction of the light.

As we assume light only scatters once, this reflected light reaches the eye without further scattering.

FIGURE 4.2.2 Important paths of light in single-scattering participating media. ds and dl are the distances from the eye to the

surface and the light, x is the distance to a point on the viewing ray, γ is the angle between the viewing ray and the light direction, and d(x) is the distance from the light to this point.

Using math similar to that proposed by Nishita et al. [Nishita87], the radiance L can be represented in a single-scattering model by:

where Ls is the radiance of the surface at point s, Ka, and Ks are the media’s absorption and scattering coefficients, ρ(α) is its scattering phase function, and I0(x) is the radiance of the light visible at point x. The first term represents the color of the surface attenuated by particles in the air, similar to the color computed via hardware fog models. The second term represents color scattered toward the light by particles in the air.

This integral can be numerically sampled by approximating the integral as a sum. Unfortunately, this requires relatively fine sampling to eliminate aliasing along visibility boundaries. As a ray weaves in and out of volumetric light shafts, sufficient samples must be used to identify every transition. Just as lines in a 2D image become aliased, with some slopes appearing worse than others, shadow volumes in this discretely sampled 3D volume appear aliased when samples on adjacent rays switch from being illuminated to shadowed. Adaptively increasing sampling near shadow boundaries could reduce aliasing reasonably cheaply. Unfortunately, the locations of light shafts in complex and dynamic scenes are unknown a priori, so expensive, uniformly high sampling rates may be necessary to locate all such boundaries.

A different approach uses shadow volumes to identify when eye rays enter and leave shadowed regions. This subdivides the integral into distinct, fully illuminated intervals. For the situation shown in Figure 4.2.3, for instance, the integral above could be divided as:

where

FIGURE 4.2.3 When using shadow volumes, scattering computations can be limited to only illuminated segments of a ray, such as d2d3 and d4d5. However, front- and back-facing shadow volumes must be paired correctly, to avoid incorrectly shading

the left and right cases similarly.

For some illumination models, including [Sun05], each of these integrals can be precomputed and stored to texture, reducing runtime computations to a few texture lookups. This significantly increases rendering performance.

While this method avoids aliasing along shadow boundaries and missing shadow shafts, the shadow volumes must first be sorted to correctly pair front and back faces along each illuminated region and in order to ignore extraneous, completely shadowed polygons, such as those in Figure 4.2.3. While depth-peeling techniques can sort shadow polygons, shadow volumes for complex geometry can have arbitrarily high depth complexity, leading to arbitrarily large numbers of depth-peeling passes.