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

In my last article “Physically-based Rendering in Game, Part 3“, I explained microfacet BRDF. Here I will talk about the difference between BRDF in most current game and physically-based BRDF.

Firstly we review the equation from my second article:

[latex]L_0(\mathbf{v})=\pi \rho(\mathbf{l_c}, \mathbf{v}) \otimes \mathbf{c}_{light} (\mathbf{n} \cdot \mathbf{l_c})[/latex]

Comparison

The reflectance equation common used in game look like this:

[latex]L_{o}(\mathbf{v})=(\mathbf{c}_{diff} (\mathbf{n} \cdot \mathbf{l_c}) + \mathbf{c}_{spec}(\mathbf{r_v} \cdot \mathbf{l_c})^{\alpha}) \otimes \mathbf{c}_{light} [/latex]

According to my first article, [latex](\mathbf{n} \cdot \mathbf{l_c})[/latex] is part of reflectance equation, not diffuse term. So it should be:

[latex]L_{o}(\mathbf{v})=(\mathbf{c}_{diff} + \mathbf{c}_{spec}(\mathbf{r_v} \cdot \mathbf{l_c})^{\alpha}) \otimes \mathbf{c}_{light} (\mathbf{n} \cdot \mathbf{l_c})[/latex]

where [latex]\mathbf{r_v}[/latex] is the view vector reflected about the normal. It’s from Phong model. It doesn’t seem to correspond to anything from microfacet theory in my last article. The Blinn-Phong model is very similar to this equation, but it uses the more physically meaningful half-vector h, which is microfacet’s normal m. Changing from Phong to Blinn-Phong gives us the following model:

[latex]L_{o}(\mathbf{v})=(\mathbf{c}_{diff} + \pi \mathbf{c}_{spec}(\mathbf{n} \cdot \mathbf{h})^{\alpha}) \otimes \mathbf{c}_{light} (\mathbf{n} \cdot \mathbf{l_c})[/latex]

Recall the Lambert term from the first article, the diffuse term now is the same with physically-based one:

[latex]\mathbf{c}_{diff} = \pi \frac {\mathbf{c}_{diff}} {\pi}[/latex]

So, now we focus on specular term. If we look at the specular term only in the equation before:

[latex]L_{o}(\mathbf{v})=\pi (\mathbf{n} \cdot \mathbf{h})^{\alpha} \mathbf{c}_{spec} \otimes \mathbf{c}_{light} (\mathbf{n} \cdot \mathbf{l_c})[/latex]

Compare to microfacet specular:

[latex]L_{o}(\mathbf{v})=\pi \frac{D(\mathbf{h})G(\mathbf{l_c},\mathbf{v},\mathbf{h})}{4(\mathbf{n} \cdot \mathbf{l_c})(\mathbf{n} \cdot \mathbf{v})}F(\mathbf{c}_{spec}, \mathbf{l_c},\mathbf{h}) \otimes \mathbf{c}_{light} (\mathbf{n} \cdot \mathbf{l_c})[/latex]

Firstly, we can see from these two equations, the [latex]\mathbf{c}_{spec}[/latex] in game can be replaced by Fresnel’s [latex]F(\mathbf{c}_{spec}, \mathbf{l_c}, \mathbf{h})[/latex].

Secondly, recall my last article, I mentioned that [latex]D(\mathbf{h})[/latex] is related to roughness. So [latex]D(\mathbf{h})[/latex] and Blinn-Phong’s [latex](\mathbf{n} \cdot \mathbf{h})^{\alpha}[/latex] have similar functions. However, to convert the [latex](\mathbf{n} \cdot \mathbf{h})^{\alpha}[/latex] term into a microfacet normal distribution function it must be correctly normalized. It means the sum of the signed projected areas of the microfacets needs to equal the signed projected area of the macroscopic surface; this must hold true for any viewing direction. Mathematically, this means that the function must fulfil this equation for any v:

[latex](\mathbf{v} \cdot \mathbf{n}) = \int_{\Theta} D(\mathbf{m})(\mathbf{v} \cdot \mathbf{m}) d\omega_m[/latex]

This equation holds for any viewing direction. In the special case, v = n:

[latex]1 = \int_{\Theta} D(\mathbf{m})(\mathbf{n} \cdot \mathbf{m}) d\omega_m[/latex]

The Blinn-Phong cosine power term can be made to obey this equation by multiplying it with a simple normalization factor:

[latex]D_{BP}=\frac {\alpha + 2} {2\pi}(\mathbf{n} \cdot \mathbf{m})^{\alpha}[/latex]

The only term left is:

[latex]\frac {G(\mathbf{l_c},\mathbf{v},\mathbf{h})}{(\mathbf{n} \cdot \mathbf{l_c})(\mathbf{n} \cdot \mathbf{v})}[/latex]

It’s shadowing/masking, or geometry term divided by the foreshortening factors. The physical meaning of this term is visibility. Since our modified specular model has no visibility term, we will simply set it to 1.  That is:

[latex]G_{implicit}(\mathbf{l_c},\mathbf{v},\mathbf{h}) = (\mathbf{n} \cdot \mathbf{l_c})(\mathbf{n} \cdot \mathbf{v})[/latex]

This is actually a plausible geometry term for a heightfield microsurface (which is what the Blinn-Phong normal distribution function corresponds to, since it is zero for all backfacing microfacets). [latex]G_{implicit}()[/latex] is equal to 1 when l = n and v = n, which is correct for a heightfield (no microfacets are occluded from the direction of the macrosurface normal). It goes to 0 for either glancing view angles or glancing light angles, which again is correct (the probability of a microfacet being occluded by other microfacets increases with viewing angle).

Until now, several terms from microfacet specular BRDF are all explained, leaving us this rendering model:

[latex]L_{o}(\mathbf{v})=\frac {\alpha + 2} {8}(\mathbf{n} \cdot \mathbf{h})^{\alpha} F(\mathbf{c}_{spec}, \mathbf{l_c},\mathbf{h}) \otimes \mathbf{c}_{light} (\mathbf{n} \cdot \mathbf{l_c})[/latex]

The factor is because of [latex]\frac {\alpha + 2} {2\pi} \frac{\pi} {4} = \frac {\alpha + 2} {8}[/latex].

Add the diffuse term back, that is:

[latex]L_{o}(\mathbf{v})=(\mathbf{c}_{diff} + \frac {\alpha + 2} {8}(\mathbf{n} \cdot \mathbf{h})^{\alpha} F(\mathbf{c}_{spec}, \mathbf{l_c},\mathbf{h})) \otimes \mathbf{c}_{light} (\mathbf{n} \cdot \mathbf{l_c})[/latex]

This is the final equation, which is physically-based rendering model, derivated by this serial. Compare to the model common used in game, the calculated amount increases little. However, this equation not only ensure the energy-preserving, but also easier for artists to adjust parameters.

The most import equation of this serial is shown. In the next article, which is the last article in this serial, I’ll propose some future works, and will present some rendering results of physically-based model.