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).

Figure 8.12: Microfacet surface models are often described by a function that gives the distribution of microfacet normals bold n Subscript bold f with respect to the surface normal  bold n Subscript . (a) The greater the variation of microfacet normals, the rougher the surface is. (b) Smooth surfaces have relatively little variation of microfacet normals.

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, normal d upper A Subscript , 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.

Figure 8.13: Three Important Geometric Effects to Consider with Microfacet Reflection Models. (a) Masking: the microfacet of interest isn’t visible to the viewer due to occlusion by another microfacet. (b) Shadowing: analogously, light doesn’t reach the microfacet. (c) Interreflection: light bounces among the microfacets before reaching the viewer.

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  sigma , 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:

f Subscript normal r Baseline left-parenthesis omega Subscript normal i Baseline comma omega Subscript normal o Baseline right-parenthesis equals StartFraction upper R Over pi EndFraction left-parenthesis upper A plus upper B max left-parenthesis 0 comma cosine left-parenthesis phi Subscript normal i Baseline minus phi Subscript normal o Baseline right-parenthesis right-parenthesis sine alpha tangent beta right-parenthesis comma

where if sigma is in radians,

StartLayout 1st Row 1st Column upper A 2nd Column equals 1 minus StartFraction sigma squared Over 2 left-parenthesis sigma squared plus 0.33 right-parenthesis EndFraction 2nd Row 1st Column upper B 2nd Column equals StartFraction 0.45 sigma squared Over sigma squared plus 0.09 EndFraction 3rd Row 1st Column alpha 2nd Column equals max left-parenthesis theta Subscript normal i Baseline comma theta Subscript normal o Baseline right-parenthesis 4th Row 1st Column beta 2nd Column equals min left-parenthesis theta Subscript normal i Baseline comma theta Subscript normal o Baseline right-parenthesis period EndLayout

Figure 8.14: Dragon model rendered (a) with standard diffuse reflection from the LambertianReflection model and (b) with the OrenNayar model with a sigma parameter of 20 degrees. Note the increase in reflection at the silhouette edges and the generally less-drawn-out transitions at light terminator edges with the Oren–Nayar model. (Model courtesy of Christian Schüller.)

The implementation here precomputes and stores the values of the  upper A and  upper B 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.

<<OrenNayar Public Methods>>= 
OrenNayar(const Spectrum &R, Float sigma) : BxDF(BxDFType(BSDF_REFLECTION | BSDF_DIFFUSE)), R(R) { sigma = Radians(sigma); Float sigma2 = sigma * sigma; A = 1.f - (sigma2 / (2.f * (sigma2 + 0.33f))); B = 0.45f * sigma2 / (sigma2 + 0.09f); }

<<OrenNayar Private Data>>= 
const Spectrum R; Float A, B;

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 sine theta Subscript normal i and sine theta Subscript normal o .

<<BxDF Method Definitions>>+=  
Spectrum OrenNayar::f(const Vector3f &wo, const Vector3f &wi) const { Float sinThetaI = SinTheta(wi); Float sinThetaO = SinTheta(wo); <<Compute cosine term of Oren–Nayar model>> 
Float maxCos = 0; if (sinThetaI > 1e-4 && sinThetaO > 1e-4) { Float sinPhiI = SinPhi(wi), cosPhiI = CosPhi(wi); Float sinPhiO = SinPhi(wo), cosPhiO = CosPhi(wo); Float dCos = cosPhiI * cosPhiO + sinPhiI * sinPhiO; maxCos = std::max((Float)0, dCos); }
<<Compute sine and tangent terms of Oren–Nayar model>> 
Float sinAlpha, tanBeta; if (AbsCosTheta(wi) > AbsCosTheta(wo)) { sinAlpha = sinThetaO; tanBeta = sinThetaI / AbsCosTheta(wi); } else { sinAlpha = sinThetaI; tanBeta = sinThetaO / AbsCosTheta(wo); }
return R * InvPi * (A + B * maxCos * sinAlpha * tanBeta); }

To compute the max left-parenthesis 0 comma cosine left-parenthesis phi Subscript normal i Baseline minus phi Subscript normal o Baseline right-parenthesis right-parenthesis term, we can apply the trigonometric identity

cosine left-parenthesis a minus b right-parenthesis equals cosine a cosine b plus sine a sine b comma

such that we just need to compute the sines and cosines of phi Subscript normal i and phi Subscript normal o .

<<Compute cosine term of Oren–Nayar model>>= 
Float maxCos = 0; if (sinThetaI > 1e-4 && sinThetaO > 1e-4) { Float sinPhiI = SinPhi(wi), cosPhiI = CosPhi(wi); Float sinPhiO = SinPhi(wo), cosPhiO = CosPhi(wo); Float dCos = cosPhiI * cosPhiO + sinPhiI * sinPhiO; maxCos = std::max((Float)0, dCos); }

