<p>I'm trying to understand BRDF importance sampling following the exemples of the lambertian/diffuse model and the reciprocal Phong model.</p>

<p>I would like to be able to extend the principle to other models. If you know good ressources on the subject please feel free to give me references.</p>

<p>1) In the diffuse case, the pdf <span class="math-container">$p_d(\theta,\phi)$</span> of directions is :
<span class="math-container">\begin{equation}
p_d(\theta,\phi)=\frac{f_r\cos{\theta}\sin{\theta}}{\int_0^{2\pi}\int_0^{\frac{\pi}{2}} f_r\cos{\theta}\sin{\theta}\,\mathrm{d}\theta\mathrm{d}\phi}
=\frac{\cos{\theta}\sin{\theta}}{\pi}
\end{equation}</span></p>

<p>In the reciprocal Phong model the pdf <span class="math-container">$p_s(\theta_s,\phi_s)$</span> is :</p>

<p><span class="math-container">\begin{equation}
p_s(\theta_s,\phi_s)=\frac{k_s\cos^n{\theta_s}\sin{\theta_s}}{\int_0^{2\pi}\int_0^{\frac{\pi}{2}}k_s\cos^n{\theta_s}\sin{\theta_s}\,\mathrm{d}\theta_s\mathrm{d}\phi_s}
=\frac{n+1}{2\pi}\cos^n{\theta_s}\sin{\theta_s}
\end{equation}</span></p>

<p>But it seems that people use the densities :
<span class="math-container">\begin{equation}
p_d(\theta,\phi)=\frac{\cos{\theta}}{\pi}
\end{equation}</span>
and
<span class="math-container">\begin{equation}
p_s(\theta_s,\phi_s)=\frac{n+1}{2\pi}\cos^n{\theta_s}
\end{equation}</span></p>

<p>What is the reason ? Could we use both versions ? Are they equivalent ?</p>

<p>2) Furthermore :
<span class="math-container">\begin{equation}
\int_0^{2\pi}\int_0^{\frac{\pi}{2}} \frac{\cos{\theta}}{\pi}\,\mathrm{d}\theta\mathrm{d}\phi=2\pi\neq 1
\end{equation}</span>
and
<span class="math-container">\begin{equation}
\int_0^{2\pi}\int_0^{\frac{\pi}{2}}\frac{n+1}{2\pi}\cos^n{\theta_s}\,\mathrm{d}\theta_s\mathrm{d}\phi_s = \quad?
\end{equation}</span></p>

<p>Shouldn't the pdfs have an integral equal to 1?</p>

<p>3) In another post (<a href="https://computergraphics.stackexchange.com/questions/5968/probability-density-function-while-using-spherical-coordinates">Probability density function while using spherical coordinates</a>), people explains that the sines functions are never taken into account because they are "artefacts" of the coordinate system.</p>

<p>Is that true ? Should we always reject sines functions ? And if so, why do we compute pdf with sines and reject them after ?</p>

<p>EDIT:</p>

<p>Thanks to the comment of @lightxbulb, it seems that the integrals of my second point should be evaluated with respect to solid angles:
<span class="math-container">\begin{equation}
\int_{\Omega} \frac{\cos{\theta}}{\pi}\,\mathrm{d}\omega
=\int_0^{2\pi}\int_0^{\frac{\pi}{2}} \frac{\cos{\theta}\sin{\theta}}{\pi}\,\mathrm{d}\theta\mathrm{d}\phi
=1
\end{equation}</span>
and
<span class="math-container">\begin{equation}
\int_{\Omega}\frac{n+1}{2\pi}\cos^n{\theta_s}\,\mathrm{d}\omega
=\int_0^{2\pi}\int_0^{\frac{\pi}{2}}\frac{n+1}{2\pi}\cos^n{\theta_s}\sin{\theta_s}\,\mathrm{d}\theta_s\mathrm{d}\phi_s
=1
\end{equation}</span></p>

<p>which brings me to another point:</p>

<p>4) Here are different Monte-Carlo estimators for the reflected part of the rendering equation, with respect to different coordinate system:</p>

