• Portfolio and blog of sydneyzh.

# Sampling from a hemisphere

By following the same steps of CDF function inversion method from the previous post, a pair of canonical random variables $(\varepsilon_1, \varepsilon_2)$ can be transformed to sample on a hemisphere.

The general CDF takes the form of $$C \int_0^{\phi_0} \int_0^{\theta_0} w(\phi, \theta) \mathrm{sin}\theta\mathrm{d}\phi \mathrm{d}\theta,$$ in which $w(\phi, \theta)$ is the weight function.

To generate samples uniformly, $w$ is aa constant of one. So the transformation from $(\varepsilon_1, \varepsilon_2)$ to $(\phi, \theta)$ can be

$$\phi = 2\pi \varepsilon_1 \text{ and } \theta = \mathrm{acos}(1 - \varepsilon_2).$$

To generate cosine weighted samples for graphics applications(recall that there is a cosine factor between the tangent plane picking up the radiance and the reflection/scattering surface plane),

$$w(\theta) = \mathrm{cos}\theta.$$

Therefore, the transformation can be solved as

$$\phi = 2\pi \varepsilon_1 \text{ and } \theta = \mathrm{acos}(\sqrt{1 - \varepsilon_2}).$$

Uniform(left) and cosine weighted(right) sampling results: