~/imallett (Ian Mallett)   Applying Monte Carlo Integration to Evaluate the Rendering Equation (Implicit Formulation)

Note: you should read the tutorial for the explicit formulation first; this tutorial will skip over some steps that that tutorial covers in detail.

Recall equation $(3)$ from Monte Carlo Integration (renumbered here):$\int_{domain}g(x) d x = E\left[\frac{g(x)}{pdf(x)}\right] ~~~~~~~~~~~~~~~(1)$Next, we need the rendering equation. In this tutorial, the main difference is that we will be using the implicit formulation, which multiplies the outgoing projection term into the integrand's BRDF and the emission term. This has a number of advantages, as discussed in my explanation of the explicit formulation. Again, in my opinion, it is less easy to understand from first principles, so I strongly recommend familiarizing yourself with BRDFs in the explicit formulation first. The implicit formulation of the rendering equation is:$\vec{L}(\vec{x},\vec{\omega}_o) = \left[ \int_{\Omega_{\vec{x},\vec{N}_{\vec{x}}}} \vec{L}(\vec{y}_i,\,-\vec{\omega}_i) \left| \vec{N}_{\vec{x}} \cdot \vec{\omega}_i \right| \vec{f}_r(\vec{x},\vec{\omega}_i,\vec{\omega}_o) \, d\,\vec{\omega}_i \right] + \overrightarrow{Em}(\vec{x},\vec{\omega}_o) ~~~~~~~~~~~~~~~(2)$Again, note that $\vec{f}_r(\cdots)$ and $\overrightarrow{Em}(\cdots)$ have different meanings than they did in the explicit formulation; they contain the projection term multiplied in implicitly. Note that this doesn't necessarily mean that you'll ever see that term when their definitions are written out; most BRDFs are defined in terms of this projected space initially.

BRDF Energy Conservation

