Log in

No account? Create an account

Some notes on sampling BRDFs - 410

About Some notes on sampling BRDFs

Previous Entry Some notes on sampling BRDFs Apr. 3rd, 2009 @ 04:56 pm Next Entry

These notes are the product of some fiddling earlier today on how to use BRDFs to do stochastic ray-tracing. I’m putting them up here as a Google target because I couldn’t find any similar treatments on the web. I hope they’re useful to someone!

The BRDF is the ratio of reflected radiance to incident irradiance at a particular wavelength. Radiance is a measure of energy (proportional to photon count for a particular wavelength) and irradiance is radiance scaled by projective area.

Letting $L_{i,r}(\theta_{i,r}, \phi_{i,r})$ represent the incident and reflected radiance, then the BRDF is given by:

\begin{displaymath} f(\theta_i, \phi_i, \theta_r, \phi_r) = L_r(\theta_r, \phi_r) / ( L_i(\theta_i, \phi_i) \cos \theta_i ), \end{displaymath}

where the incident irradiance is

\begin{displaymath} E_i(\theta_i, \phi_i) = L_i(\theta_i, \phi_i) \cos \theta_i. \end{displaymath}

From this we can find an estimate for the incident and reflected radiance contribution from a single direction:

\begin{displaymath} L_r(\theta_r, \phi_r; \theta_i, \phi_i) = E_i(\theta_i, \phi_i) f(\theta_i, \phi_i, \theta_r, \phi_r), \end{displaymath}
\begin{displaymath} E_i(\theta_i, \phi_i; \theta_r, \phi_r) = L_r(\theta_r, \phi_r) / f(\theta_i, \phi_i, \theta_r, \phi_r). \end{displaymath}

For the moment, consider two PDFs over the incident and reflected directions:

\begin{displaymath} P_r(\theta_r, \phi_r; \theta_i, \phi_i) = (1/N_r(\theta_i, \phi_i)) f(\theta_i, \phi_i, \theta_r, \phi_r), \end{displaymath}
\begin{displaymath} P_i(\theta_i, \phi_i; \theta_r, \phi_r) = (1/N_i(\theta_r, \phi_r)) f(\theta_i, \phi_i, \theta_r, \phi_r) \cos \theta_i. \end{displaymath}

The normalisation functions, $N_{i,r}(.)$ are:

\begin{displaymath} N_r(\theta_i, \phi_i) = \int_{-\pi}^{+\pi} \int_0^{\pi/2} ... ...phi_i, \theta_r, \phi_r) \sin\theta_r d\theta_r d\phi_r, \end{displaymath}
\begin{displaymath} N_i(\theta_r, \phi_r) = \int_{-\pi}^{+\pi} \int_0^{\pi/2} ... ...r, \phi_r) \cos \theta_i \sin\theta_i d\theta_i d\phi_i. \end{displaymath}

Suppose we wish to model light transport by sampling from $P_i(.)$ or $P_r(.)$. For an eye ray, we with to estimate the total reflected radiance at a point:

\begin{displaymath} R(\theta_r, \phi_r) = \int_{-\pi}^{+\pi} \int_0^{\pi/2} L_... ...phi_r; \theta_i, \phi_i) \sin\theta_i d\theta_i d\phi_i. \end{displaymath}

We can re-express $R(.)$ via $L_i(.)$ and $P_i(.)$:

\begin{displaymath} R(\theta_r, \phi_r) = \int_{-\pi}^{+\pi} \int_0^{\pi/2} L_... ...phi_i; \theta_r, \phi_r) \sin\theta_i d\theta_i d\phi_i. \end{displaymath}

We can estimate this integral via importance sampling. That is to say if we draw $(\theta_i, \phi_i)$ from $P_i(.)$,

\begin{displaymath} R(\theta_r, \phi_r) \approx \left< L_i(\theta_r, \phi_r; \theta_i, \phi_i) N_i(\theta_r, \phi_r) \right> \end{displaymath}

where $\left< . \right>$ denotes the sample mean.

Now consider tracing a light ray. We interpret the ratio

\begin{displaymath} L_r(.) / L_i(.) = \cos \theta_i f(\theta_i, \phi_i, \theta_r, \phi_r) \end{displaymath}

as a relative likelihood of a ray incident at $(\theta_i, \phi_i)$ being reflected at $(\theta_r, \phi_r)$. For a given incidence angle, $\cos \theta_i$ is constant and we can therefore interpret $P_r(.)$ as a PDF governing the ray transport.

