0
$\begingroup$

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:

  1. Pick a light $L$ in the scene with some PDF $p_{\mathcal{L}}$.
  2. 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).
  3. Cast a shadow ray from the current position $x$ to the sampled point $y$.
  4. Check visibility.
  5. 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 $p_\omega(y) = \frac{\cos \theta_y}{\lvert y-x \rvert ^2} p_A(y)$.
  6. 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.
  7. 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.

New contributor
uhwo is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
2
  • $\begingroup$ How do you pick a point uniformly on the triangular mesh? Also $p_\omega(\omega)\,d\omega = p_\omega(\omega)\frac{\cos\theta_y}{\|y-x\|^2}\,dA = p_A(y)\,dA$ and then $p_\omega(\omega) = \frac{\|y-x\|^2}{\cos\theta_y}p_A(y)$, so your pdf was wrong unless I'm trippin. $\endgroup$
    – lightxbulb
    yesterday
  • $\begingroup$ Entire surface is correct since you filter out 0 contribution through the visibility function. It is like having a function $g$ that is nonzero in $[a,b]$ (i.e. $\operatorname{supp}(f) = [a,b]$) and instead of numerically approximating $\int_{a}^{b}g(t)\,dt$ you approximate $\int_{a}^{b+\delta}g(t)\,dt= \int_{a}^{b}g(t)\,dt + \int_{b}^{b+\delta}g(t)\,dt =\int_a^b g(t)\,dt$, with $\delta>0$. But as you can see those are equal (since $g((b,b+\delta]) = 0$) Granted you'll have higher variance when approximating $\int_a^{b+\delta}g(t)\,dt$ because some samples will end up with zero contribution. $\endgroup$
    – lightxbulb
    yesterday

Your Answer

uhwo is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.