I'm writing a Monte Carlo path tracer, and I'm trying to allow any mesh to be an emitter, but I'm not entirely sure about the probabilities to use when I sample them.
Right now, my algorithm for light sampling does the following:
- Pick a light $L$ in the scene with some PDF $p_{\mathcal{L}}$.
- Pick a random point $y$ on the mesh with uniform probability $p_{\mathcal{S}}(y) = \frac1{S_L}$, where $S_L$ is the total area of the mesh (computed summing over all the areas of all the triangles composing the mesh).
- Cast a shadow ray from the current position $x$ to the sampled point $y$.
- Check visibility.
- Compute the PDF wrt solid angle (I need it wrt to solid angle for my integrator); the PDF wrt area mesure should now be just $p_A(y) = p_{\mathcal{L}}(L) \cdot p_{\mathcal{S}}(y)$ (the choice of light and of a point on the light are independent events), hence the actual PDF I need is EDIT: not $p_\omega(\omega) = \frac{\cos \theta_y}{\lvert y-x \rvert ^2} p_A(y)$ but $p_\omega(\omega) = \frac{\lvert y-x \rvert ^2}{\cos \theta_y} p_A(y)$ :).
- Compute the light contribution to the current point as $\frac{E_L \cdot f_r \cdot \cos(\theta_x)}{p_\omega(y)}\cdot \mathrm{thr}$, where $\mathrm{thr}$ is the ray throughput, $E_L$ is the emissive value of the light $L$, $f_r = f_r(-\omega_{\mathrm{incoming}},\omega_{\mathrm{shadow}})$ is the BRDF of the surface containing $x$, $\omega_{\mathrm{incoming}}$ is the unit vector of the current ray direction, and $\omega_{\mathrm{shadow}} = \frac{y-x}{\lvert y-x \rvert ^2}$ is the direction of the shadow ray.
- Use that light contribution for next event estimation; use $p_\omega$ as my PDF for the NEE when computing the weights for multiple importance sampling.
I think this should account correctly for the fact that only the projected area of my mesh on the plane of the triangle $x$ lies on should contribute to the illumination of $x$, as the visibility check rules out all the triangles "hidden" by the geometry of the mesh, but I'd like to be sure that I'm not forgetting anything.
EDIT: In particular, the thing that makes me a bit unsure is using the entire surface area of the mesh, even though the part facing the point $x$ might be much smaller.
so that the PDF for picking a triangle is weighted by the surface of each triangle
- I was worried that may not have been the case. It's all good if you're doing this (it's called inverse transform sampling btw). Note that if you non-uniformly rescale your mesh, the CDF becomes invalid. Also I hope you properly uniformly sample the triangle - there's some math in the Global Illumination Compendium, in PBRT, in ray-tracing gems, and in some other places. $\endgroup$