Finally, the sine alpha and tangent beta terms are found. Note that whichever of omega Subscript normal i or omega Subscript normal o has a larger value for cosine theta (i.e., a larger  z component) has a smaller value for  theta . We can set sine alpha using the appropriate sine value computed at the beginning of the method. The tangent can then be computed using the identity tangent theta equals sine theta slash cosine theta .

<<Compute sine and tangent terms of Oren–Nayar model>>= 
Float sinAlpha, tanBeta; if (AbsCosTheta(wi) > AbsCosTheta(wo)) { sinAlpha = sinThetaO; tanBeta = sinThetaI / AbsCosTheta(wi); } else { sinAlpha = sinThetaI; tanBeta = sinThetaO / AbsCosTheta(wo); }

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.

<<MicrofacetDistribution Declarations>>= 
class MicrofacetDistribution { public: <<MicrofacetDistribution Public Methods>> 
virtual Float D(const Vector3f &wh) const = 0; virtual Float Lambda(const Vector3f &w) const = 0; Float G1(const Vector3f &w) const { return 1 / (1 + Lambda(w)); } Float G(const Vector3f &wo, const Vector3f &wi) const { return 1 / (1 + Lambda(wo) + Lambda(wi)); } virtual Vector3f Sample_wh(const Vector3f &wo, const Point2f &u) const = 0; Float Pdf(const Vector3f &wo, const Vector3f &wh) const;
protected: <<MicrofacetDistribution Protected Methods>> 
MicrofacetDistribution(bool sampleVisibleArea) : sampleVisibleArea(sampleVisibleArea) { }
<<MicrofacetDistribution Protected Data>> 
const bool sampleVisibleArea;
};

