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), 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 @lightxbulb, 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.