<p>If your map <span class="math-container">$\omega:[0,2\pi) \times [0,\pi] \to \mathbb{S}^2\subset \mathbb{R}^3$</span> is the standard spherical coordinates map:</p>
<p><span class="math-container">$$\omega = (\cos\phi \sin\theta, \sin\phi \sin\theta, \cos\theta),$$</span></p>
<p>then the Jacobian is:</p>
<p><span class="math-container">$$J = \frac{\partial \omega}{\partial (\phi, \theta)} = \begin{bmatrix} \uparrow &amp; \uparrow \\\frac{\partial\omega}{\partial \phi} &amp; \frac{\partial\omega} {\partial\theta} \\ \downarrow &amp; \downarrow \end{bmatrix} = \begin{bmatrix} -\sin\phi \sin\theta &amp; \cos\phi\cos\theta \\ \cos\phi\sin\theta &amp; \sin\phi \cos\theta \\ 0 &amp; \sin\theta\end{bmatrix}.$$</span></p>
<p>The area measure on the sphere is <span class="math-container">$d\sigma(\omega) = \sqrt{\det J^T J} \,d\lambda(\phi)d\lambda(\theta) = |\sin\theta|\,d\lambda(\phi)d\lambda(\theta)$</span>. Here <span class="math-container">$\lambda$</span> is just the Lebesgue measure and it is often omitted. Now assume the probability density function for picking <span class="math-container">$(\phi,\theta)$</span> is <span class="math-container">$p_{\phi,\theta}$</span>. Taking into account <span class="math-container">$d\sigma(\omega) = |\sin\theta|\,d\lambda(\phi)d\lambda(\theta)$</span> we have:
<span class="math-container">$$p_{\phi,\theta}(\phi,\theta) \,d\lambda(\phi) d\lambda(\theta) = p_{\sigma}(\omega)\,d\sigma(\omega) \implies p_{\sigma}(\omega) = \frac{p_{\phi,\theta}(\phi,\theta)}{|\sin\theta|}.$$</span></p>
<p>Note that translations and rotations do not change the term <span class="math-container">$\sqrt{J^T J}$</span> since the derivative of a translation is zero, and a rotation is orthogonal <span class="math-container">$R^TR=I$</span> and thus <span class="math-container">$\sqrt{J^TR^TRJ} = \sqrt{J^TJ} = |\sin\theta|$</span>. I am mentioning this since typically you integrate over the sphere not w.r.t. the standard coordinate axes, but some frame oriented around the normal, which can be implemented as <span class="math-container">$\omega' = R\omega$</span>.</p>
<p>If <span class="math-container">$p_{\phi,\theta}$</span> is separable you can write it as <span class="math-container">$p_{\phi,\theta}(\phi,\theta) = p_{\phi}(\phi)p_{\theta}(\theta)$</span>.</p>
<p>The change of variables in an integral over the unit sphere happens as follows:</p>
<p><span class="math-container">\begin{align}
I
&amp;=\int_{\mathbb{S}^2} L_i(x, \omega_i) f(\omega_o, x, \omega_i) (\omega_i \cdot n)\,d\sigma(\omega_i) \\
&amp;= \int_{0}^{2\pi}\int_0^{\pi} L_i(x,\omega_i(\phi,\theta))f(\omega_o,x, \omega_i(\phi,\theta)) (\omega_i(\phi,\theta) \cdot n)|\sin\theta|\,d\lambda(\theta) d\lambda(\phi) \\
&amp;= \int_0^1\int_0^1  L_i(x,\omega_i(u,v))f(\omega_o,x, \omega_i(u,v)) (\omega_i(u,v) \cdot n)\underbrace{|\sin\theta|\left|\det \frac{\partial(\phi,\theta)}{\partial (u,v)}\right|}_{1/p_{\sigma}(\omega_i)}\,d\lambda(u) d\lambda(v) \\
&amp;= \int_0^1\int_0^1 \frac{L_i(x,\omega_i(u_j,v_j))f(\omega_o,x, \omega_i(u,v)) (\omega_i(u,v) \cdot n)}{p_{\sigma}(\omega_i(u,v))}\,d\lambda(u) d\lambda(v) \\
&amp;\approx \frac{1}{N} \sum_{j=1}^N\frac{L_i(x,\omega_i(u_j,v_j))f(\omega_o,x, \omega_i(u_j,v_j)) (\omega_i(u_j,v_j) \cdot n)}{p_{\sigma}(\omega_i(u_j,v_j))}, \quad (u_j,v_j) \sim U[0,1]^2.
\end{align}</span></p>

