A Secret of The Normalmap
A Secret of The Normalmap
Abstract zoomed in
1 Introduction
Representing surface detail at a variety of scales requires good fil-
tering algorithms. For texture mapping, there has been consider-
able effort at developing and analyzing filtering methods [Heck-
bert 1989]. A common, linear approach to reduce aliasing is MIP-
mapping [Williams 1983]. Normal mapping (also known as bump
mapping [Blinn 1978] or normal perturbation), a simple and widely
used analogue to color texture mapping, specifies the surface nor-
mal at each texel. Unfortunately, normal map filtering is very diffi-
cult because shading is not linear in the normal.
For example, consider the simple V-groove surface geometry in
Fig. 1a. In a closeup, this spans two pixels, each of which has
distinct normals (b). As we zoom out (c), the average normal of the
two sides (e) corresponds simply to a flat surface, where the shading
is likely very different. By contrast, our method preserves the full
normal distribution (d) in the spirit of [Fournier 1992], and shows
how to convolve it with the BRDF (f) to get an accurate result.
A more complex example is Fig. 2, which compares our method Figure 2: Top: Closeup of the base normal map; all other methods
with “ground truth”1 , standard MIP-mapping of normals, and the are identical at this scale and are not shown. Schematic (a) and dif-
recent normal map filtering technique of [Toksvig 2005]. At close fusely shaded (b) views are provided to aid in comparison/visualization.
range (top row), minimal filtering is required and all methods per- Middle: When we zoom out, differences emerge between our (6-lobe) spher-
form identically. However, as we zoom out (middle and especially ical vMF method, the Toksvig approach (rightmost), and normalized MIP-
bottom rows), we quickly obtain radically different results. mapping. (Unnormalized MIP-mapping of normals produces an essentially
It has long been known qualitatively that antialiasing involves black image.) Bottom: Zooming out even further, our method is clearly
convolution of the input signal (here, the distribution of surface more accurate than Toksvig’s model, and compares favorably with ground
truth. (The reader may zoom into the PDF to compare images.)
∗ {charhan,bosun,ravir,eitan}@cs.columbia.edu
URL: http://www.cs.columbia.edu/cg/normalmap normals) and an appropriate low-pass filter. Our most important
1 “Ground truth” images are obtained using jittered supersampling (on
contribution is theoretical, formalizing these ideas and developing
the order of hundreds of samples per pixel) and unfiltered normal maps. a comprehensive framework for normal map filtering.
In Sec. 4, we derive an analytic formula, showing that filtering
can be written as a spherical convolution of the BRDF of the ma-
terial with a function we define as the normal distribution function
(NDF)2 of the texel. This mathematical form holds for a large class
of common BRDFs including Lambertian, Blinn-Phong, microfacet
models like Torrance-Sparrow, and many measured BRDFs. How-
ever, the convolution does not apply exactly to BRDF models that
2 We define the NDF as a weighted mapping of surface normals onto the
unit sphere; more formally, it is the extended Gaussian Image [Horn 1984]
of the geometry within a texel.
Acronym Definition Symbol convolution—it is easy to understand [Tan et al. 2005] as an im-
NDF normal distribution function γ (n) portant special case in this framework. Our formulation also al-
SH spherical harmonics Ylm lows spherical harmonic methods for low-frequency materials and
SRBF spherical radial basis function γ (n · µ ) Lambertian objects, which do not even require non-linear fitting
EM expectation maximization
of lobes. For high-frequency materials we use vMFs and spheri-
vMF von Mises-Fisher distribution γ (n · µ ; θ ),
θ = {κ , µ }
cal EM, which operate in the natural spherical domain of surface
movMF mixture of vMF lobes γ (n; Θ), normals; by contrast, planar Gaussian fits, as in [Tan et al. 2005],
Θ = {α j , θ j }Jj=1 have been shown to considerably reduce accuracy both in our work
(Fig. 7) and in other contexts [Strehl et al. 2000].
Table 1: Important abbreviations and acronyms used in the paper. Note that [Tan et al. 2005] treat the BRDF itself as a pre-baked
distribution of normals at fine-scale texels. We support and discuss
depend on the “reflected direction” between the light source and this multi-scale tradeoff between BRDF and geometry (Sec. 6.2).
viewer, e.g., the standard Phong model. Our analytic result imme- However, our spherical representation enables us to derive a for-
diately connects geometrical normal map filtering with the older mal convolution result of the NDF with the BRDF, and allows us to
lighting-BRDF convolution result for appearance [Basri and Jacobs separate or factor the two. The same NDF can be used with differ-
2001; Ramamoorthi and Hanrahan 2001]. This result also unifies ent, possibly non-Gaussian BRDFs, easily. We can also change the
many previous normal map filtering approaches, which can now be BRDF at runtime, and support dynamic, low-frequency complex
viewed as special cases. lighting.
Moreover, we can immediately apply a host of mathematical rep- Hierarchy of Representations: A hierarchy of scales, with
resentations originally developed for lighting-BRDF convolution. geometry transitioning to bump or normal maps, transitioning to
In particular, we develop two novel algorithms. Our first method BRDFs, was first proposed by Kajiya [1985]. This idea is explored
(Sec. 5) is a general framework that uses spherical harmonics (SH). in detail by [Becker and Max 1993], but they do not focus on nor-
Although general, this method is most suitable for low-frequency mal map filtering as in our work. Similarly, appearance-preserving
BRDFs, where it suffices to use a small number of SH coefficients. simplification methods replace fine-scale geometry with normal and
Our second method, intended for high-frequency materials, uses texture maps [Cohen et al. 1998]. It is likely that our approach could
an approximate function fitting technique known as spherical ex- enable continuous level of detail and antialiasing in these methods.
pectation maximization (EM) [Banerjee et al. 2005]. This method Separately, our formulation allows one to understand the tradeoff
approximates or fits the NDF with von Mises-Fisher (vMF) distri- between a normal distribution and the BRDF, since the final image
butions (Sec. 7). vMFs are spherical Gaussian-like functions, sym- is given by a convolution of the NDF and BRDF.
metric about a central direction (average normal). To our knowl-
Convolution and Precomputed Radiance Transfer (PRT):
edge, the use of vMFs and spherical EM is new in graphics, and
Many of our mathematical representations and ideas derive from
may have broader relevance. Finally, our framework enables real-
previous spherical convolution techniques [Basri and Jacobs 2001;
istic BRDFs, including measured materials (Fig. 4), as well as dy-
Ramamoorthi and Hanrahan 2001]. We also build on PRT meth-
namically changing reflectance, lighting and view (Fig. 8). We are
ods that have used spherical harmonics [Sloan et al. 2002]. Our
also able to incorporate low-frequency environment maps (Fig. 9).
spherical vMF method extends zonal harmonics [Sloan et al. 2005]
Although this paper presents an in-depth theoretical discussion, and spherical radial basis functions [Tsai and Shih 2006]. We
the final algorithms are relatively simple. Readers more interested also considered wavelet methods (introduced for reflectance in
in implementation may wish to pay special attention to Sec. 5.1, that [Lalonde and Fournier 1997]), but found the number of terms for an
describes the spherical harmonic method, and the full pseudocode artifact-free solution too large for practical use, even with smoother
provided in Algorithms 1 and 2 for the vMF method of Sec. 7. Ad- wavelets.3 A real-time method for wavelet-based BRDF represen-
ditionally, videos and example GLSL shader code for all of our tation and filtering on the GPU is given in [Claustres et al. 2007],
results are available for download from our website. which does not account for normal map filtering.
We emphasize, however, that ours is not a PRT algorithm; it re-
2 Previous Work quires minimal precomputation and works with conventional real-
time rendering techniques. Furthermore, our method rests on an
Normal Map Filtering: Many previous methods approximate explicit analytic convolution formula and uses the representations
the normal distribution function using a single symmetric or asym- above solely for normal map filtering, not for PRT.
metric lobe. [Schilling 1997] described the lobe using covariance
matrices, while [Olano and North 1997] mapped normal distribu-
tions consisting of a single 3D Gaussian. A simple GPU method is
3 Preliminaries
described in [Toksvig 2005]. In our framework, these methods can In this section, we introduce relevant notation for the reflectance
retrospectively be considered similar to using a single vMF lobe. equation, and BRDF and normal map representations. Note that
As seen in Figs. 2 and 7, one lobe is insufficient for complex NDFs. in this paper, we focus only on normal map filtering and do not
An early inspiration is [Fournier 1992], which uses up to seven consider displacement maps, occlusion, masking, geometry sim-
Phong lobes per texel (and up to 56 at the coarsest scales). This can plification or cast shadows—filtering these additional effects is an
be seen as a special case of our framework, with some similarities to important direction of future work (and discussed in Sec. 9).
our spherical vMF algorithm. Note that [Fournier 1992] uses non- The reflected light B at a spatial point x in direction ω o is
linear least-squares optimization to fit lobes. In our experience, this Z
is unstable and slow, especially considering the number of peaks B(x, ω o ) = L(x, ω i )ρ (ω ′i , ω ′o ) d ω i , (1)
and texels in a normal map. vMFs are very similar to Gaussian or S2
Phong lobes, but have many technical advantages, in allowing for where L is the lighting at x from incident direction ω i , and ρ is the
fast and robust fitting using existing algorithms for spherical EM. BRDF (actually, the transfer function including the cosine of the in-
The most recent and closest previous work is [Tan et al. 2005], cident angle). Most generally we must integrate over the sphere S2
which uses EM to fit Gaussian lobes to a planar projection of
the hemispherical NDF at each texel. We introduce a new theo- 3 PRT methods can use a coarse wavelet approximation of the lighting,
retical result in terms of the analysis of normal map filtering as since it is not visualized directly, but we directly visualize NDF and BRDF.
of incident directions, but in this paper L will usually be assumed to Normal Map Filtering: In screen space, the exitant radiance
be from a small number of point lights, making equation 1 a sum- or pixel color B(x, ω o ) at a surface location x should represent the
mation over discrete directions ω i . We will relax this restriction, average radiance at the N corresponding finer-level texels q:
and discuss extensions to environment maps, in Sec. 8.
1
Z
Equation 1 is the standard reflectance equation. However, we B(x, ω o ) = ∑ L(x, ω i )ρ eff (ω i , ω o ; n(q)) d ω i
have made explicit that ω ′i and ω ′o are the local directions in the N q∈x S
2
eff
√
ρlm = 2πγ−(l+m) ρlm . (9)
where we again make clear that the NDF γl, j is a function of the
texel q. This equation can be used directly for shading once we find
ω for the light source and view direction.
convolving the normalized BRDF ρ̂l with a single normalized vMF For each vMF lobe, we would now like to find a y j that best
lobe γl . It is possible to directly use equation 19 for the vMF coef- describes the yi of all its underlying texels. In the appendix, we
ficients and equation 14 for rendering with general BRDFs. How- augment the EM likelihood function with an additional term whose
ever, a much simpler method is available for the important special maximization yields an extra line in the M-step,
forms of Blinn-Phong and Torrance-Sparrow like BRDFs. First,
consider a normalized Blinn-Phong model of the form, ∑N
i=1 hzi j iyi
yj ← (22)
s+1 ∑N
i=1 hzi j i
ρ = f (ω h · n) = (ω h · n)s ,
2π Note that, since y j does not affect the E-step, the preceding can be
where s is the specular exponent or shininess. It can be shown [Ra- run as a postprocess to the vanilla EM algorithm.
mamoorthi and Hanrahan 2001] that the spherical harmonic coeffi- This extension enables correct filtering of spatially-varying ma-
2
cients are ρ̂l ≈ e−l /2s . Therefore, the result after convolution with terials (as in Fig. 2). Note however that only linear blending of basis
the vMF is still approximately a Blinn-Phong shape: BRDFs (and not for example, freely varying specular exponents) is
allowed. Moreover, the result is a “best-fit” approximation, since
2 2
/2κ 2
/2s′ normals and colors are assumed decorrelated.
Λl ρleff = ρ̂l Λl γl = e−l /2s e−l = e−l ,
′ κs Coherent Lobes for Hardware Interpolation: In our case, ac-
s =
κ +s curate rendering involves shading the 8 neighboring MIP-map tex-
s′ + 1 ′ els (using the BRDF and respective movMFs), and then trilinearly
=⇒ ρ eff (ω h · µ ) = (ω h · µ )s . (20) interpolating them with appropriate weights. Greater efficiency
2π
(usually a 2× to 4× speedup) is obtained if we instead follow the
For a Torrance-Sparrow like BRDF of the form of equation 18, classic hardware approach of first trilinearly interpolating the pa-
we obtain a similar form for ρ eff , only with a new surface roughness rameters Θ of the movMFs. We can then simply run our GPU pixel
σ ′ in the Torrance-Sparrow model, given by shader once on the interpolated parameters Θ̃. For accurate inter-
q polation, this requires us to construct the movMFs in the MIP-map
σ ′ = σ 2 + (2κ )−1 . (21) such that lobe j of each texel be similarly aligned to the jth lobe
stored at each neighboring texel.
Equations 20 and 21 can easily be implemented in a GPU shader For alignment, we introduce a new term in our EM likelihood
for rendering (lines 12-13 in Algorithm 2 implement equation 20; function, and maximize (details are provided in the appendix). The
the full Algorithm 2 is explained at the end of Sec. 7.3). The sim- final result replaces line 13 in the M-step of Algorithm 1 with
plicity of these formulae allows us to change BRDF parameters on !
the fly, and also to consider very high-frequency BRDFs. K
µ j ← normalize r j +C ∑ α jk µ jk . (23)
7.3 Extensions k=1
Different Materials/Colors: It is often the case that one would C is a parameter that controls the strength of alignment (intuitively,
like to associate additional spatially varying properties (such as col- it seeks to move µ j closer to the central directions µ jk of the K
ors, material blending weights, etc.) to a normal map. For example, neighbors, favoring neighbors with larger amplitudes α jk .).
the normal map in Fig. 2 contains regions of different colors. We As in the Gaussian mixture model method of [Tan et al. 2005],
represent these properties in a feature vector yi associated with each we build our aligned movMFs starting at the topmost (that is, most
normal ni , and extend the EM algorithm accordingly. filtered) MIP-map level and proceed downward, following scan-
Algorithm 2 Pseudocode for the vMF GLSL fragment shader
1: {Setup: calculate half angle ω h and incident angle ω i }
2: ρ ← 0
3: for j = 1 to J do {Add up contributions for all J lobes}
4: {Look up vMF parameters stored in 2D texture map}
5: θ ← texture2D(vMFTexture[ j], s,t)
6: α y ← texture2D(colorTexture[ j], s,t)
7: α ← θ .x
8: r ← θ .yzw
α {θ .yzw stores α r}
3
9: κ ← 3krk−krk
1−krk2
10: µ ← normalize(r)
11: {Calculate shading per equation 20}
12: s′ ← κκ+s
s
{s is Blinn-Phong exponent}
s′ +1 ′
13: Bs ← 2π (ω h · µ )s {Equation 20}
14: ρ ← ρ + α y(Ks Bs + Kd )(ω i · µ )
15: end for
16: gl_FragColor ← L × ρ {L is light intensity}
Transactions on Graphics (SIGGRAPH 2004) 23, 3, 475–485. i=1 i=1 j=1 k=1
O LANO , M., AND N ORTH , M. 1997. Nor- which, considering all J lobes and hidden variables hzi j i, becomes
mal distribution mapping. Tech. Rep. 97-041 " #
J N N K
http://www.cs.unc.edu/~olano/papers/ndm/ndm.pdf, UNC. 2 ′
R AMAMOORTHI , R., AND H ANRAHAN , P. 2001. A signal-
∑ ∑ ln γ (ni |θ j )hzi j i + ∑ −kyi − yz k i hzi j i + ∑ C α jk (µ j · µ jk ) .
j=1 i=1 i=1 k=1
processing framework for inverse rendering. In SIGGRAPH 01,
117–128. Maximizing with respect to y j , we directly obtain equation 22. The
maximization with respect to µ j is more complex,
S CHILLING , A. 1997. Toward real-time photorealistic rendering:
Challenges and solutions. In SIGGRAPH/Eurographics Work- N
!
K
shop on Graphics Hardware, 7–16. µ j = normalize κ j ∑ ni hzi j i +C′ ∑ α jk µ jk .
S LOAN , P., K AUTZ , J., AND S NYDER , J. 2002. Precomputed radi- i=1 k=1
ance transfer for real-time rendering in dynamic, low-frequency Finally, redefining C = C′ /κ j , we obtain equation 23.
lighting environments. ACM Transactions on Graphics (SIG-
GRAPH 02 proceedings) 21, 3, 527–536.
S LOAN , P., L UNA , B., AND S NYDER , J. 2005. Local, deformable
precomputed radiance transfer. ACM Transactions on Graphics
(SIGGRAPH 05 proceedings) 24, 3, 1216–1224.
S TREHL , A., G HOSH , J., AND M OONEY, R. 2000. Impact of
similarity measures on web-page clustering. In Proc Natl Conf
on Artificial Intelligence : Workshop of AI for Web Search (AAAI
2000), 58–64.
S UN , B., S UNKAVALLI , K., R AMAMOORTHI , R., B ELHUMEUR ,
P., AND NAYAR , S. 2007. Time-Varying BRDFs. IEEE Trans-
actions on Visualization and Computer Graphics 13, 3, 595–609.
TAN , P., L IN , S., Q UAN , L., G UO , B., AND S HUM , H. 2005.
Multiresolution reflectance filtering. In EuroGraphics Sympo-
sium on Rendering 2005, 111–116.
T OKSVIG , M. 2005. Mipmapping normal maps. Journal of Graph-
ics Tools 10, 3, 65–71.