转载请注明出处为KlayGE游戏引擎,本文的永久链接为http://www.klayge.org/?p=516

In last article “Physically-based Rendering in Game, Part 2“, I introduce lighting equations. In this one, I will explain you physically-based BRDF.

Microfacet BRDF

The basis for most physically-based specular BRDF terms is microfacet theory. This theory was developed to describe surface reflection from general (non-optically flat) surfaces. The basic assumption underlying microfacet theory is that the surface is composed of many microfacets, too small to be seen individually. Each microfacet is assumed to be optically flat.

Each of these microfacets reflects light from a given incoming direction into a single outgoing direction which depends on the orientation of the microfacet normal m. When evaluating a BRDF term, both the light direction l and the view direction v are specified. This means that of all the millions of microfacets on the surface, only those that happen to be angled just right to reflect l into v have any contribution to the BRDF value. In the figure below, we can see that these active microfacets have their surface normal m oriented exactly halfway between l and v. We will denote it as h.

Microfacet

Not all microfacets for which m = h will contribute to the reflection; some are blocked by other microfacets from the direction of l (shadowing), from the direction of v (masking), or from both. Microfacet theory assumes that all shadowed light is lost from the specular term. The microfacet specular BRDF term has the following form:

[latex]\rho(\mathbf{l}, \mathbf{v})=\frac{F(\mathbf{l},\mathbf{h})G(\mathbf{l},\mathbf{v},\mathbf{h})D(\mathbf{h})}{4(\mathbf{n} \cdot \mathbf{l})(\mathbf{n} \cdot \mathbf{v})}[/latex]

[latex]F(\mathbf{l}, \mathbf{h})[/latex] is the Fresnel reflectance of the active microfacets (m = h). [latex]G(\mathbf{l}, \mathbf{v}, \mathbf{h})[/latex] is the proportion of active microfacets which are not shadowed or masked. [latex]D(\mathbf{h})[/latex] is the microfacet normal distribution function evaluated at the active microfacet normal m = h; in other words, the concentration of microfacets with normals equal to h. Finally, the denominator [latex]4(\mathbf{n} \cdot \mathbf{l})(\mathbf{n} \cdot \mathbf{v})[/latex] is a correction factor which accounts for quantities being transformed between the local space of the microfacets and that of the overall macrosurface.

Fresnel Term

The Fresnel reflectance term computes the fraction of light reflected from an optically flat surface. Its value depends on two things: the incoming angle (angle between light vector and surface normal) and the refractive index of the material. The Schlick approximation of Fresnel term is:

[latex]F_{Schlick}(\mathbf{c}_{spec}, \mathbf{l}, \mathbf{h})=\mathbf{c}_{spec}+(1-\mathbf{c}_{spec})(1-\mathbf{l} \cdot \mathbf{h})^5[/latex]

which [latex]\mathbf{c}_{spec}[/latex] is the specular color.

Normal Distribution Term

In most surfaces, the microfacet’s orientations are not uniformly distributed. Microfacet normals closer to the macroscopic surface normal tend to appear with smoother. The exact distribution is defined via the microfacet normal distribution function D(m). The function D() determines the size, brightness, and shape of the specular highlight. Normal distribution functions have some kind of “roughness” or variance parameter (anisotropic functions typically have two variance parameters).

Shadowing-Masking Term

The shadowing and masking term G(l, v, h) is also often called the geometry term. In many cases, the shadowing-masking term partially cancels out the [latex](\mathbf{n} \cdot \mathbf{l})(\mathbf{n} \cdot \mathbf{v})[/latex] denominator in microfacet BRDF equation, replacing it with some other expression such as [latex]max(\mathbf{n} \cdot \mathbf{l}, \mathbf{n} \cdot \mathbf{v})[/latex]. The shadowing-masking term is essential for BRDF energy conservation–without such a term the BRDF can reflect arbitrarily more light energy than it receives. A key part of the microfacet BRDF is the ratio between the active area (combined area of the microfacets which reflect light energy from l to v) and the total area (of the macroscopic surface). If shadowing and masking are not accounted for, then the active area may exceed the total area, an obvious impossibility which can lead to the BRDF not conserving energy, in some cases by a huge amount, as you see below:

Shadowing Masking Term

On the top the flat macroscopic surface is shown in green, and the rugged microscopic surface is shown in blue. The facets for which m = h are marked in red. The projection of the macroscopic surface area onto the view direction is shown as a green line on the upper left. The projected areas of the individual red microfacets are shown as separate red lines. On the bottom left the areas of the red microfacets are added up without accounting for masking, resulting in an active area greater than the total area. So the BRDF illogically reflects more energy than it receives. On the right we see that the red areas are combined in a way that accounts for masking. The overlapping areas are no longer counted multiple times, and we see that the correct active area is smaller than the total area.

Talking so much about BRDF, this article ends here. The next article will explain the difference between BRDF in most current game and physically-based BRDF.