CC BY-SA 4.0
2024-03-16T02:13:49.787Z
Thank you for your comprehensive answer!
Enigmatisms
CC BY-SA 4.0
2024-03-16T10:35:08.503Z
@Enigmatisms I added in that translations and rotations would not change this, this means you can for example choose $\theta$ to be the angle to the normal.
lightxbulb
CC BY-SA 4.0
2024-03-17T06:36:49.903Z
Thanks for the tip
Enigmatisms
CC BY-SA 4.0
2024-03-14T12:56:23.040Z
2024-03-19T14:50:13.317Z
2024-03-19T14:50:13.317Z
lightxbulb
<p>If in the path tracing use case, I have some sampling strategies to sample a scattering direction in a 2D space (<span class="math-container">$\theta, \phi$</span>). Of course, I need to convert it to a 3D direction vector (with length being 1). My question is, is the PDF of this 3D direction vector the same as that of <span class="math-container">$(\theta, \phi)$</span>? If I recall correctly, there should be a Jacobian term for the conversion from spherical coords to 3D Cartesian space, so the PDF is probably different?</p>
<p>If the sampling PDF for <span class="math-container">$\theta$</span> is <span class="math-container">$p_1(\theta), \theta \in [0, \pi)$</span> (volumetric scattering requires sampling on the entire sphere), and PDF for sampling <span class="math-container">$\phi$</span> is <span class="math-container">$p_2(\phi), \phi \in [0, 2\pi)$</span>.</p>
<ul>
<li>What will be the PDF of the 3D direction vector <span class="math-container">$p_d(\omega)$</span>?</li>
<li>What about the case that <span class="math-container">$\theta, \phi$</span> is sampled from a 2D joint distribution <span class="math-container">$p(\theta, \phi)$</span> (like, sampling from precomputed tabulations), is there any difference from the first case?</li>
<li>And if I am gonna evaluate the MC integral here, is the following correct?
<span class="math-container">$$
\text{scattering throughput}=f(\omega, \omega') \times C / p_d(\omega), C=\begin{cases}
\sigma_s, \text{volumetric}\\
\omega^T \omega',\text{surface}
\end{cases}
$$</span></li>
</ul>

<pathtracing><mathematics><sampling>
Measure (or Jacobian) conversion for direction sampling
Enigmatisms
# Measure (or Jacobian) conversion for direction sampling

(Asked by: username_0 on 2024-03-14)

If in the path tracing use case, I have some sampling strategies to sample a scattering direction in a 2D space ($\theta, \phi$). Of course, I need to convert it to a 3D direction vector (with length being 1). My question is, is the PDF of this 3D direction vector the same as that of $(\theta, \phi)$? If I recall correctly, there should be a Jacobian term for the conversion from spherical coords to 3D Cartesian space, so the PDF is probably different?

If the sampling PDF for $\theta$ is $p\_1(\theta), \theta \in [0, \pi)$ (volumetric scattering requires sampling on the entire sphere), and PDF for sampling $\phi$ is $p\_2(\phi), \phi \in [0, 2\pi)$.

* What will be the PDF of the 3D direction vector $p\_d(\omega)$?
* What about the case that $\theta, \phi$ is sampled from a 2D joint distribution $p(\theta, \phi)$ (like, sampling from precomputed tabulations), is there any difference from the first case?
* And if I am gonna evaluate the MC integral here, is the following correct?
  $$
  \text{scattering throughput}=f(\omega, \omega') \times C / p\_d(\omega), C=\begin{cases}
  \sigma\_s, \text{volumetric}\\
  \omega^T \omega',\text{surface}
  \end{cases}
  $$

**Tags:** pathtracing, mathematics, sampling


---

## 1 answers

### Answer by username_1 on 2024-03-14. Score: 3 | Accepted answer

If your map $\omega:[0,2\pi) \times [0,\pi] \to \mathbb{S}^2\subset \mathbb{R}^3$ is the standard spherical coordinates map:

$$\omega = (\cos\phi \sin\theta, \sin\phi \sin\theta, \cos\theta),$$

then the Jacobian is:

$$J = \frac{\partial \omega}{\partial (\phi, \theta)} = \begin{bmatrix} \uparrow & \uparrow \\\frac{\partial\omega}{\partial \phi} & \frac{\partial\omega} {\partial\theta} \\ \downarrow & \downarrow \end{bmatrix} = \begin{bmatrix} -\sin\phi \sin\theta & \cos\phi\cos\theta \\ \cos\phi\sin\theta & \sin\phi \cos\theta \\ 0 & \sin\theta\end{bmatrix}.$$

The area measure on the sphere is $d\sigma(\omega) = \sqrt{\det J^T J} \,d\lambda(\phi)d\lambda(\theta) = |\sin\theta|\,d\lambda(\phi)d\lambda(\theta)$. Here $\lambda$ is just the Lebesgue measure and it is often omitted. Now assume the probability density function for picking $(\phi,\theta)$ is $p\_{\phi,\theta}$. Taking into account $d\sigma(\omega) = |\sin\theta|\,d\lambda(\phi)d\lambda(\theta)$ we have:
$$p\_{\phi,\theta}(\phi,\theta) \,d\lambda(\phi) d\lambda(\theta) = p\_{\sigma}(\omega)\,d\sigma(\omega) \implies p\_{\sigma}(\omega) = \frac{p\_{\phi,\theta}(\phi,\theta)}{|\sin\theta|}.$$

Note that translations and rotations do not change the term $\sqrt{J^T J}$ since the derivative of a translation is zero, and a rotation is orthogonal $R^TR=I$ and thus $\sqrt{J^TR^TRJ} = \sqrt{J^TJ} = |\sin\theta|$. I am mentioning this since typically you integrate over the sphere not w.r.t. the standard coordinate axes, but some frame oriented around the normal, which can be implemented as $\omega' = R\omega$.

If $p\_{\phi,\theta}$ is separable you can write it as $p\_{\phi,\theta}(\phi,\theta) = p\_{\phi}(\phi)p\_{\theta}(\theta)$.

The change of variables in an integral over the unit sphere happens as follows:

\begin{align}
I
&=\int\_{\mathbb{S}^2} L\_i(x, \omega\_i) f(\omega\_o, x, \omega\_i) (\omega\_i \cdot n)\,d\sigma(\omega\_i) \\
&= \int\_{0}^{2\pi}\int\_0^{\pi} L\_i(x,\omega\_i(\phi,\theta))f(\omega\_o,x, \omega\_i(\phi,\theta)) (\omega\_i(\phi,\theta) \cdot n)|\sin\theta|\,d\lambda(\theta) d\lambda(\phi) \\
&= \int\_0^1\int\_0^1 L\_i(x,\omega\_i(u,v))f(\omega\_o,x, \omega\_i(u,v)) (\omega\_i(u,v) \cdot n)\underbrace{|\sin\theta|\left|\det \frac{\partial(\phi,\theta)}{\partial (u,v)}\right|}\_{1/p\_{\sigma}(\omega\_i)}\,d\lambda(u) d\lambda(v) \\
&= \int\_0^1\int\_0^1 \frac{L\_i(x,\omega\_i(u\_j,v\_j))f(\omega\_o,x, \omega\_i(u,v)) (\omega\_i(u,v) \cdot n)}{p\_{\sigma}(\omega\_i(u,v))}\,d\lambda(u) d\lambda(v) \\
&\approx \frac{1}{N} \sum\_{j=1}^N\frac{L\_i(x,\omega\_i(u\_j,v\_j))f(\omega\_o,x, \omega\_i(u\_j,v\_j)) (\omega\_i(u\_j,v\_j) \cdot n)}{p\_{\sigma}(\omega\_i(u\_j,v\_j))}, \quad (u\_j,v\_j) \sim U[0,1]^2.
\end{align}

> **Comments:**
> **username_0**: Thank you for your comprehensive answer!  
> **username_1**: @username_0 I added in that translations and rotations would not change this, this means you can for example choose $\theta$ to be the angle to the normal.  
> **username_0**: Thanks for the tip  

---

