🎯 Sampling the hemisphere

16-minute read

Introduction

Generating samples within a hemisphere around a point is needed when doing Monte-Carlo path tracing. These samples can be chosen in a smart way, to be proportional to the BRDF. The following sections explain how to generate these samples, and how to properly weight them using the pdf, for several BRDF models.

The result of importance sampling can be a significant reduction in noise. In the following image, the sphere on the left uses cosine-weighted sampling while the sphere on the right uses BRDF importance-sampling.

Sable.
Cosine-weighted sampling.
The Last of Us.
BRDF importance-sampling

Spherical and cartesian coordinates

When generating samples in the hemisphere, this is usually done using spherical coordinates by calculating a ΞΈ\theta and Ο•\phi angle. These can then be converted to cartesian coordinates using the following formula.

{x=cos(Ο•)β‹…sin(ΞΈ)y=sin(Ο•)β‹…sin(ΞΈ)z=cos(ΞΈ)\left\{\begin{matrix} \begin{aligned} x&=\cos(\phi) \cdot \sin(\theta)\\ y&=\sin(\phi) \cdot \sin(\theta)\\ z&=\cos(\theta) \end{aligned} \end{matrix}\right.

In these snippets you'll see that the sine/cosine is often calculated directly instead of calculating the angle ΞΈ\theta and then taking the sine/cosine.

Technique

The following steps are performed.

  1. Calculate the normalized PDF
  2. Split up the PDF (one for ΞΈ\theta, one for Ο•\phi)
  3. Calculate the CDF by integrating the PDF
  4. Set the CDF equal to some random number between 0 and 1 to obtain a ΞΈ\theta and Ο•\phi angle which define the sample

A common action that is performed throughout the following equations is going from an integral over the hemisphere using solid angles, to an integral over the hemisphere using spherical coordinates. This transformation is done as follows.

∫Ωf(ΞΈ)dw=∫02Ο€βˆ«0Ο€2f(ΞΈ,Ο•)sinΞΈdΞΈdΟ•\int _{\Omega }f(\theta)dw = \int_{0}^{2\pi }\int_{0}^{\frac{\pi}{2}}f(\theta, \phi) \sin\theta d \theta d \phi

Uniform hemisphere

{ΞΈ=cosβˆ’1(Ξ΅0)Ο•=2πΡ1\left\{\begin{matrix} \begin{aligned} \theta &= \cos^{-1}(\varepsilon_{0}) \\ \phi &= 2\pi \varepsilon_{1} \end{aligned}\end{matrix}\right.

pdf(wi)=12Ο€pdf(w_{i}) = \frac{1}{2\pi}

Derivation

For uniform sampling, the PDF should be proportional to 1. We PDF is normalized by dividing by the PDF, integrated over the whole hemisphere.

pdf(Ο‰)=1∫Ω1dΟ‰=1∫02Ο€βˆ«0Ο€21sinΞΈdΞΈdΟ•=12Ο€pdf(ΞΈ,Ο•)=pdf(Ο‰)sinΞΈ=sinΞΈ2Ο€\begin{aligned} pdf(\omega) &= \frac{1}{\int _{\Omega }1d\omega} = \frac{1}{\int_{0}^{2\pi }\int_{0}^{\frac{\pi}{2}}1\sin\theta d \theta d \phi} = \frac{1}{2\pi} \\ pdf(\theta,\phi) &= pdf(\omega ) \sin\theta = \frac{\sin\theta}{2\pi} \end{aligned}

Next, the PDF is split up. We obtain the pdf for ΞΈ\theta by integrating over the whole domain of the Ο•\phi angle which is the same as multiplying by 2Ο€2\pi since the pdf is isotropic. The pdf for Ο•\phi may be obtained by using conditional probabilities and the rule of Bayes.

pdf(ΞΈ)=∫02Ο€pdf(ΞΈ,Ο•)dΟ•=sinΞΈpdf(Ο•βˆ£ΞΈ)=pdf(ΞΈ,Ο•)pdf(ΞΈ)=sinΞΈ2Ο€sinΞΈ=12Ο€\begin{aligned} pdf(\theta) &= \int_{0}^{2\pi}pdf(\theta, \phi) d\phi = \sin\theta \\ pdf(\phi|\theta) &= \frac{pdf(\theta, \phi)}{pdf(\theta)} = \frac{\frac{\sin\theta}{2\pi}}{\sin\theta} = \frac{1}{2\pi} \end{aligned}

We can then integrate the PDF to get the CDF.

cdf(ΞΈ)=∫0ΞΈpdf(ΞΈ)dΞΈ=∫0ΞΈsinΞΈdΞΈ=1βˆ’cosΞΈcdf(Ο•βˆ£ΞΈ)=∫0Ο•pdf(Ο•βˆ£ΞΈ)dΞΈ=∫0Ο•12Ο€dΟ•=1Ο•2Ο€\begin{aligned} cdf(\theta) &= \int_{0}^{\theta}pdf(\theta)d\theta = \int_{0}^{\theta}\sin\theta d\theta = 1-\cos\theta \\ cdf(\phi|\theta) &= \int_{0}^{\phi}pdf(\phi|\theta) d\theta = \int_{0}^{\phi}\frac{1}{2\pi} d\phi = \frac{1\phi}{2\pi} \end{aligned}

By setting these CDFs equal to a random number Ξ΅,Ο΅[0,1]\varepsilon, \epsilon \left [ 0, 1 \right ], we can find an equation for the angle ΞΈ\theta and Ο•\phi that we can use for our sample.

\begin{alignat*}{2} cdf(\theta) &= 1-\cos\theta {}& =\varepsilon_{0} \rightarrow \theta &= \cos^{-1}(1-\varepsilon_{0}) \\ cdf(\phi|\theta) &= \frac{1\phi}{2\pi} {}& =\varepsilon_{1} \rightarrow \phi &= 2\pi \varepsilon_{1} \end{alignat*}

Since Ξ΅\varepsilon is a number between 0 and 1, these equations can be written a bit cleaner as follows.

{ΞΈ=cosβˆ’1(Ξ΅0)Ο•=2πΡ1\left\{\begin{matrix} \begin{aligned} \theta &= \cos^{-1}(\varepsilon_{0}) \\ \phi &= 2\pi \varepsilon_{1} \end{aligned} \end{matrix}\right.

Cosine-weighted hemisphere

{ΞΈ=cosβˆ’1(Ξ΅0)Ο•=2πΡ1\left\{\begin{matrix} \begin{aligned} \theta &= \cos^{-1}(\sqrt{\varepsilon_{0}}) \\ \phi &= 2\pi \varepsilon_{1} \end{aligned} \end{matrix}\right.

pdf(wi)=cosΞΈΟ€pdf(w_{i}) = \frac{\cos\theta}{\pi}

Derivation

For cosine-weighted sampling, the PDF should be proportional to a cosine. The PDF is normalized by dividing by the result of integrating the PDF over the whole hemisphere.

pdf(Ο‰)=cosθ∫ΩcosΞΈdΟ‰=cosθ∫02Ο€βˆ«0Ο€2sinΞΈcosΞΈdΞΈdΟ•=cosΞΈΟ€pdf(ΞΈ,Ο•)=pdf(Ο‰)sinΞΈ=sinΞΈcosΞΈΟ€\begin{aligned} pdf(\omega) &= \frac{\cos\theta}{\int _{\Omega }\cos\theta d\omega} = \frac{\cos\theta}{\int_{0}^{2\pi }\int_{0}^{\frac{\pi}{2}}\sin\theta\cos\theta d \theta d \phi} = \frac{\cos\theta}{\pi} \\ pdf(\theta,\phi) &= pdf(\omega ) \sin\theta = \frac{\sin\theta\cos\theta}{\pi} \end{aligned}

Next, the PDF is split up. We obtain the pdf for ΞΈ\theta by integrating over the whole domain of the Ο•\phi angle which is the same as multiplying by 2Ο€2\pi since the pdf is isotropic. The pdf for Ο•\phi may be obtained by using conditional probabilities and the rule of Bayes.

pdf(ΞΈ)=∫02Ο€pdf(ΞΈ,Ο•)dΟ•=2sinΞΈcosΞΈpdf(Ο•βˆ£ΞΈ)=pdf(ΞΈ,Ο•)pdf(ΞΈ)=sinΞΈcosΞΈΟ€2sinΞΈcosΞΈ=12Ο€\begin{aligned} pdf(\theta) &= \int_{0}^{2\pi}pdf(\theta, \phi) d\phi = 2\sin\theta\cos\theta \\ pdf(\phi|\theta) &= \frac{pdf(\theta, \phi)}{pdf(\theta)} = \frac{\frac{\sin\theta\cos\theta}{\pi}}{2\sin\theta\cos\theta} = \frac{1}{2\pi} \end{aligned}

We can then integrate the PDF to get the CDF.

cdf(ΞΈ)=∫0ΞΈpdf(ΞΈ)dΞΈ=∫0ΞΈ2sinΞΈcosΞΈdΞΈ=sin2ΞΈcdf(Ο•βˆ£ΞΈ)=∫0Ο•pdf(Ο•βˆ£ΞΈ)dΞΈ=∫0Ο•12Ο€dΟ•=1Ο•2Ο€\begin{aligned} cdf(\theta) &= \int_{0}^{\theta}pdf(\theta)d\theta = \int_{0}^{\theta}2\sin\theta\cos\theta d\theta = \sin^2\theta \\ cdf(\phi|\theta) &= \int_{0}^{\phi}pdf(\phi|\theta) d\theta = \int_{0}^{\phi}\frac{1}{2\pi} d\phi = \frac{1\phi}{2\pi} \end{aligned}

By setting these CDFs equal to a random number Ξ΅,Ο΅[0,1]\varepsilon, \epsilon \left [ 0, 1 \right ], we can find an equation for the angle ΞΈ\theta and Ο•\phi that we can use for our sample.

\begin{alignat*}{2} cdf(\theta) &= \sin^2\theta {}& =\varepsilon_{0} \rightarrow \theta &= \sin^{-1}(\sqrt{\varepsilon_{0}}) = \cos^{-1}(\sqrt{1-\varepsilon_{0}}) \\ cdf(\phi|\theta) &= \frac{1\phi}{2\pi} {}& =\varepsilon_{1} \rightarrow \phi &= 2\pi \varepsilon_{1} \end{alignat*}

Since Ξ΅\varepsilon is a number between 0 and 1, these equations can be written a bit cleaner as follows.

{ΞΈ=cosβˆ’1(Ξ΅0)Ο•=2πΡ1\left\{\begin{matrix} \begin{aligned} \theta &= \cos^{-1}(\sqrt{\varepsilon_{0}}) \\ \phi &= 2\pi \varepsilon_{1} \end{aligned} \end{matrix}\right.

Power cosine-weighted hemisphere

This is a generalization of the cosine-weighted sampling scheme in the previous section. Instead of sampling proportional to cosΞΈ\cos\theta, here we sample proportional to cosΞ±ΞΈ\cos^{\alpha}\theta.

{ΞΈ=cosβˆ’1(Ξ΅01Ξ±+1)Ο•=2πΡ1\left\{\begin{matrix} \begin{aligned} \theta &= \cos^{-1}(\varepsilon_{0}^{\frac{1}{\alpha+1}}) \\ \phi &= 2\pi \varepsilon_{1} \end{aligned} \end{matrix}\right.

pdf(wi)=(Ξ±+1)cosΞ±ΞΈ2Ο€pdf(w_{i}) = \frac{(\alpha+1)\cos^{\alpha}\theta}{2\pi}

Derivation

For power cosine-weighted sampling, the PDF should be proportional to a cosine with a power exponent. The PDF is normalized by dividing by the result of integrating the PDF over the whole hemisphere

pdf(Ο‰)=cosαθ∫ΩcosΞ±ΞΈdΟ‰=cosαθ∫02Ο€βˆ«0Ο€2sinΞΈcosΞ±ΞΈdΞΈdΟ•=(Ξ±+1)cosΞ±ΞΈ2Ο€pdf(ΞΈ,Ο•)=pdf(Ο‰)sinΞΈ=(Ξ±+1)cosΞ±ΞΈsinΞΈ2Ο€\begin{aligned} pdf(\omega) &= \frac{\cos^{\alpha}\theta}{\int _{\Omega }\cos^{\alpha}\theta d\omega} = \frac{\cos^{\alpha}\theta}{\int_{0}^{2\pi }\int_{0}^{\frac{\pi}{2}}\sin\theta\cos^{\alpha}\theta d \theta d \phi} = \frac{(\alpha+1)\cos^{\alpha}\theta}{2\pi} \\ pdf(\theta,\phi) &= pdf(\omega ) \sin\theta = \frac{(\alpha+1)\cos^{\alpha}\theta\sin\theta}{2\pi} \end{aligned}

Next, the PDF is split up. We obtain the pdf for ΞΈ\theta by integrating over the whole domain of the Ο•\phi angle which is the same as multiplying by 2Ο€2\pi since the pdf is isotropic. The pdf for Ο•\phi may be obtained by using conditional probabilities and the rule of Bayes.

pdf(ΞΈ)=∫02Ο€pdf(ΞΈ,Ο•)dΟ•=(Ξ±+1)cosΞ±ΞΈsinΞΈpdf(Ο•βˆ£ΞΈ)=pdf(ΞΈ,Ο•)pdf(ΞΈ)=(Ξ±+1)cosΞ±ΞΈsinΞΈ2Ο€(Ξ±+1)cosΞ±ΞΈsinΞΈ=12Ο€\begin{aligned} pdf(\theta) &= \int_{0}^{2\pi}pdf(\theta, \phi) d\phi = (\alpha+1)\cos^{\alpha}\theta\sin\theta \\ pdf(\phi|\theta) &= \frac{pdf(\theta, \phi)}{pdf(\theta)} = \frac{\frac{(\alpha+1)\cos^{\alpha}\theta\sin\theta}{2\pi}}{(\alpha+1)\cos^{\alpha}\theta\sin\theta} = \frac{1}{2\pi} \end{aligned}

We can then integrate the PDF to get the CDF.

cdf(ΞΈ)=∫0ΞΈpdf(ΞΈ)dΞΈ=∫0ΞΈ(Ξ±+1)cosΞ±ΞΈsinΞΈdΞΈ=1βˆ’cos(Ξ±+1)ΞΈcdf(Ο•βˆ£ΞΈ)=∫0Ο•pdf(Ο•βˆ£ΞΈ)dΞΈ=∫0Ο•12Ο€dΟ•=1Ο•2Ο€\begin{aligned} cdf(\theta) &= \int_{0}^{\theta}pdf(\theta)d\theta = \int_{0}^{\theta}(\alpha+1)\cos^{\alpha}\theta\sin\theta d\theta = 1-\cos^{(\alpha+1)}\theta \\ cdf(\phi|\theta) &= \int_{0}^{\phi}pdf(\phi|\theta) d\theta = \int_{0}^{\phi}\frac{1}{2\pi} d\phi = \frac{1\phi}{2\pi} \end{aligned}

By setting these CDFs equal to a random number Ξ΅,Ο΅[0,1]\varepsilon, \epsilon \left [ 0, 1 \right ], we can find an equation for the angle ΞΈ\theta and Ο•\phi that we can use for our sample.

\begin{alignat*}{2} cdf(\theta) &= 1-\cos^{(\alpha+1)}\theta {}& =\varepsilon_{0} \rightarrow \theta &= \cos^{-1}((1-\varepsilon_{0})^{\frac{1}{\alpha+1}}) \\ cdf(\phi|\theta) &= \frac{1\phi}{2\pi} {}& =\varepsilon_{1} \rightarrow \phi &= 2\pi \varepsilon_{1} \end{alignat*}

Since Ξ΅\varepsilon is a number between 0 and 1, these equations can be written a bit cleaner as follows.

{ΞΈ=cosβˆ’1(Ξ΅01Ξ±+1)Ο•=2πΡ1\left\{\begin{matrix} \begin{aligned} \theta &= \cos^{-1}(\varepsilon_{0}^{\frac{1}{\alpha+1}}) \\ \phi &= 2\pi \varepsilon_{1} \end{aligned} \end{matrix}\right.

Microfacet-BRDF hemisphere

For microfacet BRDFs, the sampling can be made proportional to the used normal distribution function D(h)D(h). The steps are similar for each normal distribution function. The PDFs may be calculated by noting that NDFs need to satisfy the following equation where ΞΈ\theta is the angle between the normal vector NN and the halfway vector HH.

∫ΩD(h)cosθdh=1\int _{\Omega }D(h)\cos\theta dh = 1

Blinn-Phong

D(h)=(Ξ±+2)cosΞΈΞ±2Ο€D(h) = \frac{(\alpha+2)\cos\theta^{\alpha}}{2\pi}

{ΞΈ=cosβˆ’1(Ξ΅01Ξ±+2)Ο•=2πΡ1\left\{\begin{matrix} \begin{aligned} \theta &= \cos^{-1}(\varepsilon_{0}^{\frac{1}{\alpha+2}}) \\ \phi &= 2\pi \varepsilon_{1} \end{aligned} \end{matrix}\right.

pdf(wi)=(Ξ±+2)cosΞΈ(Ξ±+1)2Ο€pdf(w_{i}) = \frac{(\alpha+2)\cos\theta^{(\alpha+1)}}{2\pi}

Derivation

pdf(Ο‰)=D(h)cosΞΈ=(Ξ±+2)cosΞΈΞ±cosΞΈ2Ο€=(Ξ±+2)cosΞΈ(Ξ±+1)2Ο€pdf(ΞΈ,Ο•)=pdf(Ο‰)sinΞΈ=(Ξ±+2)cosΞΈ(Ξ±+1)sinΞΈ2Ο€\begin{aligned} pdf(\omega) &= D(h)\cos\theta = \frac{(\alpha+2)\cos\theta^{\alpha}\cos\theta}{2\pi} = \frac{(\alpha+2)\cos\theta^{(\alpha+1)}}{2\pi} \\ pdf(\theta,\phi) &= pdf(\omega ) \sin\theta = \frac{(\alpha+2)\cos\theta^{(\alpha+1)}\sin\theta}{2\pi} \end{aligned}

Next, the PDF is split up. We obtain the pdf for ΞΈ\theta by integrating over the whole domain of the Ο•\phi angle which is the same as multiplying by 2Ο€2\pi since the pdf is isotropic. The pdf for Ο•\phi may be obtained by using conditional probabilities and the rule of Bayes.

pdf(ΞΈ)=∫02Ο€pdf(ΞΈ,Ο•)dΟ•=(Ξ±+2)cosΞΈ(Ξ±+1)sinΞΈpdf(Ο•βˆ£ΞΈ)=pdf(ΞΈ,Ο•)pdf(ΞΈ)=(Ξ±+2)cosΞΈ(Ξ±+1)sinΞΈ2Ο€(Ξ±+2)cosΞΈ(Ξ±+1)sinΞΈ=12Ο€\begin{aligned} pdf(\theta) &= \int_{0}^{2\pi}pdf(\theta, \phi) d\phi = (\alpha+2)\cos\theta^{(\alpha+1)}\sin\theta \\ pdf(\phi|\theta) &= \frac{pdf(\theta, \phi)}{pdf(\theta)} = \frac{\frac{(\alpha+2)\cos\theta^{(\alpha+1)}\sin\theta}{2\pi}}{(\alpha+2)\cos\theta^{(\alpha+1)}\sin\theta} = \frac{1}{2\pi} \end{aligned}

We can then integrate the PDF to get the CDF.

cdf(ΞΈ)=∫0ΞΈpdf(ΞΈ)dΞΈ=∫0ΞΈ(Ξ±+2)cosΞΈ(Ξ±+1)sinΞΈdΞΈ=1βˆ’cosΞΈ(Ξ±+2)cdf(Ο•βˆ£ΞΈ)=∫0Ο•pdf(Ο•βˆ£ΞΈ)dΞΈ=∫0Ο•12Ο€dΟ•=1Ο•2Ο€\begin{aligned} cdf(\theta) &= \int_{0}^{\theta}pdf(\theta)d\theta = \int_{0}^{\theta}(\alpha+2)\cos\theta^{(\alpha+1)}\sin\theta d\theta = 1-\cos\theta^{(\alpha+2)} \\ cdf(\phi|\theta) &= \int_{0}^{\phi}pdf(\phi|\theta) d\theta = \int_{0}^{\phi}\frac{1}{2\pi} d\phi = \frac{1\phi}{2\pi} \end{aligned}

By setting these CDFs equal to a random number Ξ΅,Ο΅[0,1]\varepsilon, \epsilon \left [ 0, 1 \right ], we can find an equation for the angle ΞΈ\theta and Ο•\phi that we can use for our sample.

\begin{alignat*}{2} cdf(\theta) &= 1-\cos\theta^{(\alpha+2)}\theta {}& =\varepsilon_{0} \rightarrow \theta &= \cos^{-1}((1-\varepsilon_{0})^{\frac{1}{\alpha+2}}) \\ cdf(\phi|\theta) &= \frac{1\phi}{2\pi} {}& =\varepsilon_{1} \rightarrow \phi &= 2\pi \varepsilon_{1} \end{alignat*}

Since Ξ΅\varepsilon is a number between 0 and 1, these equations can be written a bit cleaner as follows.

{ΞΈ=cosβˆ’1(Ξ΅01Ξ±+2)Ο•=2πΡ1\left\{\begin{matrix} \begin{aligned} \theta &= \cos^{-1}(\varepsilon_{0}^{\frac{1}{\alpha+2}}) \\ \phi &= 2\pi \varepsilon_{1} \end{aligned} \end{matrix}\right.

Beckmann

D(h)=eβˆ’tanΞΈ2Ξ±2Ξ±2cos4ΞΈD(h) = \frac{e^{\frac{-\tan\theta^{2}}{\alpha^{2}}}}{\alpha^{2}\cos^4\theta}

{ΞΈ=tanβˆ’1βˆ’Ξ±2ln(1βˆ’Ξ΅0Ο€)Ο•=2πΡ1\left\{\begin{matrix} \begin{aligned} \theta &= \tan^{-1}\sqrt{-\alpha^2\ln(1-\frac{\varepsilon_{0}}{\pi})} \\ \phi &= 2\pi \varepsilon_{1} \end{aligned} \end{matrix}\right.

pdf(wi)=eβˆ’tanΞΈ2Ξ±2Ξ±2cos3ΞΈpdf(w_{i}) = \frac{e^{\frac{-\tan\theta^{2}}{\alpha^{2}}}}{\alpha^{2}\cos^3\theta}

Derivation

pdf(Ο‰)=D(h)cosΞΈ=eβˆ’tanΞΈ2Ξ±2cosΞΈΞ±2cos4ΞΈ=eβˆ’tanΞΈ2Ξ±2Ξ±2cos3ΞΈpdf(ΞΈ,Ο•)=pdf(Ο‰)sinΞΈ=eβˆ’tanΞΈ2Ξ±2sinΞΈΞ±2cos3ΞΈ\begin{aligned} pdf(\omega) &= D(h)\cos\theta = \frac{e^{\frac{-\tan\theta^{2}}{\alpha^{2}}}\cos\theta}{\alpha^{2}\cos^4\theta} = \frac{e^{\frac{-\tan\theta^{2}}{\alpha^{2}}}}{\alpha^{2}\cos^3\theta} \\ pdf(\theta,\phi) &= pdf(\omega ) \sin\theta = \frac{e^{\frac{-\tan\theta^{2}}{\alpha^{2}}}\sin\theta}{\alpha^{2}\cos^3\theta} \end{aligned}

Next, the PDF is split up. We obtain the pdf for ΞΈ\theta by integrating over the whole domain of the Ο•\phi angle which is the same as multiplying by 2Ο€2\pi since the pdf is isotropic. The pdf for Ο•\phi may be obtained by using conditional probabilities and the rule of Bayes.

pdf(ΞΈ)=∫02Ο€pdf(ΞΈ,Ο•)dΟ•=2Ο€eβˆ’tanΞΈ2Ξ±2sinΞΈΞ±2cos3ΞΈpdf(Ο•βˆ£ΞΈ)=pdf(ΞΈ,Ο•)pdf(ΞΈ)=eβˆ’tanΞΈ2Ξ±2sinΞΈΞ±2cos3ΞΈ2Ο€eβˆ’tanΞΈ2Ξ±2sinΞΈΞ±2cos3ΞΈ=12Ο€\begin{aligned} pdf(\theta) &= \int_{0}^{2\pi}pdf(\theta, \phi) d\phi = \frac{2\pi e^{\frac{-\tan\theta^{2}}{\alpha^{2}}}\sin\theta}{\alpha^{2}\cos^3\theta} \\ pdf(\phi|\theta) &= \frac{pdf(\theta, \phi)}{pdf(\theta)} = \frac{\frac{e^{\frac{-\tan\theta^{2}}{\alpha^{2}}}\sin\theta}{\alpha^{2}\cos^3\theta}}{\frac{2\pi e^{\frac{-\tan\theta^{2}}{\alpha^{2}}}\sin\theta}{\alpha^{2}\cos^3\theta}} = \frac{1}{2\pi} \end{aligned}

We can then integrate the PDF to get the CDF.

cdf(ΞΈ)=∫0ΞΈpdf(ΞΈ)dΞΈ=∫0ΞΈ2Ο€eβˆ’tanΞΈ2Ξ±2sinΞΈΞ±2cos3ΞΈdΞΈ=Ο€(1βˆ’eβˆ’tanΞΈ2Ξ±2)cdf(Ο•βˆ£ΞΈ)=∫0Ο•pdf(Ο•βˆ£ΞΈ)dΞΈ=∫0Ο•12Ο€dΟ•=1Ο•2Ο€\begin{aligned} cdf(\theta) &= \int_{0}^{\theta}pdf(\theta)d\theta = \int_{0}^{\theta}\frac{2\pi e^{\frac{-\tan\theta^{2}}{\alpha^{2}}}\sin\theta}{\alpha^{2}\cos^3\theta} d\theta = \pi(1-e^{\frac{-\tan\theta^{2}}{\alpha^{2}}})\\ cdf(\phi|\theta) &= \int_{0}^{\phi}pdf(\phi|\theta) d\theta = \int_{0}^{\phi}\frac{1}{2\pi} d\phi = \frac{1\phi}{2\pi} \end{aligned}

By setting these CDFs equal to a random number Ξ΅,Ο΅[0,1]\varepsilon, \epsilon \left [ 0, 1 \right ], we can find an equation for the angle ΞΈ\theta and Ο•\phi that we can use for our sample.

\begin{alignat*}{2} cdf(\theta) &= \pi(1-e^{\frac{-\tan\theta^{2}}{\alpha^{2}}}) {}& =\varepsilon_{0} \rightarrow \theta &= \tan^{-1}\sqrt{-\alpha^2\ln(1-\frac{\varepsilon_{0}}{\pi})} \\ cdf(\phi|\theta) &= \frac{1\phi}{2\pi} {}& =\varepsilon_{1} \rightarrow \phi &= 2\pi \varepsilon_{1} \end{alignat*}

This gives us the following samples.

{ΞΈ=tanβˆ’1βˆ’Ξ±2ln(1βˆ’Ξ΅0Ο€)Ο•=2πΡ1\left\{\begin{matrix} \begin{aligned} \theta &= \tan^{-1}\sqrt{-\alpha^2\ln(1-\frac{\varepsilon_{0}}{\pi})} \\ \phi &= 2\pi \varepsilon_{1} \end{aligned} \end{matrix}\right.

Additional resources

http://www.igorsklyar.com/system/documents/papers/4/fiscourse.comp.pdf

https://agraphicsguynotes.com/posts/sample_microfacet_brdf/

https://www.reedbeta.com/blog/hows-the-ndf-really-defined/

https://www.graphics.cornell.edu/~bjw/wardnotes.pdf

https://cseweb.ucsd.edu/~ravir/6998/papers/p265-ward.pdf

https://schuttejoe.github.io/post/ggximportancesamplingpart1/