Given an incident ray we sample an outgoing direction from $P_r(.)$ and propagate the ray along it. We must however normalise the reflected radiance by the probability of having sampled that reflection direction. Specifically we multiply the incident luminance by the sample weight $A(.) = L_r(.) / (L_i(.) P_r(.))$ or

\begin{displaymath} A(\theta_i, \phi_i, \theta_r, \phi_r) = \cos \theta_i f(\the... ...i, \theta_r, \phi_r) / P_r(\theta_r, \phi_r; \theta_i, \phi_i) \end{displaymath}

which, by definition, can be simplified to

\begin{displaymath} A(\theta_i, \phi_i) = N_r(\theta_i, \phi_i) \cos \theta_i. \end{displaymath}

We call this multiplicative factor the attenuation.

For a Lambertian diffuse BRDF, $f(.) = k$ is constant and so $N_i(.) = \pi k$. Thus, if we draw $(\theta_i, \phi_i)$ from $P_i(.) \propto \cos \theta_i$, we have

\begin{displaymath} R(\theta_r, \phi_r) \approx \pi k \left< L_i(\theta_r, \phi_r; \theta_i, \phi_i) \right>. \end{displaymath}

Similarly, $N_r(.) = 2\pi k$, therefore $A(.) = 2 \pi k \cos \theta_i$ with uniform $P_r(.) = 1/(2\pi)$.

For a physically based BRDF, it must satisfy two conditions. Firstly it mus satisfy Helmholtz reciprocity:

\begin{displaymath} f(\theta_i, \phi_i, \theta_r, \phi_r) = f(\theta_r, \phi_r, \theta_i, \phi_i). \end{displaymath}

Secondly, it must conserve energy:

\begin{displaymath} \forall\, (\theta_i, \phi_i), \quad \int_{-\pi}^{+\pi} \int_... ...i_r) \cos \theta_r \, \sin\theta_r \, d\theta_r d\phi_r \le 1. \end{displaymath}

For a Lambertian BRDF, this implies that $k \le 1/\pi$.

Leave a comment
Date:April 4th, 2009 01:51 pm (UTC)
Excuse my ignorance, but what's the computationally hhard bit in this process?

It looks as though some serious mileage could be made by spherical harmonic expansion of almost everything in sight, at which points the integrals reduce to sums, and keeping only a few spherical harmonics would keep isotropic reflectivity/absorbtion plus a few anisotropic effects.

that may be an obviously right (and known for 400 years) or obviously wrong statement :). I'm still trying to figure out what your objective is here.
[User Picture Icon]
Date:April 4th, 2009 02:14 pm (UTC)
Nothing particularly hard but real BRDFs may not be particularly nicely expressable in spherical harmonics[1]. Also the sampling approach converges to the correct answer whereas a SH based approach will always be approximate. Finally the sample variance is bounded with importance sampling meaning that noise characteristics are well understood meaning that subsequent denoising steps can make use of knowledge of the noise statistics.

The simplicity of individual steps also slightly lends itself to off-CPU evaluation e.g. on compute cards/parallel processing nodes.

But ultimately, the real reason is personal interest in learning more about sampling arguments.

[1] The logical extension being e.g a) purely specular reflective surface which is a delta function, not particularly firendly to SH or b) a hard edged illumination source which would require an infinite series of SH components to represent fully.
[User Picture Icon]
Date:April 4th, 2009 02:15 pm (UTC)
[User Picture Icon]
Date:April 4th, 2009 07:01 pm (UTC)
I am seriously impressed with this post. Not the content per se, but the presentation and the amount of work that would appear to have gone into producing it. The text in the math PNGs lines up perfectly with the regular text. And the image alt tags, FTW. Google fodder indeed. Bravo.
[User Picture Icon]
Date:April 4th, 2009 07:16 pm (UTC)
Yes, I was thinking that. What tool did you use (assuming you didn't do it all laboriously by hand!) to generate the HTML+PNGs, and from what sort of source? I'm on the lookout for anything that will do this job better than what I currently use.
[User Picture Icon]
Date:April 4th, 2009 07:33 pm (UTC)
LaTeX2HTML[1], it is actually lifted from a tex file in the 'notes' folder of the source tar ball.

[1] http://www.latex2html.org/
(Leave a comment)
Top of Page Powered by LiveJournal.com