<p>Solid angles:
<span class="math-container">\begin{equation}
L_r(\vec{x},\vec{\omega}_o)=\frac{1}{N}\sum_{i=1}^N \frac{L_i(\vec{x},\vec{\omega}_i(x,y,z)) f_r(\vec{x},\vec{\omega}_i(x,y,z),\vec{\omega}_o) \cos{\theta}}{p_1(\vec{\omega}_i(x,y,z))}
\end{equation}</span>
Spherical coordinates:
<span class="math-container">\begin{equation}
L_r(\vec{x},\vec{\omega}_o)=\frac{1}{N}\sum_{i=1}^N \frac{L_i(\vec{x},\vec{\omega}_i(\theta,\phi)) f_r(\vec{x},\vec{\omega}_i(\theta,\phi),\vec{\omega}_o) \cos{\theta}\sin{\theta}}{p_2(\vec{\omega}_i(\theta,\phi))}
\end{equation}</span>
Unit square:
<span class="math-container">\begin{equation}
L_r(\vec{x},\vec{\omega}_o)=\frac{\pi}{N}\sum_{i=1}^N \frac{L_i(\vec{x},\vec{\omega}_i(u,v)) f_r(\vec{x},\vec{\omega}_i(u,v),\vec{\omega}_o)}{p_3(\vec{\omega}_i(u,v))}
\end{equation}</span></p>

<p>Sorry for the heavy notations but I would like to fully understand. So:
<span class="math-container">\begin{equation}
p_1(\vec{\omega_i})=\frac{\cos{\theta}}{\pi}\quad ?
\end{equation}</span></p>

<p><span class="math-container">\begin{equation}
p_2(\vec{\omega_i})=\frac{\cos{\theta}\sin{\theta}}{\pi}\quad ?
\end{equation}</span></p>

<p><span class="math-container">\begin{equation}
p_3(\vec{\omega_i})=\quad ?
\end{equation}</span></p>

<p>People seem to use:
<span class="math-container">\begin{equation}
p_3(\vec{\omega_i})=\frac{\cos{\theta}}{\pi}
\end{equation}</span></p>

<p>I'm doing something wrong but I don't know what</p>

<p>EDIT2:</p>

<p>The equation involving (<span class="math-container">$\xi_1,\xi_2$</span>) on page 9 in the reference is not the reflected part of the rendering equation but the integral of the BRDF on the hemisphere. But we don't care here because 1) the luminance <span class="math-container">$L_i$</span> in the reflected part is not known (that's why we use importance sampling only on the BRDF) and 2) a Monte-Carlo estimator is something like:
<span class="math-container">\begin{equation}
\int f(x)\, \mathrm{d}x\approx\frac{1}{N}\sum_{i=1}^N \frac{f(x_i)}{p(x_i)}
\end{equation}</span>
So that's just different integrands but the pdfs should be the same. Correct me if I'm wrong.</p>

<p>Here are the mappings:</p>

<p>From the spherical coordinates to solid angles:
<span class="math-container">\begin{equation}
\begin{cases}
x = \sin{\theta}\cos{\phi} \\
y = \sin{\theta}\sin{\phi} \\
z = \cos{\theta}
\end{cases}
\end{equation}</span></p>

<p>From the unit square to the spherical coordinates:
<span class="math-container">\begin{equation}
\begin{cases}
\theta = \arcsin{\sqrt{u}} \\
\phi = 2\pi v
\end{cases}
\end{equation}</span></p>

<p>I suppose that the expression "cosine weighted mapping" comes from the cosine with the normal (<span class="math-container">$z=\cos{\theta}$</span>) ? If the cosine of the mapping modify the pdf why the sine of the Jacobian doesn't ? And if the mapping modify the pdf why (<span class="math-container">$\theta = \arcsin{\sqrt{u}}$</span>) doesn't too ?</p>

<p>I have an implementation in front of me (ref : Lászlo Szirmay-Kalos, Monte Carlo Methods in Global Illumination, page 104 and 112). I think that what is done is to use the first estimator with the pdf <span class="math-container">$p(\vec{\omega}_i)=\frac{\cos{\theta}}{\pi}$</span>. But the choice of the pdf is not explained and I'm very confused with the different mappings and the influence of each transformation on the mathematical formulation of the problem.</p>

