# 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 2 days ago
• pbr-book.org/3ed-2018/Color_and_Radiometry/… – Peter 22 hours ago
• 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 22 hours ago
• @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 20 hours ago
• 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 15 hours ago

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$$: