COMPUTER ANIMATION AND VIRTUAL WORLDS Comp. Anim. Virtual Worlds 2008; 19: 553–567 Published online 20 June 2008 in Wiley InterScience (www.interscience.wiley.com) DOI: 10.1002/cav.228
........................................................................................... Generalized minimum-norm perspective shadow maps By Fan Zhang* , Hanqiu Sun, Chong Zhao and Lifeng Wang
.......................................................................... Shadow mapping has been extensively used for real-time shadow rendering in 3D computer games, though it suffers from the inherent aliasing problems due to its image-based nature. This paper presents an enhanced variant of light space perspective shadow maps to optimize perspective aliasing distribution in possible general cases where the light and view directions are not orthogonal. To be mathematically sound, the generalized representation of perspective aliasing errors has been derived in detail. Our experiments have shown the enhanced shadow quality using our algorithm in dynamic scenes. Copyright © 2008 John Wiley & Sons, Ltd. Received: 19 December 2007; Accepted: 16 April 2008 KEY WORDS:
image-based rendering; shadow algorithms; computer games
Introduction Shadowing effects are very important for the realism of virtual scenes in 3D computer games, which significantly enhance players’ perception of the surrounding environment with useful depth clues. For game developers, the reality that they are facing is that the commonly used shading models do not directly support the global illumination effects like shadows. Shadow mapping1 is one of the most popular dynamic shadowing techniques. Unlike object-based approaches such as shadow volumes,2 this image-based approach has no restriction on the type of geometric primitives, and requires only one extra rendering pass per light. Such generality and efficiency make shadow mapping extensively adopted in 3D games. There are two rendering passes involved in shadow mapping. In the first pass, the scene is rendered into the shadow map texture from the light’s point of view. In the second pass, the scene is rendered from the eye’s point of view. For each point being rendered, it is transformed into the light’s coordinates again for depth comparison. If the corresponding depth value in shadow map is less than that of the transformed point, this point is shadowed.
*Correspondence to: F. Zhang, Department of Computer Science and Engineering, The Chinese University of Hong Kong, Shatin N.T., Hong Kong, China. E-mail:
[email protected]
The major problem when using shadow mapping is the aliased shadow boundaries mainly caused by insufficient texture resolution. Numerous anti-aliasing approaches have been proposed during the past decade. A main research line is termed perspective reparameterizations (PRs) that address the reduction of perspective aliasing errors.3 We have a note here, to keep consistent with the naming convention in Reference [4], we use the term “perspective reparameterization” instead of “perspective shadow maps” in this paper. The two terms are usually exchangeable in this research line. The basic idea behind typical PRs3,5,6 is to reparameterize shadow maps by applying a perspective warping transformation to both the scene and light, as visualized in Figure 1. The motivation is that perspective aliasing errors are independent of local geometry details, and the sampling density at the light in the post-transformed space better accommodates the requirements for the reconstruction of shadowed images. All PR techniques mainly exploit two factors: the near-plane distance of the warping frustum and the warping direction. The essential difference among variant PRs is the selection of the first factor, because the near plane distance of the warping frustum determines how strong the warping effect is. For example, the warping strength in light space perspective shadow maps (LiSPSMs)5 is adjusted to equalize errors at depth boundaries. On the other hand, the selection of the second factor strongly influences the implementation complexity. With an inappropriate warping direction, the frequently changed types of lights after applying the
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
F. ZHANG ET AL.
...........................................................................................
Figure 1. A schematic illustration of perspective reparameterizations, where V and W stand for the eye’s view frustum and warping frustum, respectively. Both V and the light are transformed into W’s post-perspective space in which the shadow map is generated. perspective transform may cause mapping singularities. For example, the warping direction in LiSPSMs is chosen to be in parallel with the shadow plane in order to avoid producing mapping singularities. It greatly simplifies the implementation and analysis. There’s a major limitation existed for most of currently existed PRs,3–8 which results from the representation of aliasing they used. The aliasing errors are previously approximated in a static scenario only, where the light and view directions are orthogonal and termed the ideal case. Because the angle between the light and view directions isn’t taken into account by this direction-independent approximation, the resultant warping transformation cannot produce the expected aliasing distribution for a general light-view configuration in dynamic scenes. For example, although the warping strength in LiSPSMs does vary as the light is tiled towards the viewer to stimulate the degeneration to standard shadow maps, the aliasing distribution along the view direction is not equalized at the depth boundaries anymore. Likewise, the analysis results of the ideal case5,9 are hard to be directly used to quantitatively analyze errors in general cases. In this paper, the term general case refers to the arbitrary light-view configuration.
Main Contributions The main contributions of this paper include: (1) We present a detailed derivation of the generalized representation of aliasing errors in PR techniques.
Although a similar result has been mentioned by Zhang et al.,4 a mathematical derivation is somehow missed. As a further improvement, the representation in this paper is explicitly parameterized without introducing any proxy values. As a special study case, Figure 4 visualizes how the generalized representation unifies variant aliasing distributions in the ideal case. Notice that, unlike the similar results presented by Michael et al.,5 this figure for the first time plots how errors are distributed in trapezoidal shadow maps (TSMs).6 Furthermore, in this paper, we extend the analysis to both screen dimensions (see Eqs (10) and (24)) for better understanding and quantifying errors in general cases. (2) We propose the generalized minimum-norm perspective reparameterization (GMNPR) to exemplify the applications of the aliasing representation. This algorithm generalizes LiSPSMs in general cases with two advantages: (i) GMNPR stabilizes the optimal aliasing distribution in possible general cases. Such direction-invariant feature (partially) preserves the optimized shadow quality for dynamic scenes. (ii) GMNPR inherits the flexibility of LiSPSMs. The warping directions in both methods are the same. We thus don’t need special treatments such as the “inverse perspective matrix”7 for the mapping singularity problem in the post-perspective space. The remainder of the paper is organized as follows: we first review related work and then formulate the
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
554
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
MINIMUM-NORM PERSPECTIVE SHADOW MAPS ...........................................................................................
generalized representation of aliasing errors. Based on this representation, we derive and analyze our GMNPR in a purely mathematical view. We subsequently present the experimental results to show enhanced shadow rendering using our algorithm. Finally, we give the conclusion and further work.
Previous Work The literature on real-time shadow rendering is vast and far beyond the scope of this paper. Here we focus our review on most relevant work in solving the aliasing problem of shadow mapping. The exhausted survey and review of shadow rendering algorithms refer to References [10,11]. PRs refer to the algorithms that reparameterize the shadow map by warping the texel distribution on the shadow plane with a perspective transformation. The first PR was introduced in the perspective shadow maps (PSMs),3 in which both the scene and light source are transformed to the post-perspective space of the view frustum. The shadow map is generated in this space by rendering a view from the transformed light source. Special treatments are needed when implementing PSMs.7 Although the shadow quality is significantly increased at the regions near the viewer, the warping strength is usually over-strong such that under-sampling happens for distant objects. LiSPSMs5 avoid the complicated lighttransformation in PSMs by using the warping direction in parallel with the shadow plane. The equalized aliasing distribution over the depth range produces better shadow quality at both near and distant regions. TSMs6 are designed to reduce aliasing errors for “important” objects in the view frustum. This algorithm first calculates a 2D trapezoidal approximation of the view frustum as seen from the light. The warping transformation is then selected by the “κ-ξ rule”. The focus region in the view frustum, the frusta truncated at the distance κ to the near plane, is mapped to the y = ξ line on the shadow plane. A typical setting is κ = 50%, ξ = 80%. Chong et al.8 tilt the shadow plane using a generalized projection transformation based on a few user-specified planes. This approach guarantees perfect sampling for the objects lie on these planes. However, such oblique shadow plane cannot be globally optimal for the whole scene. Adaptive shadow maps (ASMs)12 reduce aliasing by storing the shadow map as a hierarchical grid. By evaluating the contribution of each shadow map texel to the overall image quality, the grid is refined to create higher resolution at regions that contain shadow boundaries.
Artifacts at those critical regions are thus greatly reduced without requiring a “flat” shadow map of huge resolution. However, the traversal and refinement operations require many rendering passes and aren’t feasible for real-time applications. A GPU-accelerated implementation of ASMs was lately presented by Lefohn et al.13 Partitioning algorithms9,14–16 improve the shadow quality using multiple shadow maps, but with requiring multiple rendering passes. Like this paper, the paper in Reference [9] also presents an analysis of PRs. However, the analysis mainly addresses the ideal case. Hybrid techniques17–21 combine shadow volumes2 and shadow mapping to achieve a better tradeoff between the performance and shadow quality. Although hybrid techniques take the merits of both image-space and objectspace methods, they also inherit drawbacks of both approaches at the same time. Shadow Silhouette Maps22 significantly reduce jagged shadow boundaries by exploiting a representation of the scene’s silhouette, but artifacts can be introduced as the representation stores of only one silhouette point in each shadow map texel. In compressed shadow maps (CSMs),23 the lit surfaces are represented by endpoints of intermediate line segments to reduce the memory assumption. However, the shadow map generation cannot be accelerated by current graphics hardware because the read-back operations are required. Percentage closer filtering (PCF)24 extends the concept of classical bilinear filtering used in texture sampling to help anti-aliasing around shadow boundaries. As a recent improvement of PCF, variance shadow maps (VSMs)25 calculate the variance over any filter region by storing the mean and mean squared of distribution of depths. A better approximation to the true occlusion can be derived by using this variant. The irregular sampling strategy can be implemented in software rendering systems to enable aliasing-free shadow maps.26,27 Shadow quality is usually improved by focusing shadow map on visible objects.28,29 Algorithms30–32 are proposed to address the problem of incorrect self-shadowing due to discrete depth quantization.
Representation of Aliasing Errors The central idea of this paper comes from analyzing the aliasing representation, we thus introduce the related theory in this section. We first formulate the generalized representation of perspective aliasing
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
555
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
F. ZHANG ET AL.
...........................................................................................
Figure 2. Definition of frequently used notations. errors in shadow mapping, then show how this representation quantifies aliasing errors for different reparameterizations in a unified way. Definition of frequently used notations in our derivation are listed in Figure 2.
General Cases Figure 3 shows the computational model used in this paper and LiSPSMs, in which the warping frustum is constructed in the light space defined by Wimmer et al.5 Without loss of generality, we assume the field-of-view angles in the x and y directions are the same. For simplicity, the computational model assumes that the light is directional and moves on the yz plane. The t and s directions of the shadow map are aligned with xl and zl , respectively. The light beams through a texel with the size ds (in the z direction) fall on a surface with the length dz in world space. Here, the local parameterization of the shadow map s(z) assumes that the shadow map is accurately focused on the view frustum and no resolution is wasted on invisible parts of the scene. The size of view beams dp on the normalized screen projected from the surface is dy/z tan φ. α and β denote the angles between the surface normal and vector to the screen and shadow map plane, respectively. By restricting the small surface on the z direction, we have dy ≈ dz cos α/ cos β. The aliasing error F for the small surface is then defined as F=
dp 1 dz cos α = ds tan φ zds cos β
(1)
The above aliasing representation can be divided into two parts: (1) perspective aliasing: dz/zds, and (2) projection aliasing: cos α/ cos β. Shadow map under-sampling occurs when perspective aliasing or projection aliasing becomes large. Projection aliasing happens for surfaces that are almost parallel to the light direction. Since projection aliasing is heavily related to the geometrical details, the local increase of sampling densities on such surfaces is required to reduce this type of aliasing. Thus, an expensive scene analysis at each frame is needed such that the hardware-acceleration is forced. On the other hand, perspective aliasing comes from the perspective foreshortening effect and can be reduced by warping the texels on the shadow plane by using a global transformation. PRs generate shadow maps in the post-perspective space of the warping frustum to cancel out the foreshortening effect introduced by the view frustum. Since the perspective warping transformation enlarges the objects close to the viewer and shrinks the distant objects, perspective aliasing is significantly reduced. Due to the symmetry, we only need to consider 0 ≤ θ ≤ π. Furthermore, since θ can be replaced by π − θ in our computation when θ > π/2, we suppose 0 ≤ θ ≤ π/2 from now on. The shadow map parameterization s = s(z) is induced by applying the perspective warping transformation W. By ignoring the projection aliasing, the aliasing error F in Eq. (1) is then simplified into (= ˙ means ignoring projection aliasing), dp 1 dz 1 1 1 = ˙ = ds tan φ zds tan φ z ds(z)/dz 1 1 1 = tan φ z s (z)
F=
(2)
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
556
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
MINIMUM-NORM PERSPECTIVE SHADOW MAPS ...........................................................................................
Figure 3. Formulation of the generalized representation F(λ, θ, z). Left: φ < θ ≤ π/2. Right: 0 ≤ θ ≤ φ.
In Figure 3, every point (x, y, z) in the view space is first transformed to (xl , yl , zl ) in the light space, then projected to (xt , yt , zt ) in W’s post-perspective space and finally transformed to 2D texture coordinates (t, s) in the shadow map space. In the following derivation, the y coordinate is ignored because we mainly analyze the t and s coordinates. From the side view and light’s view
in Figure 3, we have xl = x
zl =
z−n+
φ n tan tan θ
(3) sin θ + Wn
θ ∈ [φ,
π ] 2
(f tan φ − (f − z) tan θ) cos θ + Wn θ ∈ [0, φ]
(4)
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
557
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
F. ZHANG ET AL.
...........................................................................................
Wf − W n =
φ φ n tan + f − n + f tan sin θ θ ∈ [φ, π2 ] tan θ tan θ
θ ∈ [0, φ]
2f tan φ cos θ
(5)
Most of previous work only addresses the ideal case where zl = z. On the contrary, with the simplifications used in our computational model, we derived an analysis of the aliasing distribution in general cases where zl = z. From the projection matrix in Direct3D and texture matrix in shadow mapping, the calculation for subsequently transformed coordinates are directly given below:
2Wn n tan φ
0
0
Wf Wf −Wn
0
W T − Wf f−Wn n
(xt zt 1) = (xl zl 1)
1
0
2
0
0
1
(6)
0
(t s) = (xt zt 1) 0
1
0
1 2
0
1
(7)
The light’s view in Figure 3 gives
f tan φ Wf
θ ∈ [φ, π2 ]
f tan φ Wn
θ ∈ [0, φ]
tan φ =
(8)
To facilitate the comparison of the aliasing distribution in different scene configurations, we consider the aliasing problem in the normalized view frustum by introducing the following parameterization: λ=
Wn Wf − Wn
(9)
Note the standard shadow mapping approach can be treated as a PR by using a special transform in which λ = ∞ (no perspective warping). Plugging s(z) derived from Eqs (3–9) into Eq. (2), F can be represented as the following factorization: F(λ, θ, z) = ˙
With the assumptions used in our computational model, F(λ, θ, z) gives us a general representation of the aliasing distribution in the view direction in different reparameterizations. In comparison with other simplified representations5,9 which only handle the ideal case, our direction-dependent representation enables us to quantify the aliasing errors at arbitrary θ values. Note that though this representation was first introduced by Zhang et al.,4 they did not provide derivation details. More importantly, this paper extends the above derivation to the x direction as well, which enables us to take into account errors in both z and x directions instantaneously. Next we illustrate how F(λ, θ, z) unifies aliasing representations in different PR techniques including standard shadow maps (SSMs), PSMs, LiSPSMs, and TSMs. To compare with the result presented by Wimmer et al.,5 the situation in the ideal case (θ = π/2) is considered. Without surprising, the two results should be the same because the analysis in Reference [5] is simply a special case of our representation. Furthermore, as an interesting supplement, we first plot the aliasing distribution in TSM which is not included in Reference [5].
1 1 1 (z + ψ2 (λ, θ))2 = ψ1 (λ, θ) tan φ z s (z) z
Ideal Case In PR techniques, the only free parameter λ in Eq. (10) is selected according to specific constraints, in order to produce the expected warping effects. For examples, the “linear” constraint in PSM results in a linear aliasing distribution over the depth range. The constraint in LiSPSM makes the maximum errors “minimal with respect to the L∞ norm”. The focus-driven constraint in TSM requires the user-specified region to occupy the majority of the shadow map resolution. An important note here is that we won’t claim which one of them is the best in this paper because each of them cannot be suitable for all applications. In practice, the λ parameter usually has to be tweaked for satisfactory rendering results. SSM can be regarded as a special PR by using a warping frustum with λ = ∞.
(10) FSSM = F(∞, π/2, z) =
where,
ψ1 (λ, θ) =
1 tan φ
1 φ f −n+(f +n) tan tanθ
1 tanθ 1 tan φ 2fλ(λ+1) tan φ
ψ2 (λ, θ) =
λ(λ+1)
tan φ
θ ∈ [0, φ]
φ −f f (2λ + 1) tan tan θ
(11)
It means that the perspective errors of SSM increase hyperbolically as the object moves closer to the view plane. n Because W = V in PSM, λPSM = f −n . Hence,
θ ∈ [φ, π2 ]
φ f − n + (f + n) tan θ λ + n tan −n tan θ
1 (f − n) tan φ z
θ ∈ [φ, π2 ] θ ∈ [0, φ]
FPSM = F
n , π/2, z f −n
=
1 f −n z tan φ fn
(12)
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
558
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
MINIMUM-NORM PERSPECTIVE SHADOW MAPS ...........................................................................................
which means the aliasing distribution in PSM is a linear function with respect to z. LiSPSM is designed to minimize the maximum error in terms of the L∞ norm. Since F achieves maximal at boundaries of the depth range, λLiSPSM should satisfy F(λLiSPSM , π/2, n) = F(λLiSPSM , π/2, f ) which gives
λLiSPSM
√ n + fn = f −n
The maximum of L∞ (F), denoted as L∞ max (F), is then
L∞ max (F)
= F(λLiSPSM , π/2, n) =
Figure 4. The aliasing distributions in different reparameterizations in the ideal case. n √ = 1, f = 100, and φ = π/6. A scale 1/ 3 is used.
n (f − n). f
Algorithm The aliasing distribution in LiSPSM is FLiSPSM = F(λLiSPSM , π/2, z) √ √ √ 1 (z + fn)2 f− n √ √ = √ tan φ fn( f + n) z
(13)
TSM maps the focus point pκ with the depth value zκ = n + (f − n)κ to a point on the s = ξ line on the shadow plane. Solving s(zκ ) = ξ by using Eqs (3–9), we have λTSM =
(1 − ξ)κ ξ−κ
and FTSM = F
(1 − ξ)κ ξ−κ
r Stabilize the optimal aliasing distribution in possible
general cases.
r Converge to standard shadow maps as the light direc-
, π/2, z
z + (f − n) (1−ξ)κ −n (ξ − κ)2 ξ−κ = tan φ(f − n)(1 − ξ)(1 − κ)ξκ z
2
tion goes to parallel with the view direction.
(14)
In particular, for the typical settings κ = 0.5 and ξ = 0.8 in TSM,
λTSM
1 = 3
FTSM
As the light direction goes to parallel with the view direction, the available depth range affected by the warping frustum decreases accordingly. In other words, the warping strength decreases as θ goes small. This requires λ to be direction-adaptive to satisfy the application-specific constraint. With the representation in Eq. (10), users are capable of designing the direction-adaptive λ(θ) to produce the expected warping strength in the general case. Although λLiSPSM also takes into account θ, as we explain later, it actually equalizes the aliasing distribution only in the ideal case. Based on the observations above, we propose the GMNPR to satisfy the following two requirements:
z + f −4n 1 9n 3 = tan φ 4(f − n) z
2 (15)
Figure 4 plots the aliasing distributions in different reparameterizations.
There’s nearly no difference for implementing and applying GMNPR in comparison with LiSPSMs, except for the λ selection in the warping frustum which controls the warping strength. In the following, we thus focus on deriving appropriate λ values to produce the equalized aliasing distribution for dynamic scenes. In mathematical sense, we can define variant norms. Like LiSPSMs, GMNPR is designed to minimize the L∞ norm of errors. Once given λ and θ, Eq. (10) shows that F(z) has a single positive local extremum (a minimum)
−1
φ φ at the location z = n 1 − tan f − n + (f + n) tan . tan θ tan θ ∞ Therefore, the maximum L (F) is achieved at the
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
559
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
F. ZHANG ET AL.
...........................................................................................
boundaries of the depth range. Let L∞ max (F) be the maximum L∞ (F) within [n, f ]. Minimizing L∞ max (F) requires that the errors at near and far planes are equal, or F(λ, θ, n) = F(λ, θ, f )
(16)
The above maxima can be directly calculated from Eq. (10) as follows:
r Case 1: If φ ≤ θ ≤ π/2,
2 f − n + (f + n) tanφ tanθ (λ + µ) F(λ, θ, n) = n tan φ λ(λ + 1)
F(λ, θ, f ) = µ=
f − n + (f + n) tanφ tanθ f tan φ
n tanθ (f − n) tanφ +f +n
ν=1 −
(λ + ν)2 λ(λ + 1)
Figure 5. Adjustment of the λGMNPR selection in practice.
f tanθ (f − n) tanφ +f +n
r Case 2: If 0 ≤ θ ≤ φ, F(λ, θ, n) = µ=
2 (λ + ν)2 2f (λ + µ)2 F(λ, θ, f ) = ntanθ λ(λ + 1) tanθ λ(λ + 1)
1 f − n tanθ − 2 2f tanφ
ν=
1 2
r Smooth transition of shadow qualities at θ = φ.
Note the singularity at θ = φ may result in the discontinuous transition of shadow qualities in practice. To avoid this problem, the continuous λ transition at θ = φ should be satisfied. λ∗2 (φ) = λ1 (φ)
(18)
r Convergence to SSM as θ goes to 0.
Leading the above results to Eq. (16) gives the optimal λ selection, λ1 (θ) = ν−µ λ= √ − µ= f/n − 1 λ2 (θ) =
replace λ2 by a positive function λ∗2 which should satisfy the following two criteria:
(n+
√
tanφ
fn)−n tanθ
θ ∈ [φ, π2 ]
tanφ f −n+(f +n) tanθ
√
f + fn tanθ 2f tanφ
−
1 2
θ ∈ [0, φ] (17)
Now let’s consider the critical angle θ = φ. Figure 5 plots λ against θ. We can see that λ decreases slowly as θ goes from π/2 to φ, thus the perspective warping effect becomes stronger. At the singularity θ = φ, λ takes a nose-dive and rapidly plunges towards 0, which reaches well for λ > 0. But λ = 0 is obviously disastrous, as it practically concentrates the whole shadow map into one texel. Due to the fact that the perspective projection is a hyperbolic mapping, the depth region [λ ≤ z ≤ 2λ] occupies about half of the depth range [0 ≤ s ≤ 0.5] in the post-perspective space. In practice, it’s never a good idea to let λ be too small in any PR, as this introduces strong warping such that the shadow-map texels are usually biased to few pixels in the near plane. Hence, the rapid decrease to zero for λ makes Eq. (17) hard to be used in practice when θ < φ. To avoid this problem, we have to
When θ < φ, from Figure 3, the warping frustum bounds two lines on the far plane of the view frustum. The available depth range distorted by the warping frustum is significantly narrowed. In such cases, PRs should weaken the warping strength in order to avoid the unbalanced distribution of shadow details on the screen. In particular, when θ = 0, all perspective reparameterizations converge to standard shadow maps. lim λ∗2 (θ) = ∞
(19)
θ→0
Many candidates can fulfill Eqs (18) and (19). In our experiments, λ∗2 is chosen to be √ θ fn 1 ∗ θ π = λ2 (θ) = λ1 (φ)/tan (20) 4φ 2f tan 4φ π Substituting Eq. (20) into Eq. (17) gives our final λGMNPR selection as follows: λGMNPR =
λ(1) GMNPR (θ) = λ1 (θ) = ∗ λ(2) GMNPR (θ) = λ2 (θ) =
n+
√
tanφ
fn−n tanθ
tanφ
f −n+(f +n) tanθ
√
fn 1 2f tan( θ π) 4φ
θ ∈ [φ, π2 ] θ ∈ [0, φ] (21)
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
560
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
MINIMUM-NORM PERSPECTIVE SHADOW MAPS ...........................................................................................
Eq. (21) gives us a direction-adaptive λ selection for minimum-norm aliasing distribution, which essentially extends LiSPSMs to general cases. Note that all λ values discussed in this paper are for the warping frustum W with a normalized depth range, namely Wf − Wn = 1, where Wf and Wn represent W’s near-plane and far-plane values, respectively. In LiSPSMs, the near-plane distance of the warping frustum Wn in general cases is approximated as: Wn =
√ n + fn sin θ
By normalizing the depth range of the warping frustum, we have λLiSPSM (θ) =
=
Wn Wf − Wn √
n+sin θfn n+
√
Eq. (17) tells us that the above approximation is not optimal in non-ideal cases (at least for θ > φ). The λ selection in LiSPSM makes F optimal only in the ideal case where θ = π/2. Note that other possible generalized PRs can also be derived from Eq. (10), such as the generalized linear perspective reparamterization (GLPR)4 which requires F(z) ∼ z for given λ and θ values, where ∼ stands for the linear dependency. This reparameterization essentially extends PSMs to non-ideal cases. The main problem of GLPR is that the warping strength might be over-strong in some cases. Our experimental results show the comparison of our GMNPR and GLPR.
Analysis 1 tanφ tanφ (n tanθ +f −n+f tanθ )sinθ
fn 1 sin θ 2f tanφ cos θ
θ ∈ [φ, π2 ] θ ∈ [0, φ] (22)
Figure 6 plots the aliasing distributions in LiSPSM (top row) and GMNPR (bottom row) for the configuration n = 1, f = 100, and φ = π/6. Due to the critical angle θ = φ in Eq. (10), we compare them in the following two aspects:
Figure 6. Aliasing distributions.
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
561
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
F. ZHANG ET AL.
...........................................................................................
Figure 7. Maximum error in F (left), maximum error in G (middle), and storage factor S ∗ (right). A scale log2 is used.
r Non-degenerate cases θ > φ. The aliasing distribution
r
in GMNPR, FGMNPR , is direction-invariant (in terms of minimum-norm) as the θ value changes. The aliasing errors at boundaries of the depth range remain equal for all possible θ values, while FLiSPSM fluctuates with the varying of θ. As θ decreases, the aliasing errors at near regions in LiSPSM increase, but the shape of FGMNPR keeps unchanged for varying θ values. Such direction-invariant feature is very useful for shadow rendering in dynamic scenes because the consistent transition of shadow quality should be preserved as possible during the user’s navigation/interaction. Degenerate cases θ ≤ φ. The values of both FLiSPSM and FGMNPR become extremely large for small θ values. For better illustration, a log10 scale is used in Figure 6 now. As θ goes from φ to 0, all PRs cannot make F optimal and converge to SSMs. The effectiveness of the perspective warping dramatically decreases such that no PR has any special advantage over others. This problem is well known as the dueling frusta case in which the anti-aliasing (using single shadow map with given resolution) still remains unsolved in computer graphics.
Aliasing Distribution in the x Direction
G(λ, θ, z) = ϕ1 (λ, θ)
z + ϕ2 (λ, θ) z
ϕ1 (λ, θ) =
ϕ2 (λ, θ) =
tan φ
f −n+(f +n) tanθ tan θ λ tan φ
2f
tan φ
λ+(f −n)(1− tanθ ) sin θ
(23)
θ ∈ [φ, π2 ] θ ∈ [0, φ]
φ tan φ π f − n + (f + n) tan tanθ λ + n tanθ − n θ ∈ [φ, 2 ]
φ 2fλ tan tan θ + f
tan φ tan θ
−1
θ ∈ [0, φ]
Instead of discussing G independently like what we have done on F, we effectively evaluate different reparameterizations by taking into account aliasing errors in both z and x directions simultaneously. To be independent of shadow map and image resolutions, we adopt the following “storage factor” proposed by Lloyd et al.9 as the metric of aliasing errors:
n≤z≤f
1 1 dx 1 1 1 1 1 1 = = tan φ z dt tan φ z dt/dx tan φ z t (x)
(24)
where
S ∗ (λ, θ) = max F × max G,
So far, we have only discussed the aliasing distribution in the z direction. The situation is slightly different in the x direction. The width of light beams dt in the shadow map corresponds to a step dz/dt in world space for the x direction. Like our derivation of F, the perspective aliasing in the x direction, denoted G, can be written as: G(λ, θ, z) =
Computing the explicit representation t(x) from Eqs. (3–9) and plugging it into Eq. (23), we get the following factorized form:
n≤z≤f
given λ and θ
Figure 7 plots the maximum errors in z, x directions, and the storage factor, respectively. Likewise, GMNPR produces lower errors than in both directions when θ > φ. This feature is very important because it balances the improvement of shadow quality in both directions, otherwise shadow details might be worse in one direction. In degenerate cases θ < φ, though errors in LiSPSM are lower than that in GMNPR, it doesn’t make much sense because all reparameterizations will not work well due to the dueling frusta problem.
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
562
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
MINIMUM-NORM PERSPECTIVE SHADOW MAPS ...........................................................................................
Figure 8. Testing scenes: Robots (11K), Dragon (51K), and Ceiling (23K).
Before we leave this section, we have an important note on the conclusion “PSMs, LiSPSMs, and some TSMs are equivalent in terms of the storage factor” (i.e., S ∗ keeps constant for different PRs) claimed by Lloyd et al.9 However, it’s easy to prove that such invariance of S ∗ (λ, θ) doesn’t hold in the general case θ = π/2 by using our global representations of F and G, which means further research on PRs still remains challenging and valuable. In Figure 7, we can see that S ∗ doesn’t keep constant in general cases.
Results We have developed our GMNPR using Microsoft DirectX SDK 9.0. We run the shadow rendering tests using 800 × 600 image resolution, and the performance is measured by an Intel Pentium 4 2.8 GHz CPU with 1G RAM, a NVidia GeForce 6800Ultra GPU with 256M video memory. In addition, we have compared our algorithm with SSM, LiSPSM, and GLPR.4 Two virtual scenes are composed and tested in our experiments as shown in Figure 8. In our tests, a dynamic directional lighting source and field of view 60◦ are set up. n = 1 m, f = 800 m, φ = π/6 are configured for all of tests. All algorithms achieve real-time performance in our experiments. We have a note here, there’s nearly no difference between the implementations (also performance) of LiSPSMs and GMNNPR , except for the λ selection as shown in Eqs (21) and (22).
Robots To verify the theoretical results shown in Figures 6 and 7, we compare different algorithms using this simple scene which consists of 49 uniformly placed objects. Figure 9 shows two views at θ = 55◦ and 35◦ . As we can see, SSM produces the worst shadow quality for near objects. Since
GMNPR preserves the optimal aliasing distribution in most general cases, the shadow quality in GMNPR is better than that in LiSPSM. The associated shadow maps are listed as well. As we can see, the shadow maps in GMNPR preserves that near regions consume the majority of shadow map resolution as the viewer or light moves.
Dragon To further prove above results in practice, we compare the shadow quality for different view/light configurations using this complicated scene which contains many randomly placed high-polygon objects. Figure 10 shows the enhanced shadow rendering in both scenarios. More importantly, due to the direction-adaptive λ, a stable transition of shadow quality is achieved in our algorithm.
Ceiling We use this scene to compare GMNPR with GLPR which is also a direction-adaptive PR technique. Figure 11 shows two views and corresponding light’s views, where the blue frame represents the view frustum. In View-1, both GLPR and GMNPR produce satisfactory shadow quality at near regions. From the associated light’s views, we can see the warping strength in GLPR is stronger than that in GMNPR. However, the overstrong warping strength in GLPR sometimes may cause the extremely unbalanced distribution of shadow details. When the viewer moves closer to the object, λGLPR becomes too small such that the warped object only occupies a very small portion of shadow map in practice. The shadow quality thus sharply decreases as shown in View-2. This problem is hard to be solved even by using some optimization techniques like “unit cube clipping”.7
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
563
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
F. ZHANG ET AL.
...........................................................................................
Figure 9. Comparison of the shadow quality and associated shadow maps. The red rectangles zoom in the local shadow details.
Figure 10. Comparison of the shadow quality for different view/light configurations.
Conclusion In this paper, we have proposed the GMNPR to enhance the shadow rendering in 3D computer games. Our algorithm preserves the optimal aliasing distribution in
possible general cases. Such direction-invariant feature is very important for the consistent transition of shadow quality during user’s interaction with dynamic scenes. By using the generalized representation of aliasing errors, our analysis explains different algorithms in a
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
564
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
MINIMUM-NORM PERSPECTIVE SHADOW MAPS ...........................................................................................
Figure 11. Comparison of the shadow quality and corresponding light’s views. Note that the extremely stretched shadow details in GLPR due to the over-strong warping effect. The optimization technique “unit cube clipping”7 is used for both algorithms. purely mathematical view. Our experimental results have shown the improved shadow quality by using our algorithm. The first aspect in our future work is to approximate the errors from an analytic way rather than a geometric intuition in Eq. (1). An important limitation in Eq. (1) is that the approximation of errors holds valid only for the points along the z axis. Notice that such local restriction is adopted in all current PR techniques. Therefore, the resultant optimal aliasing distribution (w.r.t minimumnorm) in both GMNPR and LiSPSMs can only be achieved in such local area. However, due to the “prior unknown” complexity of geometries in the space (e.g., the objects lie on a non-z ray originated from the eye), the practical visual quality might be extremely unbalanced in different scenes or unstable in different view/light configurations. Therefore, it might be possible to break such local restriction by approximating errors from an analytic view. Second, since the computational model used in this paper (Figure 3) assumes that the warping direction is parallel to the shadow plane, we would like to further our work to derive other direction-adaptive reparameterizations by using arbitrary warping direction. Finally, it would be also interesting to extend our analysis to other types of lights.
ACKNOWLEDGEMENTS
The work was supported by RGC research grant (grant no. 416007). Part of 3D models used in our experiments is downloaded from http://www.planetquake.com and http:// www.3dcafe.com
References 1. Lance W. Casting curved shadows on curved surfaces. In Proceedings of SIGGRAPH’78, ACM Press, New York, NY, USA, 1978; 270–274. 2. Franklin CC. Shadow algorithms for computer graphics. In Proceedings of SIGGRAPH’77, ACM Press, New York, NY, USA, 1977; 242–248. 3. Marc S, George D. Perspective shadow maps. In Proceedings of SIGGRAPH’02, ACM Press, New York, NY, USA, 2002; 557–562. 4. Zhang F, Xu L, Tao C, Sun H. Generalized linear perspective shadow map reparameterization. In VRCIA’06: Proceedings of the 2006 ACM international conference on Virtual reality continuum and its applications, ACM Press, New York, NY, USA, 2006; 339–342. 5. Wimmer M, Scherzer D, Werner P. Light space perspective shadow maps. In the Eurographics Symposium on Rendering 2004. Eurographics, Eurographics Association, 2004. 6. Tobias M, and Tan T-S. Anti-aliasing and continuity with trapezoidal shadow maps. In the Eurographics Symposium on Rendering 2004. Eurographics, Eurographics Association, 2004. 7. Simon K. Perspective shadow maps: care and feeding. GPU Gems. Addison-Wesley, 2004; 217–244. 8. Chong HY, Gortler SJ. A lixel for every pixel. In the Eurographics Symposium on Rendering 2004. Eurographics, Eurographics Association, 2004. 9. Brandon L, Tuft D, Yoon SE, Manocha D. Warping and partitioning for low error shadow maps. In Proceedings of the Eurographics Symposium on Rendering 2006, Eurographics Association, 2006; 215–226. 10. Woo A, Poulin P, Fournier A. A survey of shadow algorithms. IEEE Computer Graphics and Application 1990; 10(6): 13–32. 11. Tomas A-M, Chan E, Heidrich W, Kautz J, Kilgard M, Stamminger M. Real-time shadowing techniques. In Proceedings
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
565
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
F. ZHANG ET AL.
...........................................................................................
12.
13.
14.
15.
16.
17.
18.
19.
20. 21. 22. 23. 24.
25.
26.
27.
28. 29.
30.
31.
of SIGGRAPH’04 Course Notes, ACM Press, New York, NY, USA, 2004. Fernando R, Fernandez S, Bala K, Greenberg DP. Adaptive shadow maps. In Proceedings of SIGGRAPH’01, ACM Press, New York, NY, USA, 2001; 387–390. Lefohn AE, Sengupta S, Kniss J, Strzodka R, Owens JD. Glift: Generic, efficient, random-access gpu data structures. ACM Transactions on Graphics 2006; 25(1): 60–99. Tadamura K, Qin X, Jiao G, Nakamae E. Rendering optimal solar shadows with plural sunlight depth buffers. The Visual Computer 2001; 17(2): 76–90. Zhang F, Sun H, Xu L, Lun LK. Parallel-split shadow maps for large-scale virtual environments. In VRCIA’06: Proceedings of the 2006 ACM International Conference on Virtual Reality Continuum and Its Applications, ACM Press, New York, NY, USA, 2006; 311–318. Arvo J. Tiled shadow maps. In Proceedings of Computer Graphics International 2004, IEEE Computer Society, 2004; 240–247. Govindaraju NK, Lloyd B, Yoon S-E, Sud A, Manocha D. Interactive shadow generation in complex environments. ACM Transactions on Graphics 2003; 22(3): 501–510. Chan E, Durand F. An efficient hybrid shadow rendering algorithm. In Proceedings of the Eurographics Symposium on Rendering, Eurographics Association, 2004; 185–195. Aila T, Tomas A-M. A hierarchical shadow volume algorithm. In Proceedings of Graphics Hardware 2004, Eurographics Association, 2004; 15–23. McCool MD. Shadow volume reconstruction from depth maps. ACM Transactions on Graphics 2000; 19(1): 1–26. Arvo J, Aila T. Optimized shadow mapping using the stencil buffer. Journal of Graphics Tools 2004; 8(3): 23–32. Sen P, Cammarano M, Hanrahan P. Shadow silhouette maps. ACM Transactions on Graphics 2003; 22(3): 521–526. Arvo J, Hirvikorpi M. Compressed shadow maps. The Visual Computer 2005; 21(3): 125–138. Reeves WT, Salesin DH, Cook RL. Rendering antialiased shadows with depth maps. In Proceedings of SIGGRAPH’87, ACM Press, New York, NY, USA, 1987; 283–291. Donnelly W, Lauritzen A. Variance shadow maps. In Proceedings of the 2006 Symposium on Interactive 3D Graphics, SI3D 2006, Redwood City, ACM Press, California, USA, 2006; 161–165. Aila T, Laine S. Alias-free shadow maps. In the Eurographics Symposium on Rendering 2004, Eurographics, Eurographics Association, 2004; 161–166. Johnson GS, Lee J, Burns CA, Mark WR. The irregular z-buffer: hardware acceleration for irregular data structures. ACM Transactions on Graphics 2005; 24(4): 1462–1482. Brabec S, Annen T, Seidel H-P. Practical shadow mapping. Journal of Graphics Tools 2002; 7(4): 9–18. Low K-L, Ilie A. Computing a view frustum to maximize an object’s image area. Journal of Graphics Tools 2003; 8(1): 3–15. Wang Y, Molnar S. Second-depth shadow mapping. Technical report, University of North Carolina at Chapel Hill, Chapel Hill, NC, USA, 1994. Weiskopf D, Ertl T. Shadow mapping based on dual depth layers. In Proceedings of the Eurographics Symposium on Rendering 2003, Eurographics, Eurographics Association, 2003; 53–60.
32. Hourcade JC, Nicolas A. Algorithms for antialiased cast shadows. Computers and Graphics 1985; 9(3): 259–265.
Authors’ biographies:
Dr Fan Zhang received his Ph.D. from the Department of Computer Science and Engineering, The Chinese University of Hong Kong, in 2007. His main research interests include image-based rendering especially real-time shadow rendering and novel rendering techniques for real-time global illumination.
Dr Hanqiu Sun received her M.S. in electrical engineering from University of British, Columbia and Ph.D. in computer science from University of Alberta, Canada. Dr Sun has published more than 100 refereed technical papers in VR/CG prestigious journals, book chapters, and international conferences. She has served as guest editors of MIT PRESENCE and Journal of CAVW, program co-chair of ACM VRST 2002, organization co-chair of Pacific Graphics 2005 and CGI 2006, conference general chair of ACM VRCIA 2006, and numerous international program committees. Her current research interests include virtual and augmented reality, interactive graphics/animation, hypermedia, computer-assisted surgery, internet-based navigation, tele-medicine, realistic haptics simulation.
Chong Zhao received his B.S. degree in Computer Science from Jilin University, China and M.S. degree from the Math Institute, Chinese Academy of Science. He is
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
566
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav
MINIMUM-NORM PERSPECTIVE SHADOW MAPS ...........................................................................................
currently a Ph.D. student in the Department of Computer Science and Engineering, The Chinese University of Hong Kong. His main research interests include wavelets in graphics, geometry modeling in multi-resolution.
Lifeng Wang received the Ph.D. in computer graphics from CAD&CG Lab of Zhejiang University, Hangzhou, China, in July 1999. After that he joined Microsoft Research Asia as a researcher from 1999 to 2006 in the Internet Graphics Group. He is now a research and development manager of the Media and Entertainment Division of Autodesk Inc., Shanghai. His research interests focus on interactive 3D graphics, realistic modeling and rendering algorithms, image-based rendering, and computer vision. He is a member of the IEEE.
............................................................................................ Copyright © 2008 John Wiley & Sons, Ltd.
567
Comp. Anim. Virtual Worlds 2008; 19: 553–567 DOI: 10.1002/cav