CC BY-SA 4.0
2020-04-14T19:32:42.257Z
1) The versions without the sine are with respect to the solid angle measure, the sine pops out when you go to spherical coordinates from the Jacobian. Either way, the sine gets canceled with the sine from the rendering equation always. 2) You're missing the sine since you plugged in the pdfs with respect to the solid angle measure into an integral over spherical coordinates. 3) The sine comes from the parametrisation. It gets canceled in the estimator by the pdf.
lightxbulb
CC BY-SA 4.0
2020-04-14T20:01:56.793Z
Thanks for your answer @lightxbulb. If I understand correctly : whatever change of variable we do : from directions (solid angle) to spherical coordinates and from the hemisphere (spherical coordinates) to the unit square (to uniformly pick random numbers), because what we do is selecting a new direction (for reflection), the pdf stay in the "directions/solid angle" coordinate system ?
kipgon
CC BY-SA 4.0
2020-04-14T20:18:54.223Z
You always go to spherical coordinates at some point if you use the solid angle formulation. The issue you had comes from the fact that you used a pdf with respect to the solid angle measure as a pdf with respect to spherical coordinates. Note: $d\omega = \sin\theta \,d\theta d\phi$. The sine of the pdf always gets canceled with the sine in the rendering equation in the estimator.
lightxbulb
CC BY-SA 4.0
2020-04-15T18:20:04.037Z
What is this unit square estimator, why is there a $\pi$, and why is $\cos\theta$ missing from the numerator?
lightxbulb
CC BY-SA 4.0
2020-04-15T18:31:22.160Z
$\pi$ appeared and $\cos{\theta}\sin{\theta}$ disappeared because of the Jacobian of the mapping from the square to the spherical coordinates. See Lafortune : Using the Modified Phong Reflectance Model for Physically Based Rendering, page 9).
kipgon
CC BY-SA 4.0
2020-04-15T20:28:05.273Z
I looked at the reference you cited. The integral there is for the hemispherical reflectivity and no estimators are presented. What is shown on page 9 is simply different parametrizations. The one you seem to be confused about $(\xi_1, \xi_2)$ involves a cosine weighted mapping from the unit square coordinates to spherical coordinates (or rather the inverse). Let's ignore for a second that the integral is different. The analogue for the rendering equation estimator would be exactly the spherical one, because you used a cosine weight there.
lightxbulb
<pathtracing><brdf><monte-carlo><importance-sampling>
Understanding BRDF sampling
kipgon
# Understanding BRDF sampling

(Asked by: username_0 on 2020-04-14)

I'm trying to understand BRDF importance sampling following the exemples of the lambertian/diffuse model and the reciprocal Phong model.

I would like to be able to extend the principle to other models. If you know good ressources on the subject please feel free to give me references.

1) In the diffuse case, the pdf $p\_d(\theta,\phi)$ of directions is :
\begin{equation}
p\_d(\theta,\phi)=\frac{f\_r\cos{\theta}\sin{\theta}}{\int\_0^{2\pi}\int\_0^{\frac{\pi}{2}} f\_r\cos{\theta}\sin{\theta}\,\mathrm{d}\theta\mathrm{d}\phi}
=\frac{\cos{\theta}\sin{\theta}}{\pi}
\end{equation}

In the reciprocal Phong model the pdf $p\_s(\theta\_s,\phi\_s)$ is :

\begin{equation}
p\_s(\theta\_s,\phi\_s)=\frac{k\_s\cos^n{\theta\_s}\sin{\theta\_s}}{\int\_0^{2\pi}\int\_0^{\frac{\pi}{2}}k\_s\cos^n{\theta\_s}\sin{\theta\_s}\,\mathrm{d}\theta\_s\mathrm{d}\phi\_s}
=\frac{n+1}{2\pi}\cos^n{\theta\_s}\sin{\theta\_s}
\end{equation}

But it seems that people use the densities :
\begin{equation}
p\_d(\theta,\phi)=\frac{\cos{\theta}}{\pi}
\end{equation}
and
\begin{equation}
p\_s(\theta\_s,\phi\_s)=\frac{n+1}{2\pi}\cos^n{\theta\_s}
\end{equation}

What is the reason ? Could we use both versions ? Are they equivalent ?

2) Furthermore :
\begin{equation}
\int\_0^{2\pi}\int\_0^{\frac{\pi}{2}} \frac{\cos{\theta}}{\pi}\,\mathrm{d}\theta\mathrm{d}\phi=2\pi\neq 1
\end{equation}
and
\begin{equation}
\int\_0^{2\pi}\int\_0^{\frac{\pi}{2}}\frac{n+1}{2\pi}\cos^n{\theta\_s}\,\mathrm{d}\theta\_s\mathrm{d}\phi\_s = \quad?
\end{equation}

Shouldn't the pdfs have an integral equal to 1?

3) In another post ([Probability density function while using spherical coordinates](https://computergraphics.stackexchange.com/questions/5968/probability-density-function-while-using-spherical-coordinates)), people explains that the sines functions are never taken into account because they are "artefacts" of the coordinate system.

Is that true ? Should we always reject sines functions ? And if so, why do we compute pdf with sines and reject them after ?

EDIT:

Thanks to the comment of @username_1, it seems that the integrals of my second point should be evaluated with respect to solid angles:
\begin{equation}
\int\_{\Omega} \frac{\cos{\theta}}{\pi}\,\mathrm{d}\omega
=\int\_0^{2\pi}\int\_0^{\frac{\pi}{2}} \frac{\cos{\theta}\sin{\theta}}{\pi}\,\mathrm{d}\theta\mathrm{d}\phi
=1
\end{equation}
and
\begin{equation}
\int\_{\Omega}\frac{n+1}{2\pi}\cos^n{\theta\_s}\,\mathrm{d}\omega
=\int\_0^{2\pi}\int\_0^{\frac{\pi}{2}}\frac{n+1}{2\pi}\cos^n{\theta\_s}\sin{\theta\_s}\,\mathrm{d}\theta\_s\mathrm{d}\phi\_s
=1
\end{equation}

which brings me to another point:

4) Here are different Monte-Carlo estimators for the reflected part of the rendering equation, with respect to different coordinate system:

Solid angles:
\begin{equation}
L\_r(\vec{x},\vec{\omega}\_o)=\frac{1}{N}\sum\_{i=1}^N \frac{L\_i(\vec{x},\vec{\omega}\_i(x,y,z)) f\_r(\vec{x},\vec{\omega}\_i(x,y,z),\vec{\omega}\_o) \cos{\theta}}{p\_1(\vec{\omega}\_i(x,y,z))}
\end{equation}
Spherical coordinates:
\begin{equation}
L\_r(\vec{x},\vec{\omega}\_o)=\frac{1}{N}\sum\_{i=1}^N \frac{L\_i(\vec{x},\vec{\omega}\_i(\theta,\phi)) f\_r(\vec{x},\vec{\omega}\_i(\theta,\phi),\vec{\omega}\_o) \cos{\theta}\sin{\theta}}{p\_2(\vec{\omega}\_i(\theta,\phi))}
\end{equation}
Unit square:
\begin{equation}
L\_r(\vec{x},\vec{\omega}\_o)=\frac{\pi}{N}\sum\_{i=1}^N \frac{L\_i(\vec{x},\vec{\omega}\_i(u,v)) f\_r(\vec{x},\vec{\omega}\_i(u,v),\vec{\omega}\_o)}{p\_3(\vec{\omega}\_i(u,v))}
\end{equation}

Sorry for the heavy notations but I would like to fully understand. So:
\begin{equation}
p\_1(\vec{\omega\_i})=\frac{\cos{\theta}}{\pi}\quad ?
\end{equation}

\begin{equation}
p\_2(\vec{\omega\_i})=\frac{\cos{\theta}\sin{\theta}}{\pi}\quad ?
\end{equation}

\begin{equation}
p\_3(\vec{\omega\_i})=\quad ?
\end{equation}

People seem to use:
\begin{equation}
p\_3(\vec{\omega\_i})=\frac{\cos{\theta}}{\pi}
\end{equation}

I'm doing something wrong but I don't know what

EDIT2:

The equation involving ($\xi\_1,\xi\_2$) on page 9 in the reference is not the reflected part of the rendering equation but the integral of the BRDF on the hemisphere. But we don't care here because 1) the luminance $L\_i$ in the reflected part is not known (that's why we use importance sampling only on the BRDF) and 2) a Monte-Carlo estimator is something like:
\begin{equation}
\int f(x)\, \mathrm{d}x\approx\frac{1}{N}\sum\_{i=1}^N \frac{f(x\_i)}{p(x\_i)}
\end{equation}
So that's just different integrands but the pdfs should be the same. Correct me if I'm wrong.

