# Probability density for explicit light sampling

When implementing explicit light sampling, I am separating the monte-carlo approximation to two parts

$$\frac{1}{N+M}(\sum^N \text{direct} + \sum^M \text{indirect})$$

$$\text{direct} = \frac{\text{bsdf} \times C \times cos(\theta)}{p}$$

I am confused as how to obtain $$p$$ for direct lightning. My light source is an arbitrary triangularized mesh and I am sampling random points from it's surface.

A solution was presented here: Path weight for direct light sampling

$$\frac{A}{r^2} (N_\text{light} \cdot -L)$$

Where does this come from? I'm asking for a reference or a derivation. Thanks!

• Read "[Shirley, 1996] Monte Carlo Techniques for Direct Lighting Calculations". – gallickgunner Jun 29 at 16:50
• pbr-book.org/3ed-2018/Color_and_Radiometry/… – Peter Jul 1 at 10:50
• Also, I think you need to account for the probability of picking that triangle. I believe that the first equation you list is incorrect. You can't just add the direct and indirect samples together because they are from two different sampling schemes. You should look at multiple importance sampling which is a technique for combining sampling methods together. If you want help with implementing that don't hesitate to ask. – Peter Jul 1 at 10:50
• @Peter i thought the probability is taken into account with $A$, as long as points are sampled uniformly from the surface. However i already got decent results adding together the samples. The link I mentioned explains that the samples can be added together when using the formula – vuoriov4 Jul 1 at 13:05
• I think it would work as long as A is the surface area of the whole mesh (not the triangle you are sampling) and the probablity of selecting a triangle is proportional to its surface area. If you want to do more advanced triangle selection which takes into account occlusion or distance from the shading point then you would have to change this. – Peter Jul 1 at 17:45

It comes from the relation between the area formulation and the solid angle formulation of the rendering equation: $$d\omega = \frac{\cos\theta_L}{r^2}dA$$: