Where does the cosine factor comes from in the GGX PDF?

The GGX NDF, as it appears on the paper where it is presented is:

$$D(m)=\frac{\alpha_g^2\space\chi^+(m\cdot n)}{\pi\cos^4(\theta_m)(\alpha_g^2+\tan^2(\theta_m))^2}$$

It is equivalent, in the range $[0,\frac{\pi}{2}]$, to the following formulation (notation simplified by me):

$$D(m)=\frac{\alpha^2}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}$$

by finding the derivative of the inverse of the expresions used for importance sampling ($\theta_m=\arctan(\frac{\alpha\sqrt{\xi_1}}{\sqrt{1-\xi_1}})$ and $\phi_m=2\pi\xi_2$) presented in the same paper we can derive the following PDF:

$$p(m)=\frac{\alpha^2\cos(\theta)\sin(\theta)}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}$$

When finding the corresponding PDF for, for instance, the Blinn NDF the only difference is a $\sin(\theta)$ in the numerator that comes from the fact that the NDF is a distribution over a hemisphere. So where does the $\cos(\theta)$ factor in the GGX PDF come from?

I think it is explained after formula (37) in the paper but i don't understand the reasoning behind it.

PD:here are the Blinn NDF and PDF as i understand them for reference

NDF: $\frac{n+1}{2\pi}\cos^n(\theta)$ --- PDF: $\frac{n+1}{2\pi}\cos^n(\theta)\sin(\theta)$

EDIT: here is a link to the paper in case it makes the question easier to answer

• BTW, the Blinn–Phong NDF should have $n + 2$, not $n + 1$, in the numerator (see equation 30 in the paper). – Nathan Reed Dec 5 '17 at 21:49
• Yup, thank you. now I also understand that the exponent in the PDF should be n+1 – Sebastián Mestre Dec 6 '17 at 6:37

Normal distribution functions are defined a bit differently than you might expect. They're not strictly a probability distribution over solid angle; they have to do with the density of microfacets with respect to macro-surface area. The upshot is that they're normalized with an extra cosine factor: $$\int_\Omega D(m) \cos(\theta_m)\, d\omega_m = 1$$ This cosine factor accounts for the projected area of microfacets onto the macrosurface. When importance-sampling the NDF this cosine factor must be accounted for as well.
The equations for sampling $D(m) | m \cdot n |$ are:
(just above equations 35–36). The $|m \cdot n|$ factor there is equal to $|cos(\theta_m)|$. So the quantity being sampled is not just the NDF itself, but includes this extra factor. Then, as you note, the sine shows up as part of the area element for spherical coordinates.