Here are the mappings:

From the spherical coordinates to solid angles:
\begin{equation}
\begin{cases}
x = \sin{\theta}\cos{\phi} \\
y = \sin{\theta}\sin{\phi} \\
z = \cos{\theta}
\end{cases}
\end{equation}

From the unit square to the spherical coordinates:
\begin{equation}
\begin{cases}
\theta = \arcsin{\sqrt{u}} \\
\phi = 2\pi v
\end{cases}
\end{equation}

I suppose that the expression "cosine weighted mapping" comes from the cosine with the normal ($z=\cos{\theta}$) ? If the cosine of the mapping modify the pdf why the sine of the Jacobian doesn't ? And if the mapping modify the pdf why ($\theta = \arcsin{\sqrt{u}}$) doesn't too ?

I have an implementation in front of me (ref : Lászlo Szirmay-Kalos, Monte Carlo Methods in Global Illumination, page 104 and 112). I think that what is done is to use the first estimator with the pdf $p(\vec{\omega}\_i)=\frac{\cos{\theta}}{\pi}$. But the choice of the pdf is not explained and I'm very confused with the different mappings and the influence of each transformation on the mathematical formulation of the problem.

**Tags:** pathtracing, brdf, monte-carlo, importance-sampling

> **Comments:**
> **username_1**: 1) The versions without the sine are with respect to the solid angle measure, the sine pops out when you go to spherical coordinates from the Jacobian. Either way, the sine gets canceled with the sine from the rendering equation always. 2) You're missing the sine since you plugged in the pdfs with respect to the solid angle measure into an integral over spherical coordinates. 3) The sine comes from the parametrisation. It gets canceled in the estimator by the pdf.  
> **username_0**: Thanks for your answer @username_1. If I understand correctly : whatever change of variable we do : from directions (solid angle) to spherical coordinates and from the hemisphere (spherical coordinates) to the unit square (to uniformly pick random numbers), because what we do is selecting a new direction (for reflection), the pdf stay in the "directions/solid angle" coordinate system ?  
> **username_1**: You always go to spherical coordinates at some point if you use the solid angle formulation. The issue you had comes from the fact that you used a pdf with respect to the solid angle measure as a pdf with respect to spherical coordinates. Note: $d\omega = \sin\theta \,d\theta d\phi$. The sine of the pdf always gets canceled with the sine in the rendering equation in the estimator.  
> **username_1**: What is this unit square estimator, why is there a $\pi$, and why is $\cos\theta$ missing from the numerator?  
> **username_0**: $\pi$ appeared and $\cos{\theta}\sin{\theta}$ disappeared because of the Jacobian of the mapping from the square to the spherical coordinates. See Lafortune : Using the Modified Phong Reflectance Model for Physically Based Rendering, page 9).  
> **username_1**: I looked at the reference you cited. The integral there is for the hemispherical reflectivity and no estimators are presented. What is shown on page 9 is simply different parametrizations. The one you seem to be confused about $(\xi_1, \xi_2)$ involves a cosine weighted mapping from the unit square coordinates to spherical coordinates (or rather the inverse). Let's ignore for a second that the integral is different. The analogue for the rendering equation estimator would be exactly the spherical one, because you used a cosine weight there.  

---

## 0 answers