As before, energy must be conserved. The energy constraint (corresponding to the explicit formulation's equation $5$) is:$\vec{k} = E\left[ \frac{ \left| \vec{N}_{\vec{x}} \cdot \vec{\omega}_i \right| \vec{f}_r(\vec{x},\vec{\omega}_i,\vec{\omega}_o) } { pdf(\vec{\omega}_i) } \right] ~~~~~~~~~~~~~~~(3)$Recall that $\vec{k}$ is the absorption coefficient, which is (also) "contained" in the BRDF $\vec{f}_r(\cdots)$\).

Deriving Diffuse BRDF (No Importance Sampling)

What's really happening is that light scatters off the surface according to Lambert's Cosine Law, so as you look at increasing angles, less light is scattered. However, at the same time, the surface gets "compressed" in your visual field by the same cosine term.

Think of standing on a very long concrete sidewalk (which is actually a decently diffuse surface) on a sunny day. Concrete sidewalks are divided into equally sized squares to prevent thermal cracking. If you look down, about one square of the sidewalk fills up your entire view. Also, by Lambert's Cosine Law, light is reflecting upward most strongly. Now look off to the horizon. As you look progressively farther away, more and more sidewalk tiles fill your view, each increasingly tilted. Each of these tilted tiles is reflecting less energy your way, but more of them fill the same visual space. It turns out that these effects cancel out exactly, giving the appearance that all the tiles are the same brightness. In the explicit formulation, you saw this in that tutorial's equation $(10)$ when the final projection term canceled with a term in the BRDF.

The BRDF for the implicit case comes from that observation that the apparent brightness of a diffuse surface does not change with the viewing angle. Since the BRDF doesn't change, for the implicit formulation, we simply write a constant:$\vec{f}_r(\vec{x},\vec{\omega}_i,\vec{\omega}_o) = \vec{k}_d \cdot x ~~~~~~~~~~~~~~~(4)$Again, the absorption coefficient $\vec{k}$ for diffuse has been named $\vec{k}_d$ both here and below, and $x$ is a constant normalization factor that will be found later.

The PDF for no importance sampling (i.e. constant probability) is of course a constant:$pdf(\vec{\omega}_i) = \frac{1}{2\pi} ~~~~~~~~~~~~~~~(5)$Again, it's this constant because the integral of a PDF over its domain (here the unit hemisphere) must be $1$).

By substituting the BRDF and the PDF into $(3)$ and simplifying, one obtains $x=1/\pi$ so that:$\vec{f}_r(\vec{x},\vec{\omega}_i,\vec{\omega}_o) = \frac{\vec{k}_d}{\pi} ~~~~~~~~~~~~~~~(6)$

Deriving Diffuse BRDF (With Importance Sampling)

As mentioned in the explicit formulation, the best importance sampling distribution for diffuse is:$pdf(\vec{\omega}_i) = \frac{\left|\vec{N}_{\vec{x}} \cdot \vec{\omega}_i\right|}{\pi} ~~~~~~~~~~~~~~~(7)$If we redo the substitution with this PDF, we get the same $x=1/\pi$ and therefore the same BRDF as for the non-importance-sampled case. If you think about it, this shouldn't be surprising: the PDF in $(1)$ can be any PDF with the same support (domain) as the integral. The numerator can be any function, and is independent of the choice of PDF.

Deriving Phong Specular BRDF (No Importance Sampling)

The BRDF for specular is well known to graphics programmers:$\vec{f}_r(\vec{x},\vec{\omega}_i,\vec{\omega}_o) = \vec{k}_s \cdot \langle\vec{R} \cdot \vec{\omega}_i\rangle^n \cdot x ~~~~~~~~~~~~~~~(8)$The absorption coefficient $\vec{k}$ for specular has been named $\vec{k}_s$ here and below. $\vec{R}$ is the perfect specular direction (calculated by reflecting $\vec{\omega}_o$ over $\vec{N}_{\vec{x}}$) and $n$ is the specular exponent. Here, I have used the $\langle\cdots\rangle$ notation to indicate that the argument is clamped to $0$ (so no negative numbers). Note that this is not the same as $\left|\cdots\right|$. Accounting for this is extremely important to do since $\vec{R} \cdot \vec{\omega}_i$ can indeed easily be negative.

The PDF for no importance sampling remains the same as for diffuse:$pdf(\vec{\omega}_i) = \frac{1}{2\pi} ~~~~~~~~~~~~~~~(5)$

By substitution, we find that:$x = \frac{1}{ 2\pi \cdot E\left[ \left|\vec{N}_{\vec{x}} \cdot \vec{\omega}_i\right| \langle\vec{R} \cdot \vec{\omega}_i\rangle^n \right] } ~~~~~~~~~~~~~~~(9)$The problem is that expected value. However, expected value is really a weighted average, so we can rewrite it as the average value of a function, which is computed as an integral (generalized easily from an interval to a hemisphere):$x = \frac{1}{ 2\pi \cdot \frac{1}{2\pi} \int_{\Omega_{\vec{x},\vec{N}_{\vec{x}}}} \left|\vec{N}_{\vec{x}} \cdot \vec{\omega}_i\right| \langle\vec{R} \cdot \vec{\omega}_i\rangle^n d \vec{\omega}_i } ~~~~~~~~~~~~~~~(10)$Simplifying and substituting back in, we get a BRDF of:$\vec{f}_r(\vec{x},\vec{\omega}_i,\vec{\omega}_o) = \frac{ \vec{k}_s \cdot \langle\vec{R} \cdot \vec{\omega}_i\rangle^n } { \int_{\Omega_{\vec{x},\vec{N}_{\vec{x}}}} \left|\vec{N}_{\vec{x}} \cdot \vec{\omega}_i\right| \langle\vec{R} \cdot \vec{\omega}_i\rangle^n d \vec{\omega}_i } ~~~~~~~~~~~~~~~(11)$The formula for solving that integral is nasty and complex, but it can be done for integer-valued $n$ by using the formula in the Global Illumination Compendium under section 31a. If you think about it, that integral's value only depends on the angle between $\vec{N}_{\vec{x}}$ and $\vec{R}$, so in practice, it can be precomputed in a table for a range of possible angles and then sampled.

Deriving Phong Specular BRDF (With Importance Sampling) (INCOMPLETE!)

It is very difficult to derive a PDF for importance sampled specular—so much so, in fact, that I don't know of one. However, there is an importance-sampled distribution for a $cos^n$ lobe around the normal vector:$pdf(\vec{\omega}_i) = \frac{n+1}{2\pi} \left|\vec{N}_{\vec{x}} \cdot \vec{\omega}_i\right| ~~~~~~~~~~~~~~~(12)$A vector drawn from this distribution can then be rotated using standard linear algebra techniques (e.g., change-of-basis) to fall around $\vec{R}$, giving effectively this PDF:$pdf(\vec{\omega}_i) = \frac{n+1}{2\pi} \left|\vec{R} \cdot \vec{\omega}_i\right| ~~~~~~~~~~~~~~~(13)$We have to be careful. This $\vec{\omega}_i$ no longer comes from the hemisphere $\Omega_{\vec{x},\vec{N}_{\vec{x}}}$ but from the hemisphere $\Omega_{\vec{x},\vec{R}}$. COMMENTS
 Ian Mallett - Contact - Donate - 2021 - 