8.4 Microfacet Models
Many geometric-optics-based approaches to modeling surface reflection and transmission are based on the idea that rough surfaces can be modeled as a collection of small microfacets. Surfaces comprised of microfacets are often modeled as heightfields, where the distribution of facet orientations is described statistically. Figure 8.12 shows cross sections of a relatively rough surface and a much smoother microfacet surface. When the distinction isn’t clear, we’ll use the term microsurface to describe microfacet surfaces and macrosurface to describe the underlying smooth surface (e.g., as represented by a Shape).
Microfacet-based BRDF models work by statistically modeling the scattering of light from a large collection of microfacets. If we assume that the differential area being illuminated, , is relatively large compared to the size of individual microfacets, then a large number of microfacets are illuminated and it’s their aggregate behavior that determines the observed scattering.
The two main components of microfacet models are a representation of the distribution of facets and a BRDF that describes how light scatters from individual microfacets. Given these, the task is to derive a closed-form expression giving the BRDF that describes scattering from such a surface. Perfect mirror reflection is most commonly used for the microfacet BRDF, though specular transmission is useful for modeling many translucent materials, and the Oren–Nayar model (described in the next section) treats microfacets as Lambertian reflectors.
To compute reflection from such a model, local lighting effects at the microfacet level need to be considered (Figure 8.13). Microfacets may be occluded by another facet, may lie in the shadow of a neighboring microfacet, or interreflection may cause a microfacet to reflect more light than predicted by the amount of direct illumination and the low-level microfacet BRDF. Particular microfacet-based BRDF models consider each of these effects with varying degrees of accuracy. The general approach is to make the best approximations possible, while still obtaining an easily evaluated expression.
8.4.1 Oren–Nayar Diffuse Reflection
Oren and Nayar (1994) observed that real-world objects do not exhibit perfect Lambertian reflection. Specifically, rough surfaces generally appear brighter as the illumination direction approaches the viewing direction. They developed a reflection model that describes rough surfaces by V-shaped microfacets described by a spherical Gaussian distribution with a single parameter , the standard deviation of the microfacet orientation angle.
Under the V-shape assumption, interreflection can be accounted for by only considering the neighboring microfacet; Oren and Nayar took advantage of this to derive a BRDF that models the aggregate reflection of the collection of grooves.
The resulting model, which accounts for shadowing, masking, and interreflection among the microfacets, does not have a closed-form solution, so they found the following approximation that fit it well:
where if is in radians,
The implementation here precomputes and stores the values of the and parameters in the constructor to save work in evaluating the BRDF later. Figure 8.14 compares the difference between rendering with ideal diffuse reflection and with the Oren–Nayar model.
Application of trigonometric identities can substantially improve the efficiency of the evaluation routine compared to a direct translation of the underlying equations. The implementation starts by computing the values of and .
To compute the term, we can apply the trigonometric identity
such that we just need to compute the sines and cosines of and .
Finally, the and terms are found. Note that whichever of or has a larger value for (i.e., a larger component) has a smaller value for . We can set using the appropriate sine value computed at the beginning of the method. The tangent can then be computed using the identity .
8.4.2 Microfacet Distribution Functions
Reflection models based on microfacets that exhibit perfect specular reflection and transmission have been effective at modeling light scattering from a variety of glossy materials, including metals, plastic, and frosted glass. Before we discuss the radiometric details of these models, we’ll first introduce abstractions that encapsulate their geometric properties. The code here includes implementations of two widely used microfacet models. All of this code is in the files core/microfacet.h and core/microfacet.cpp.
MicrofacetDistribution defines the interface provided by microfacet implementations as well as some common functionality for them.
One important characteristic of a microfacet surface is represented by the distribution function , which gives the differential area of microfacets with the surface normal (recall Figure 8.12, which shows how surface roughness and the microfacet normal distribution function are related). In pbrt, microfacet distribution functions are defined in the same BSDF coordinate system as BxDFs; as such, a perfectly smooth surface could be described by a delta distribution that was non-zero only when was equal to the surface normal: .
Microfacet distribution functions must be normalized to ensure that they are physically plausible. Intuitively, if we consider incident rays on the microsurface along the normal direction , then each ray must intersect the microfacet surface exactly once. More formally, given a differential area of the microsurface, , then the projected area of the microfacet faces above that area must be equal to (Figure 8.15). Mathematically, this corresponds to the following requirement:
The method MicrofacetDistribution::D() corresponds to the function ; implementations return the differential area of microfacets oriented with the given normal vector .
A widely used microfacet distribution function based on a Gaussian distribution of microfacet slopes is due to Beckmann and Spizzichino (1963); our implementation is in the BeckmannDistribution class.
The traditional definition of the Beckmann–Spizzichino model is
where if is the RMS slope of the microfacets, then .
It’s useful to define an anisotropic distribution, where the normal distribution also varies depending on the azimuthal orientation of . For example, given a for microfacets oriented perpendicular to the axis and for the axis, then values for intermediate orientations can be interpolated by constructing an ellipse through these values.
The corresponding anisotropic microfacet distribution function is
Note that the original isotropic variant of the Beckmann–Spizzichino model falls out when .
The alphax and alphay member variables are set in the BeckmannDistribution constructor, which is straightforward and therefore not included here.
The BeckmannDistribution::D() method is a direct translation of Equation (8.10). The only additional implementation detail is that infinite values of must be handled specially. This case is actually valid—it happens at perfectly grazing directions. In this case, the code below ends up attempting to compute , which results in a “not a number” (NaN) value, which would eventually lead to a NaN value returned for the current pixel sample’s radiance. Therefore, zero is explicitly returned for this case, as that is the value that converges to as goes to infinity.
Another useful microfacet distribution function is due to Trowbridge and Reitz (1975). Its anisotropic variant is given by
In comparison to the Beckmann–Spizzichino model, Trowbridge–Reitz has higher tails—it falls off to zero more slowly for directions far from the surface normal. This characteristic matches the properties of many real-world surfaces well. See Figure 8.16 for a graph of these two microfacet distribution functions.
It can be convenient to specify the BRDF’s roughness with a scalar parameter in , where values close to zero correspond to near-perfect specular reflection, rather than by specifying values directly. The RoughnessToAlpha() method, not included here, performs a mapping from such roughness values to values.
The D() method is a fairly direct transcription of Equation (8.11).
8.4.3 Masking and Shadowing
The distribution of microfacet normals alone isn’t enough to fully characterize the microsurface for rendering. It’s also important to account for the fact that some microfacets will be invisible from a given viewing or illumination direction because they are back-facing (and thus, other microfacets are in front of them) and also for the fact that some of the forward-facing microfacet area will be hidden since it’s shadowed by back-facing microfacets. These effects are accounted for by Smith’s masking-shadowing function , which gives the fraction of microfacets with normal that are visible from direction . (Note that .) In the usual case where the probability a microfacet is visible is independent of its orientation , we can write this function as .
As shown in Figure 8.17, a differential area on the surface has area when viewed from a direction that makes an angle with the surface normal. The area of visible microfacets seen from this direction must also be equal to , which leads to a normalization constraint for :
In other words, the projected area of visible microfacets for a given direction must be equal to times the differential area of the macrosurface .
Because the microfacets form a heightfield, every backfacing microfacet shadows a forward-facing microfacet of equal projected area in the direction . If is the projected area of forward-facing microfacets as seen from the direction and is the projected area of backward-facing microfacets from Equation (8.12), then . We can thus alternatively write the masking-shadowing function as the ratio of visible microfacet area to total forward-facing microfacet area:
Shadowing-masking functions are traditionally expressed in terms of an auxiliary function , which measures invisible masked microfacet area per visible microfacet area.
The Lambda() method computes this function. Its implementation is specific to each microfacet distribution.
Some algebra lets us express in terms of :
and therefore we can provide a G1() method in terms of Lambda().
The microfacet distribution alone doesn’t impose enough conditions to imply a specific function; many functions can fulfill the constraint in Equation (8.12). If we assume that there is no correlation between the heights of nearby points on the microsurface, for example, then it’s possible to find a unique given . (For many microfacet models, a closed-form expression can be found.) Although the underlying assumption isn’t true in reality—for actual microsurfaces, the height at a point is generally close to the heights of nearby points—the resulting functions turn out to be fairly accurate when compared to measured reflection from actual surfaces.
Under the assumption of no correlation of the heights of nearby points, for the isotropic Beckmann–Spizzichino distribution is
where and is the error function, .
pbrt’s computation of the Beckmann–Spizzichino function is based on a rational polynomial approximation of Equation (8.14) that is much more efficient to evaluate because it avoids calling std::erf() and std::exp(), both of which are fairly expensive to evaluate.
Masking-shadowing functions for anisotropic distributions are most easily computed by taking their corresponding isotropic function and stretching the underlying microsurface according to the and values. Equivalently, one can compute an interpolated value for the direction of interest and use that with the isotropic function; see the “Further Reading” section at the end of this chapter for more details.
Under the uncorrelated height assumption, the form of for the Trowbridge–Reitz distribution is quite simple:
Figure 8.18 shows a plot of the Trowbridge–Reitz function for a few values of . Note that the function is close to one over much of the domain but falls to zero at grazing angles. Note also that increasing surface roughness (i.e., higher values of ) causes the function to fall off more quickly.
One last useful function related to the geometric properties of a microfacet distribution is , which gives the fraction of microfacets in a differential area that are visible from both directions and . Defining requires some additional assumptions. For starters, we know that gives the fraction of microfacets that are visible from the direction and gives the fraction for . If we assume that the probability of a microfacet being visible from both directions is the probability that it is visible from each direction independently, then we have
In practice, however, these probabilities aren’t independent, and this formulation underestimates . To see why, consider the case where ; in this case any microfacet that is visible from is also visible from , and so . Because , their product in this case will cause to be too small (unless , which is usually only true if ). More generally, the closer together the two directions are, the more correlation there is between and .
A more accurate model can be derived assuming that microfacet visibility is more likely the higher up a given point on a microfacet is. This assumption leads to the model
This approximation is fairly accurate in practice and is the one we’ll use in pbrt. See the “Further Reading” section at the end of this chapter for pointers to information about this function’s derivation as well as more sophisticated approaches to defining functions.
8.4.4 The Torrance–Sparrow Model
An early microfacet model was developed by Torrance and Sparrow (1967) to model metallic surfaces. They modeled surfaces as collections of perfectly smooth mirrored microfacets. Because the microfacets are perfectly specular, only those with a normal equal to the half-angle vector,
cause perfect specular reflection from to (Figure 8.19).
The derivation of the Torrance–Sparrow model has a number of interesting steps; we’ll go through it in detail here. First, consider the differential flux incident on the microfacets oriented with half-angle for directions and . From the definition of radiance, Equation (5.2), it is
where we have written for the area measure of the microfacets with orientation and for the cosine of the angle between and (Figure 8.20).
The differential area of microfacets with orientation is
The first two terms of this product describe the differential area of facets per unit area that have the proper orientation, and the term converts this to differential area.
Therefore,
If we assume that the microfacets individually reflect light according to Fresnel’s law, the outgoing flux is
Again using the definition of radiance, the reflected outgoing radiance is
We can substitute this relationship into the previous equation and simplify, giving
We can now apply the definition of the BRDF, Equation (5.8) and add the geometric attenuation term , which gives us the Torrance–Sparrow BRDF:
One of the nice things about the Torrance–Sparrow model is that the derivation doesn’t depend on the particular microfacet distribution being used. Furthermore, it doesn’t depend on a particular Fresnel function, so it can be used for both conductors and dielectrics. However, the relationship between and used in the derivation does depend on the assumption of specular reflection from microfacets.
MicrofacetReflection uses the Torrance–Sparrow model to implement a general microfacet-based BRDF.
Its constructor takes the reflectance, a pointer to a MicrofacetDistribution implementation, and a Fresnel function.
Evaluating the terms of the Torrance–Sparrow BRDF is straightforward. For the Fresnel term, recall that given specular reflection, the angle is the same between and both and , so it doesn’t matter which vector we use to compute the cosine of . We arbitrarily choose .
Two edge cases that come up with incident and outgoing directions at glancing angles need to be handled explicitly to avoid NaN values being generated from the evaluation of the BRDF.
It’s also possible to define a BTDF for transmission through microfacets that exhibit perfect specular transmission. In that setting, with transmission from a medium with index of refraction to a medium with index of refraction , then and are related by:
This relationship can be used in place of Equation (8.17) in the derivation of the Torrance–Sparrow BRDF. The result is
where . For specular transmission, the half-angle vector is
(You may want to verify that this normal vector causes to be refracted in the direction , via Equation (8.8).)
The MicrofacetTransmission class implements this BTDF.
Its f() method is a direct transcription of Equation (8.19). Its implementation is therefore not included here.
Figure 8.21 shows the dragon rendered with the Torrance–Sparrow model and both reflection and transmission.
Figure 8.22 compares the appearance of two spheres with an isotropic and anisotropic microfacet model lit by a light source simulating a distant environment.