One important characteristic of a microfacet surface is represented by the distribution function upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis , which gives the differential area of microfacets with the surface normal omega Subscript normal h (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 omega Subscript normal h was equal to the surface normal: upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis equals delta left-parenthesis omega Subscript normal h Baseline minus left-parenthesis 0 comma 0 comma 1 right-parenthesis right-parenthesis .

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 bold n Subscript , then each ray must intersect the microfacet surface exactly once. More formally, given a differential area of the microsurface, normal d upper A Subscript , then the projected area of the microfacet faces above that area must be equal to normal d upper A Subscript (Figure 8.15). Mathematically, this corresponds to the following requirement:

integral Underscript script upper H squared left-parenthesis bold n Subscript Baseline right-parenthesis Endscripts upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis cosine theta Subscript normal h Baseline normal d omega Subscript normal h Baseline equals 1 period

Figure 8.15: Given a differential area on a surface normal d upper A Subscript , then the microfacet normal distribution function upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis must be normalized such that the projected surface area of the microfacets above the area is equal to normal d upper A Subscript .

The method MicrofacetDistribution::D() corresponds to the function upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis ; implementations return the differential area of microfacets oriented with the given normal vector omega Subscript .

<<MicrofacetDistribution Public Methods>>= 
virtual Float D(const Vector3f &wh) const = 0;

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.

<<MicrofacetDistribution Declarations>>+=  
class BeckmannDistribution : public MicrofacetDistribution { public: <<BeckmannDistribution Public Methods>> 
static Float RoughnessToAlpha(Float roughness) { roughness = std::max(roughness, (Float)1e-3); Float x = std::log(roughness); return 1.62142f + 0.819955f * x + 0.1734f * x * x + 0.0171201f * x * x * x + 0.000640711f * x * x * x * x; } BeckmannDistribution(Float alphax, Float alphay, bool samplevis = true) : MicrofacetDistribution(samplevis), alphax(alphax), alphay(alphay) { } Float D(const Vector3f &wh) const; Vector3f Sample_wh(const Vector3f &wo, const Point2f &u) const;
private: <<BeckmannDistribution Private Methods>> 
Float Lambda(const Vector3f &w) const;
<<BeckmannDistribution Private Data>> 
const Float alphax, alphay;
};

The traditional definition of the Beckmann–Spizzichino model is

upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis equals StartFraction normal e Superscript minus tangent squared theta Super Subscript normal h Superscript slash alpha squared Baseline Over pi alpha squared cosine Superscript 4 Baseline theta Subscript normal h Baseline EndFraction comma
(8.9)

where if sigma is the RMS slope of the microfacets, then alpha equals StartRoot 2 EndRoot sigma .

It’s useful to define an anisotropic distribution, where the normal distribution also varies depending on the azimuthal orientation of omega Subscript normal h . For example, given a alpha Subscript x for microfacets oriented perpendicular to the x axis and alpha Subscript y for the y axis, then alpha values for intermediate orientations can be interpolated by constructing an ellipse through these values.

The corresponding anisotropic microfacet distribution function is

upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis equals StartFraction normal e Superscript minus tangent squared theta Super Subscript normal h Superscript left-parenthesis cosine squared phi Super Subscript normal h Superscript slash alpha Super Subscript x Super Superscript 2 Superscript plus sine squared phi Super Subscript normal h Superscript slash alpha Super Subscript y Super Superscript 2 Superscript right-parenthesis Baseline Over pi alpha Subscript x Baseline alpha Subscript y Baseline cosine Superscript 4 Baseline theta Subscript normal h Baseline EndFraction period

Note that the original isotropic variant of the Beckmann–Spizzichino model falls out when alpha Subscript x Baseline equals alpha Subscript y .

The alphax and alphay member variables are set in the BeckmannDistribution constructor, which is straightforward and therefore not included here.

<<BeckmannDistribution Private Data>>= 
const Float alphax, alphay;

The BeckmannDistribution::D() method is a direct translation of Equation (8.10). The only additional implementation detail is that infinite values of tangent squared theta 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 0 slash 0 , 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 upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis converges to as tangent theta Subscript normal h goes to infinity.

<<MicrofacetDistribution Method Definitions>>= 
Float BeckmannDistribution::D(const Vector3f &wh) const { Float tan2Theta = Tan2Theta(wh); if (std::isinf(tan2Theta)) return 0.; Float cos4Theta = Cos2Theta(wh) * Cos2Theta(wh); return std::exp(-tan2Theta * (Cos2Phi(wh) / (alphax * alphax) + Sin2Phi(wh) / (alphay * alphay))) / (Pi * alphax * alphay * cos4Theta); }

Another useful microfacet distribution function is due to Trowbridge and Reitz (1975). Its anisotropic variant is given by

upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis equals StartFraction 1 Over pi alpha Subscript x Baseline alpha Subscript y Baseline cosine Superscript 4 Baseline theta Subscript normal h Baseline left-parenthesis 1 plus tangent squared theta Subscript normal h Baseline left-parenthesis cosine squared phi Subscript normal h Baseline slash alpha Subscript x Superscript 2 Baseline plus sine squared phi Subscript normal h Baseline slash alpha Subscript y Superscript 2 Baseline right-parenthesis right-parenthesis squared EndFraction period

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.

Figure 8.16: Graphs of isotropic Beckmann–Spizzichino and Trowbridge–Reitz microfacet distribution functions as a function of theta for alpha equals 0.5 . Note that Trowbridge–Reitz has higher tails for values of theta with larger magnitudes.

<<MicrofacetDistribution Declarations>>+= 
class TrowbridgeReitzDistribution : public MicrofacetDistribution { public: <<TrowbridgeReitzDistribution Public Methods>> 
static inline Float RoughnessToAlpha(Float roughness); TrowbridgeReitzDistribution(Float alphax, Float alphay, bool samplevis = true) : MicrofacetDistribution(samplevis), alphax(alphax), alphay(alphay) { } Float D(const Vector3f &wh) const; Vector3f Sample_wh(const Vector3f &wo, const Point2f &u) const;
private: <<TrowbridgeReitzDistribution Private Methods>> 
Float Lambda(const Vector3f &w) const;
<<TrowbridgeReitzDistribution Private Data>> 
const Float alphax, alphay;
};

It can be convenient to specify the BRDF’s roughness with a scalar parameter in left-bracket 0 comma 1 right-bracket , where values close to zero correspond to near-perfect specular reflection, rather than by specifying alpha values directly. The RoughnessToAlpha() method, not included here, performs a mapping from such roughness values to alpha values.

<<TrowbridgeReitzDistribution Public Methods>>= 
static inline Float RoughnessToAlpha(Float roughness);

<<TrowbridgeReitzDistribution Private Data>>= 
const Float alphax, alphay;

The D() method is a fairly direct transcription of Equation (8.11).

<<MicrofacetDistribution Method Definitions>>+=  
Float TrowbridgeReitzDistribution::D(const Vector3f &wh) const { Float tan2Theta = Tan2Theta(wh); if (std::isinf(tan2Theta)) return 0.; const Float cos4Theta = Cos2Theta(wh) * Cos2Theta(wh); Float e = (Cos2Phi(wh) / (alphax * alphax) + Sin2Phi(wh) / (alphay * alphay)) * tan2Theta; return 1 / (Pi * alphax * alphay * cos4Theta * (1 + e) * (1 + e)); }

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 upper G 1 left-parenthesis omega Subscript Baseline comma omega Subscript normal h Baseline right-parenthesis , which gives the fraction of microfacets with normal omega Subscript normal h that are visible from direction omega Subscript . (Note that 0 less-than-or-equal-to upper G 1 left-parenthesis omega Subscript Baseline comma omega Subscript normal h Baseline right-parenthesis less-than-or-equal-to 1 .) In the usual case where the probability a microfacet is visible is independent of its orientation omega Subscript normal h , we can write this function as upper G 1 left-parenthesis omega Subscript Baseline right-parenthesis .

As shown in Figure 8.17, a differential area normal d upper A Subscript on the surface has area normal d upper A Subscript Baseline cosine theta when viewed from a direction omega Subscript that makes an angle theta with the surface normal. The area of visible microfacets seen from this direction must also be equal to normal d upper A Subscript Baseline cosine theta , which leads to a normalization constraint for upper G 1 :

cosine theta equals integral Underscript script upper H squared left-parenthesis bold n Subscript Baseline right-parenthesis Endscripts upper G 1 left-parenthesis omega Subscript Baseline comma omega Subscript normal h Baseline right-parenthesis max left-parenthesis 0 comma omega Subscript Baseline dot omega Subscript normal h Baseline right-parenthesis upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis normal d omega Subscript normal h Baseline period

In other words, the projected area of visible microfacets for a given direction omega Subscript must be equal to left-parenthesis omega Subscript Baseline dot bold n Subscript Baseline right-parenthesis equals cosine theta times the differential area of the macrosurface normal d upper A Subscript .

Figure 8.17: As seen from a viewer or a light source, a differential area on the surface has area normal d upper A Subscript Baseline cosine theta , where cosine theta is the angle of the incident direction with the surface normal. The projected surface area of visible microfacets (thick lines) must be equal to normal d upper A Subscript Baseline cosine theta as well; the masking-shadowing function upper G 1 gives the fraction of the total microfacet area over normal d upper A Subscript that is visible in the given direction.

Because the microfacets form a heightfield, every backfacing microfacet shadows a forward-facing microfacet of equal projected area in the direction omega . If upper A Superscript plus Baseline left-parenthesis omega Subscript Baseline right-parenthesis is the projected area of forward-facing microfacets as seen from the direction omega Subscript and upper A Superscript minus Baseline left-parenthesis omega Subscript Baseline right-parenthesis is the projected area of backward-facing microfacets from Equation (8.12), then cosine theta equals upper A Superscript plus Baseline left-parenthesis omega Subscript Baseline right-parenthesis minus upper A Superscript minus Baseline left-parenthesis omega Subscript Baseline right-parenthesis . We can thus alternatively write the masking-shadowing function as the ratio of visible microfacet area to total forward-facing microfacet area:

upper G 1 left-parenthesis omega Subscript Baseline right-parenthesis equals StartFraction upper A Superscript plus Baseline left-parenthesis omega Subscript Baseline right-parenthesis minus upper A Superscript minus Baseline left-parenthesis omega Subscript Baseline right-parenthesis Over upper A Superscript plus Baseline left-parenthesis omega Subscript Baseline right-parenthesis EndFraction period

Shadowing-masking functions are traditionally expressed in terms of an auxiliary function normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis , which measures invisible masked microfacet area per visible microfacet area.

normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis equals StartFraction upper A Superscript minus Baseline left-parenthesis omega Subscript Baseline right-parenthesis Over upper A Superscript plus Baseline left-parenthesis omega Subscript Baseline right-parenthesis minus upper A Superscript minus Baseline left-parenthesis omega Subscript Baseline right-parenthesis EndFraction equals StartFraction upper A Superscript minus Baseline left-parenthesis omega Subscript Baseline right-parenthesis Over cosine theta EndFraction period

The Lambda() method computes this function. Its implementation is specific to each microfacet distribution.

<<MicrofacetDistribution Public Methods>>+=  
virtual Float Lambda(const Vector3f &w) const = 0;

Some algebra lets us express upper G 1 left-parenthesis omega Subscript Baseline right-parenthesis in terms of normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis :

upper G 1 left-parenthesis omega Subscript Baseline right-parenthesis equals StartFraction 1 Over 1 plus normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis EndFraction comma

and therefore we can provide a G1() method in terms of Lambda().

<<MicrofacetDistribution Public Methods>>+=  
Float G1(const Vector3f &w) const { return 1 / (1 + Lambda(w)); }

The microfacet distribution alone doesn’t impose enough conditions to imply a specific normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis 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 normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis given upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis . (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 normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis 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, normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis for the isotropic Beckmann–Spizzichino distribution is

normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis equals one-half left-parenthesis normal e normal r normal f left-parenthesis a right-parenthesis minus 1 plus StartFraction normal e Superscript minus a squared Baseline Over a StartRoot pi EndRoot EndFraction right-parenthesis comma

where a equals 1 slash left-parenthesis alpha tangent theta right-parenthesis and normal e normal r normal f is the error function, normal e normal r normal f left-parenthesis x right-parenthesis equals 2 slash StartRoot pi EndRoot integral Subscript 0 Superscript x Baseline normal e Superscript minus x Super Superscript prime 2 Baseline normal d x Superscript prime Baseline .

pbrt’s computation of the Beckmann–Spizzichino normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis 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.

<<MicrofacetDistribution Method Definitions>>+=  
Float BeckmannDistribution::Lambda(const Vector3f &w) const { Float absTanTheta = std::abs(TanTheta(w)); if (std::isinf(absTanTheta)) return 0.; <<Compute alpha for direction w>> 
Float alpha = std::sqrt(Cos2Phi(w) * alphax * alphax + Sin2Phi(w) * alphay * alphay);
Float a = 1 / (alpha * absTanTheta); if (a >= 1.6f) return 0; return (1 - 1.259f * a + 0.396f * a * a) / (3.535f * a + 2.181f * a * a); }

Masking-shadowing functions for anisotropic distributions are most easily computed by taking their corresponding isotropic function and stretching the underlying microsurface according to the alpha Subscript x and alpha Subscript y values. Equivalently, one can compute an interpolated alpha 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.

<<Compute alpha for direction w>>= 
Float alpha = std::sqrt(Cos2Phi(w) * alphax * alphax + Sin2Phi(w) * alphay * alphay);

Under the uncorrelated height assumption, the form of normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis for the Trowbridge–Reitz distribution is quite simple:

normal upper Lamda left-parenthesis omega Subscript Baseline right-parenthesis equals StartFraction negative 1 plus StartRoot 1 plus alpha squared tangent squared theta EndRoot Over 2 EndFraction period

<<MicrofacetDistribution Method Definitions>>+=  
Float TrowbridgeReitzDistribution::Lambda(const Vector3f &w) const { Float absTanTheta = std::abs(TanTheta(w)); if (std::isinf(absTanTheta)) return 0.; <<Compute alpha for direction w>> 
Float alpha = std::sqrt(Cos2Phi(w) * alphax * alphax + Sin2Phi(w) * alphay * alphay);
Float alpha2Tan2Theta = (alpha * absTanTheta) * (alpha * absTanTheta); return (-1 + std::sqrt(1.f + alpha2Tan2Theta)) / 2; }

Figure 8.18 shows a plot of the Trowbridge–Reitz upper G 1 left-parenthesis omega Subscript Baseline right-parenthesis function for a few values of alpha . 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 alpha ) causes the function to fall off more quickly.

Figure 8.18: The Masking-Shadowing Function upper G 1 left-parenthesis omega Subscript Baseline right-parenthesis for the Trowbridge-Reitz Distribution. Increasing surface roughness (higher alpha values) cause the function to fall off to zero more quickly.

One last useful function related to the geometric properties of a microfacet distribution is upper G left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis , which gives the fraction of microfacets in a differential area that are visible from both directions omega Subscript normal o and omega Subscript normal i . Defining upper G requires some additional assumptions. For starters, we know that upper G 1 left-parenthesis omega Subscript normal o Baseline right-parenthesis gives the fraction of microfacets that are visible from the direction omega Subscript normal o and upper G 1 left-parenthesis omega Subscript normal i Baseline right-parenthesis gives the fraction for omega Subscript normal i . 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

upper G left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis equals upper G 1 left-parenthesis omega Subscript normal o Baseline right-parenthesis upper G 1 left-parenthesis omega Subscript normal i Baseline right-parenthesis period

In practice, however, these probabilities aren’t independent, and this formulation underestimates upper G . To see why, consider the case where omega Subscript normal o Baseline equals omega Subscript normal i ; in this case any microfacet that is visible from omega Subscript normal o is also visible from omega Subscript normal i , and so upper G left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis equals upper G 1 left-parenthesis omega Subscript normal o Baseline right-parenthesis equals upper G 1 left-parenthesis omega Subscript normal i Baseline right-parenthesis . Because upper G 1 left-parenthesis omega Subscript Baseline right-parenthesis less-than-or-equal-to 1 , their product in this case will cause upper G left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis to be too small (unless upper G 1 left-parenthesis omega Subscript Baseline right-parenthesis equals 1 , which is usually only true if omega Subscript Baseline equals left-parenthesis 0 comma 0 comma 1 right-parenthesis ). More generally, the closer together the two directions are, the more correlation there is between upper G 1 left-parenthesis omega Subscript normal o Baseline right-parenthesis and upper G 1 left-parenthesis omega Subscript normal i Baseline right-parenthesis .

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

upper G left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis equals StartFraction 1 Over 1 plus normal upper Lamda left-parenthesis omega Subscript normal o Baseline right-parenthesis plus normal upper Lamda left-parenthesis omega Subscript normal i Baseline right-parenthesis EndFraction period

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 upper G left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis functions.

<<MicrofacetDistribution Public Methods>>+=  
Float G(const Vector3f &wo, const Vector3f &wi) const { return 1 / (1 + Lambda(wo) + Lambda(wi)); }

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,

omega Subscript normal h Baseline equals ModifyingAbove omega Subscript normal i Baseline plus omega Subscript normal o Baseline With caret comma

cause perfect specular reflection from omega Subscript normal i to omega Subscript normal o (Figure 8.19).

Figure 8.19: For perfectly specular microfacets and a given pair of directions omega Subscript normal i and omega Subscript normal o , only those microfacets with normal omega Subscript normal h Baseline equals ModifyingAbove omega Subscript normal i Baseline plus omega Subscript normal o Baseline With caret reflect light from omega Subscript normal i to omega Subscript normal o .

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 normal d normal upper Phi Subscript normal h incident on the microfacets oriented with half-angle omega Subscript normal h for directions omega Subscript normal i and omega Subscript normal o . From the definition of radiance, Equation (5.2), it is

normal d normal upper Phi Subscript normal h Baseline equals upper L Subscript normal i Superscript Baseline left-parenthesis omega Subscript normal i Baseline right-parenthesis normal d omega Subscript Baseline normal d upper A Subscript Superscript up-tack Baseline left-parenthesis omega Subscript normal h Baseline right-parenthesis equals upper L Subscript normal i Superscript Baseline left-parenthesis omega Subscript normal i Baseline right-parenthesis normal d omega Subscript Baseline cosine theta Subscript normal h Baseline normal d upper A Subscript Baseline left-parenthesis omega Subscript normal h Baseline right-parenthesis comma

where we have written normal d upper A Subscript Baseline left-parenthesis omega Subscript normal h Baseline right-parenthesis for the area measure of the microfacets with orientation omega Subscript normal h and cosine theta Subscript normal h for the cosine of the angle between omega Subscript normal i and omega Subscript normal h (Figure 8.20).

Figure 8.20: Setting for the Derivation of the Torrance–Sparrow Model. For directions omega Subscript normal i and omega Subscript normal o , only microfacets with normal omega Subscript normal h reflect light. The angle between omega Subscript normal h and bold n Subscript is denoted by theta , and the angle between omega Subscript normal h and omega Subscript normal o is denoted by theta Subscript normal h . (The angle between omega Subscript normal h and omega Subscript normal i is also necessarily theta Subscript normal h .)

The differential area of microfacets with orientation omega Subscript normal h is

normal d upper A Subscript Baseline left-parenthesis omega Subscript normal h Baseline right-parenthesis equals upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis normal d omega Subscript normal h Baseline normal d upper A Subscript Baseline period

The first two terms of this product describe the differential area of facets per unit area that have the proper orientation, and the normal d upper A Subscript term converts this to differential area.

Therefore,

normal d normal upper Phi Subscript normal h Baseline equals upper L Subscript normal i Superscript Baseline left-parenthesis omega Subscript normal i Baseline right-parenthesis normal d omega Subscript Baseline cosine theta Subscript normal h Baseline upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis normal d omega Subscript normal h Baseline normal d upper A Subscript Baseline period

If we assume that the microfacets individually reflect light according to Fresnel’s law, the outgoing flux is

normal d normal upper Phi Subscript normal o Baseline equals upper F Subscript normal r Baseline left-parenthesis omega Subscript normal o Baseline right-parenthesis normal d normal upper Phi Subscript normal h Baseline period

Again using the definition of radiance, the reflected outgoing radiance is

upper L Subscript Superscript Baseline left-parenthesis omega Subscript normal o Baseline right-parenthesis equals StartFraction normal d normal upper Phi Subscript normal o Baseline Over normal d omega Subscript normal o Baseline cosine theta Subscript normal o Baseline normal d upper A Subscript Baseline EndFraction period

If we substitute Equation (8.16) into this and then Equation (8.15) into the result, we have

upper L Subscript Superscript Baseline left-parenthesis omega Subscript normal o Baseline right-parenthesis equals StartFraction upper F Subscript normal r Baseline left-parenthesis omega Subscript normal o Baseline right-parenthesis upper L Subscript normal i Superscript Baseline left-parenthesis omega Subscript normal i Baseline right-parenthesis normal d omega Subscript normal i Baseline upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis normal d omega Subscript normal h Baseline normal d upper A Subscript Baseline cosine theta Subscript normal h Baseline Over normal d omega Subscript normal o Baseline normal d upper A Subscript Baseline cosine theta Subscript normal o Baseline EndFraction period

In Section 14.1.1, we will derive an important relationship between normal d omega Subscript normal h and normal d omega Subscript normal o under specular reflection:

normal d omega Subscript normal h Baseline equals StartFraction normal d omega Subscript normal o Baseline Over 4 cosine theta Subscript normal h Baseline EndFraction period

We can substitute this relationship into the previous equation and simplify, giving

upper L left-parenthesis omega Subscript normal o Baseline right-parenthesis equals StartFraction upper F Subscript normal r Baseline left-parenthesis omega Subscript normal o Baseline right-parenthesis upper L Subscript normal i Superscript Baseline left-parenthesis omega Subscript normal i Baseline right-parenthesis upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis normal d omega Subscript normal i Baseline Over 4 cosine theta Subscript normal o Baseline EndFraction period

We can now apply the definition of the BRDF, Equation (5.8) and add the geometric attenuation term upper G left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis , which gives us the Torrance–Sparrow BRDF:

f Subscript normal r Baseline left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis equals StartFraction upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis upper G left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis upper F Subscript normal r Baseline left-parenthesis omega Subscript normal o Baseline right-parenthesis Over 4 cosine theta Subscript normal o Baseline cosine theta Subscript normal i Baseline EndFraction period

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 normal d omega Subscript normal h and normal d omega Subscript normal o 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.

<<BxDF Declarations>>+=  
class MicrofacetReflection : public BxDF { public: <<MicrofacetReflection Public Methods>> 
MicrofacetReflection(const Spectrum &R, MicrofacetDistribution *distribution, Fresnel *fresnel) : BxDF(BxDFType(BSDF_REFLECTION | BSDF_GLOSSY)), R(R), distribution(distribution), fresnel(fresnel) { } Spectrum f(const Vector3f &wo, const Vector3f &wi) const; Spectrum Sample_f(const Vector3f &wo, Vector3f *wi, const Point2f &u, Float *pdf, BxDFType *sampledType) const; Float Pdf(const Vector3f &wo, const Vector3f &wi) const;
private: <<MicrofacetReflection Private Data>> 
const Spectrum R; const MicrofacetDistribution *distribution; const Fresnel *fresnel;
};

Its constructor takes the reflectance, a pointer to a MicrofacetDistribution implementation, and a Fresnel function.

<<MicrofacetReflection Public Methods>>= 
MicrofacetReflection(const Spectrum &R, MicrofacetDistribution *distribution, Fresnel *fresnel) : BxDF(BxDFType(BSDF_REFLECTION | BSDF_GLOSSY)), R(R), distribution(distribution), fresnel(fresnel) { }

<<MicrofacetReflection Private Data>>= 
const Spectrum R; const MicrofacetDistribution *distribution; const Fresnel *fresnel;

Evaluating the terms of the Torrance–Sparrow BRDF is straightforward. For the Fresnel term, recall that given specular reflection, the angle theta Subscript normal h is the same between omega Subscript normal h and both omega Subscript normal i and omega Subscript normal o , so it doesn’t matter which vector we use to compute the cosine of theta Subscript normal h . We arbitrarily choose  omega Subscript normal i .

<<BxDF Method Definitions>>+=  
Spectrum MicrofacetReflection::f(const Vector3f &wo, const Vector3f &wi) const { Float cosThetaO = AbsCosTheta(wo), cosThetaI = AbsCosTheta(wi); Vector3f wh = wi + wo; <<Handle degenerate cases for microfacet reflection>> 
if (cosThetaI == 0 || cosThetaO == 0) return Spectrum(0.); if (wh.x == 0 && wh.y == 0 && wh.z == 0) return Spectrum(0.);
wh = Normalize(wh); Spectrum F = fresnel->Evaluate(Dot(wi, wh)); return R * distribution->D(wh) * distribution->G(wo, wi) * F / (4 * cosThetaI * cosThetaO); }

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.

<<Handle degenerate cases for microfacet reflection>>= 
if (cosThetaI == 0 || cosThetaO == 0) return Spectrum(0.); if (wh.x == 0 && wh.y == 0 && wh.z == 0) return Spectrum(0.);

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 eta Subscript normal i to a medium with index of refraction eta Subscript normal t , then normal d omega Subscript normal h and normal d omega Subscript normal o are related by:

normal d omega Subscript normal h Baseline equals StartFraction eta Subscript normal o Superscript 2 Baseline StartAbsoluteValue omega Subscript normal o Baseline dot omega Subscript normal h Baseline EndAbsoluteValue normal d omega Subscript normal o Baseline Over left-parenthesis eta Subscript normal i Baseline left-parenthesis omega Subscript normal i Baseline dot omega Subscript normal h Baseline right-parenthesis plus eta Subscript normal o Baseline left-parenthesis omega Subscript normal o Baseline dot omega Subscript normal h Baseline right-parenthesis right-parenthesis squared EndFraction

This relationship can be used in place of Equation (8.17) in the derivation of the Torrance–Sparrow BRDF. The result is

f Subscript normal r Baseline left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis equals StartFraction upper D left-parenthesis omega Subscript normal h Baseline right-parenthesis upper G left-parenthesis omega Subscript normal o Baseline comma omega Subscript normal i Baseline right-parenthesis left-parenthesis 1 minus upper F Subscript normal r Baseline left-parenthesis omega Subscript normal o Baseline right-parenthesis right-parenthesis Over left-parenthesis left-parenthesis omega Subscript normal o Baseline dot omega Subscript normal h Baseline right-parenthesis plus eta left-parenthesis omega Subscript normal i Baseline dot omega Subscript normal h Baseline right-parenthesis right-parenthesis squared EndFraction StartFraction StartAbsoluteValue omega Subscript normal i Baseline dot omega Subscript normal h Baseline EndAbsoluteValue StartAbsoluteValue omega Subscript normal o Baseline dot omega Subscript normal h Baseline EndAbsoluteValue Over cosine theta Subscript normal o Baseline cosine theta Subscript normal i Baseline EndFraction comma

where eta equals eta Subscript normal i Baseline slash eta Subscript normal o . For specular transmission, the half-angle vector is

omega Subscript normal h Baseline equals omega Subscript normal o Baseline plus eta omega Subscript normal i Baseline period

(You may want to verify that this normal vector causes omega Subscript normal o to be refracted in the direction omega Subscript normal i , via Equation (8.8).)

The MicrofacetTransmission class implements this BTDF.

<<BxDF Declarations>>+=  
class MicrofacetTransmission : public BxDF { public: <<MicrofacetTransmission Public Methods>> 
MicrofacetTransmission(const Spectrum &T, MicrofacetDistribution *distribution, Float etaA, Float etaB, TransportMode mode) : BxDF(BxDFType(BSDF_TRANSMISSION | BSDF_GLOSSY)), T(T), distribution(distribution), etaA(etaA), etaB(etaB), fresnel(etaA, etaB), mode(mode) { } Spectrum f(const Vector3f &wo, const Vector3f &wi) const; Spectrum Sample_f(const Vector3f &wo, Vector3f *wi, const Point2f &u, Float *pdf, BxDFType *sampledType) const; Float Pdf(const Vector3f &wo, const Vector3f &wi) const;
private: <<MicrofacetTransmission Private Data>> 
const Spectrum T; const MicrofacetDistribution *distribution; const Float etaA, etaB; const FresnelDielectric fresnel; const TransportMode mode;
};

<<MicrofacetTransmission Public Methods>>= 
MicrofacetTransmission(const Spectrum &T, MicrofacetDistribution *distribution, Float etaA, Float etaB, TransportMode mode) : BxDF(BxDFType(BSDF_TRANSMISSION | BSDF_GLOSSY)), T(T), distribution(distribution), etaA(etaA), etaB(etaB), fresnel(etaA, etaB), mode(mode) { }

<<MicrofacetTransmission Private Data>>= 
const Spectrum T; const MicrofacetDistribution *distribution; const Float etaA, etaB; const FresnelDielectric fresnel; const TransportMode mode;

Its f() method is a direct transcription of Equation (8.19). Its implementation is therefore not included here.

<<MicrofacetTransmission Public Methods>>+= 
Spectrum f(const Vector3f &wo, const Vector3f &wi) const;

Figure 8.21 shows the dragon rendered with the Torrance–Sparrow model and both reflection and transmission.

Figure 8.21: Dragon models rendered with the Torrance–Sparrow microfacet model featuring both reflection (a) and transmission (b). (Model courtesy of Christian Schüller.)

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.

Figure 8.22: Spheres rendered with an isotropic microfacet distribution (left) and an anisotropic distribution (right). Note the different specular highlight shapes from the anisotropic model. We have used spheres here instead of the dragon, since anisotropic models like these depend on a globally consistent set of tangent vectors over the surface to orient the direction of anisotropy in a reasonable way.