9.8 Measured BSDFs
The reflection models introduced up to this point represent index of refraction changes at smooth and rough boundaries, which constitute the basic building blocks of surface appearance. More complex materials (e.g., paint on primer, metal under a layer of enamel) can sometimes be approximated using multiple interfaces with participating media between them; the layered material model presented in Section 14.3 is based on that approach.
However, many real-world materials are beyond the scope of even such layered models. Examples include:
- Materials characterized by wave-optical phenomena that produce striking directionally varying coloration. Examples include iridescent paints, insect wings, and holographic paper.
- Materials with rough interfaces. In pbrt, we have chosen to model such surfaces using microfacet theory and the Trowbridge–Reitz distribution. However, it is important to remember that both of these are models that generally do not match real-world behavior perfectly.
- Surfaces with non-standard microstructure. For example, a woven fabric composed of two different yarns looks like a surface from a distance, but its directional intensity and color variation are not well-described by any standard BRDF model due to the distinct reflectance properties of fiber-based microgeometry.
Instead of developing numerous additional specialized BxDFs, we will now pursue another way of reproducing such challenging materials in a renderer: by interpolating measurements of real-world material samples to create a data-driven reflectance model. The resulting MeasuredBxDF only models surface reflection, though the approach can in principle generalize to transmission as well.
Measuring reflection in a way that is practical while producing information in a form that is convenient for rendering is a challenging problem. We begin by explaining these challenges for motivation.
Consider the task of measuring the BRDF of a sheet of brushed aluminum: we could illuminate a sample of the material from a set of incident directions with and use some kind of sensor (e.g., a photodiode) to record the reflected light scattered along a set of outgoing directions with . These measurements could be stored on disk and interpolated at runtime to approximate the BRDF at intermediate configurations . However, closer scrutiny of such an approach reveals several problems:
- BSDFs of polished materials are highly directionally peaked. Perturbing the incident or outgoing direction by as little as 1 degree can change the measured reflectance by orders of magnitude. This implies that the set of incident and outgoing directions must be sampled fairly densely.
- Accurate positioning in spherical coordinates is difficult to perform by hand and generally requires mechanical aids. For this reason, such measurements are normally performed using a motorized gantry known as a goniophotometer or gonioreflectometer. Figure 9.33 shows two examples of such machines. Light stages consisting of a rigid assembly of hundreds of LEDs around a sample are sometimes used to accelerate measurement, though at the cost of reduced directional resolution.
- Sampling each direction using a 1 degree spacing in spherical coordinates requires roughly one billion sample points. Storing gigabytes of measurement data is possible but undesirable, yet the time that would be spent for a full measurement is even more problematic: assuming that the goniophotometer can reach a configuration within 1 second (a reasonable estimate for the devices shown in Figure 9.33), over 34 years of sustained operation would be needed to measure a single material.
In sum, the combination of high-frequency signals, the 4D domain of the BRDF, and the curse of dimensionality conspire to make standard measurement approaches all but impractical.
While there is no general antidote against the curse of dimensionality, the previous example involving a dense discretization of the 4D domain is clearly excessive. For example, peaked BSDFs that concentrate most of their energy into a small set of angles tend to be relatively smooth away from the peak. Figure 9.34 shows how a more specialized sample placement that is informed by the principles of specular reflection can drastically reduce the number of sample points that are needed to obtain a desired level of accuracy. Figure 9.35 shows how the roughness of the surface affects the desired distribution of samples—for example, smooth surfaces allow sparse sampling outside of the specular lobe.
The MeasuredBxDF therefore builds on microfacet theory and the distribution of visible normals to create a more efficient physically informed sampling pattern. The rationale underlying this choice is that while microfacet theory may not perfectly predict the reflectance of a specific material, it can at least approximately represent how energy is (re-)distributed throughout the 4D domain. Applying it enables the use of a relatively coarse set of measurement locations that suffice to capture the function’s behavior.
Concretely, the method works by transforming regular grid points using visible normal sampling (Section 9.6.4) and performing a measurement at each sampled position. If the microfacet sampling routine is given by a function and with denotes input samples arranged on a grid covering the 2D unit square, then we have a sequence of measurements :
where refers to the real-world BRDF of a material sample, as measured by a goniophotometer (or similar device) in directions and . This process must be repeated for different values of to also capture variation in the other direction argument. Evaluating the BRDF requires the inverse of the transformation, which yields a position on that can be used to interpolate the measurements . Figure 9.36 illustrates both directions of this mapping.
This procedure raises several questions: first, the non-random use of a method designed for Monte Carlo sampling may be unexpected. To see why this works, remember that the inversion method (Section 2.3) evaluates the inverse of a distribution’s cumulative distribution function (CDF). Besides being convenient for sampling, this inverse CDF can also be interpreted as a parameterization of the target domain from the unit square. This parameterization smoothly warps the domain so that regions with a high contribution occupy a correspondingly large amount of the unit square. The MeasuredBxDF then simply measures and stores BRDF values in these “improved” coordinates. Note that the material does not have to agree with microfacet theory for this warping to be valid, though the sampling pattern is much less efficient and requires a denser discretization when the material’s behavior deviates significantly.
Another challenge is that parameterization guiding the measurement requires a microfacet approximation of the material, but such an approximation would normally be derived from an existing measurement. We will shortly show how to resolve this chicken-and-egg problem and assume for now that a suitable model is available.
Measurement Through a Parameterization
A flaw of the reparameterized measurement sequence in Equation (9.41) is that the values may differ by many orders of magnitude, which means that simple linear interpolation between neighboring data points is unlikely to give satisfactory results. We instead use the following representation that transforms measurements prior to storage in an effort to reduce this variation:
where , and denotes the density of direction according to visible normal sampling.
If was an analytic BRDF (e.g., a microfacet model) and a 2D uniform variate, then Equation (9.42) would simply be the weight of a Monte Carlo importance sampling strategy, typically with a carefully designed mapping and density that make this weight near-constant to reduce variance.
In the present context, represents real-world data, while and encapsulate a microfacet approximation of the material under consideration. We therefore expect to take on near-constant values when the material is well-described by a microfacet model, and more marked deviations otherwise. This can roughly be interpreted as measuring the difference (in a multiplicative sense) between the real world and the microfacet simplification. Figure 9.37 visualizes the effect of the transformation in Equation (9.42).
BRDF Evaluation
Evaluating the data-driven BRDF requires the inverse of these steps. Suppose that implements an interpolation based on the grid of measurement points . Furthermore, suppose that we have access to the inverse that returns the “random numbers” that would cause visible normal sampling to generate a particular incident direction (i.e., ). Accessing through then provides a spherical interpolation of the measurement data.
We must additionally multiply by the density , and divide by the cosine factor to undo corresponding transformations introduced in Equation (9.42), which yields the final form of the data-driven BRDF:
Generalized Microfacet Model
A major difference between the microfacet model underlying the ConductorBxDF and the approximation used here is that we replace the Trowbridge–Reitz model with an arbitrary data-driven microfacet distribution. This improves the model’s ability to approximate the material being measured. At the same time, it implies that previously used simplifications and analytic solutions are no longer available and must be revisited.
We begin with the Torrance–Sparrow sampling density from Equation (9.28),
which references the visible normal sampling density from Equation (9.23). Substituting the definition of the masking function from Equation (9.18) into and rearranging terms yields
where
provides a direction-dependent normalization of the visible normal distribution. For valid reflection directions (), the PDF of generated samples then simplifies to
The MeasuredBxDF implements this expression using data-driven representations of and .
Finding the Initial Microfacet Model
We finally revisit the chicken-and-egg problem from before: practical measurement using the presented approach requires a suitable microfacet model—specifically, a microfacet distribution . Yet it remains unclear how this distribution could be obtained without access to an already existing BRDF measurement.
The key idea to resolve this conundrum is that the microfacet distribution is a 2D quantity, which means that it remains mostly unaffected by the curse of dimensionality. Acquiring this function is therefore substantially cheaper than a measurement of the full 4D BRDF.
Suppose that the material being measured perfectly matches microfacet theory in the sense that it is described by the Torrance–Sparrow BRDF from Equation (9.33). Then we can measure the material’s retroreflection (i.e., ), which is given by
The last step of the above equation removes constant terms including the Fresnel reflectance and introduces the reasonable assumption that shadowing/masking is perfectly correlated given and thus occurs only once. Substituting the definition of from Equation (9.18) and rearranging yields the following relationship of proportionality:
This integral equation can be solved by measuring for directions and using those measurements for initial guesses of . A more accurate estimate of can then be found using an iterative solution procedure where the estimated values of are used to estimate the integrals on the right hand side of Equation (9.46) for all of the s. This process quickly converges within a few iterations.
9.8.1 Basic Data Structures
MeasuredBxDFData holds data pertaining to reflectance measurements and the underlying parameterization. Because the data for an isotropic BRDF is typically a few megabytes and the data for an anisotropic BRDF may be over 100, each measured BRDF that is used in the scene is stored in memory only once. As instances of MeasuredBxDF are created at surface intersections during rendering, they can then store just a pointer to the appropriate MeasuredBxDFData. Code not included here adds the ability to initialize instances of this type from binary .bsdf files containing existing measurements.
Measured BRDFs are represented by spectral measurements at a set of discrete wavelengths that are stored in wavelengths. The actual measurements are stored in spectra.
The template class PiecewiseLinear2D represents a piecewise-linear interpolant on the 2D unit square with samples arranged on a regular grid. The details of its implementation are relatively technical and reminiscent of other interpolants in this book; hence we only provide an overview of its capabilities and do not include its full implementation here.
The class is parameterized by a Dimension template parameter that extends the 2D interpolant to higher dimensions—for example, PiecewiseLinear2D<1> stores a 3D grid of values, and PiecewiseLinear2D<3> used above for spectra is a 5D quantity. The class provides three key methods:
where PLSample is defined as
Evaluate() takes a position and then additional Float parameters to perform a lookup using multidimensional linear interpolation according to the value of Dimension.
Sample() warps via inverse transform sampling (i.e., proportional to the stored linear interpolant), returning both the sampled position on and the associated density as a PLSample. The additional parameters passed via params are used as conditional variables that restrict sampling to a 2D slice of a higher-dimensional function. For example, invoking the method PiecewiseLinear2D<3>::Sample() with a uniform 2D variate and parameters , , and would importance sample the 2D slice of a pentalinear interpolant .
Finally, Invert() implements the exact inverse of Sample(). Invoking it with the position computed by Sample() will recover the input u value up to rounding error.
Additional PiecewiseLinear1D instances are used to (redundantly) store the normal distribution in ndf, the visible normal distribution parameterized by in vndf, and the normalization constant in sigma. The data structure also records whether the material is isotropic, in which case the dimensionality of some of the piecewise-linear interpolants can be reduced.
9.8.2 Evaluation
Following these preliminaries, we can now turn to evaluating the measured BRDF for a pair of directions. See Figure 9.38 for examples of the variety of types of reflection that the measured representation can reproduce.
The only information that must be stored as MeasuredBxDF member variables in order to implement the BxDF interface methods is a pointer to the BRDF measurement data and the set of wavelengths at which the BRDF is to be evaluated.
BRDF evaluation then follows the approach described in Equation (9.45).
Zero reflection is returned if the specified directions correspond to transmission through the surface. Otherwise, the directions and are mirrored onto the positive hemisphere if necessary.
The next code fragment determines the associated microfacet normal and handles an edge case that occurs in near-grazing configurations.
A later step requires that and are mapped onto the unit square , which we do in two steps: first, by converting the directions to spherical coordinates, which are then further transformed by helper methods theta2u() and phi2u().
In the isotropic case, the mapping used for subtracts from , which allows the stored tables to be invariant to rotation about the surface normal. This may cause the second dimension of u_wm to fall out of the interval; a subsequent correction fixes this using the periodicity of the azimuth parameter.
The two helper functions encapsulate an implementation detail of the storage representation. The function phi2u() uniformly maps onto , while theta2u() uses a nonlinear transformation that places more resolution near to facilitate storing the microfacet distribution of highly specular materials.
With this information at hand, we can now evaluate the inverse parameterization to determine the sample values ui.p that would cause visible normal sampling to generate the current incident direction (i.e., ).
This position is then used to evaluate a 5D linear interpolant parameterized by the fractional 2D position on the reparameterized incident hemisphere, , , and the wavelength in nanometers. The interpolant must be evaluated once per sample of SampledSpectrum.
Finally, fr must be scaled to undo the transformations that were applied to the data to improve the quality of the interpolation and to reduce the required measurement density, giving the computation that corresponds to Equation (9.45).
In principle, implementing the Sample_f() and PDF() methods required by the BxDF interface is straightforward: the Sample_f() method could evaluate the forward mapping to perform visible normal sampling based on the measured microfacet distribution using PiecewiseLinear2D::Sample(), and PDF() could evaluate the associated sampling density from Equation (9.44). However, a flaw of such a basic sampling scheme is that the transformed BRDF measurements from Equation (9.42) are generally nonuniform on , which can inject unwanted variance into the rendering process. The implementation therefore uses yet another reparameterization based on a luminance tensor that stores the product integral of the spectral dimension of MeasuredBxDFData::spectra and the CIE Y color matching curve.
The actual BRDF sampling routine then consists of two steps. First it converts a uniformly distributed sample on into another sample that is distributed according to the luminance of the reparameterized BRDF. Following this, visible normal sampling transforms into a sampled direction and a sampling weight that will have near-constant luminance. Apart from this step, the implementations of Sample_f() and PDF() are similar to the evaluation method and therefore not included here.