<p>To perform importance sampling on a light source, a probability density function must be provided for the sampling distribution. For most light sources, a valid probability distribution can be found, but point lights and pure directional lights (directional lights which emit light exclusively in one direction, with 0 spread angle) do not have this property, as there is only one valid light path connecting them with any given point. This would require an infinite probability density, which would result in an infinitely small light contribution due to importance sampling. My question is: how can these light types be sampled without introducing bias?</p>
<p>I've asked more specifically about the mathematics behind this <a href="https://math.stackexchange.com/questions/4217966/what-would-be-the-probability-density-function-for-a-monte-carlo-sampling-strate">on the Mathematics Stack Exchange</a>, but seeing as I received no replies there, I think this would be a more appropriate place to ask.</p>

CC BY-SA 4.0
2022-01-12T02:11:59.833Z
There's nothing to integrate for those. You just directly evaluate the contribution. You can see this as having to compute $\int_{\Omega}f(x)g(x)\,dx$, where $g(x) =\delta(x-y) + h(x)$, and thus getting $f(y) + \int_{\Omega}f(x)h(x)\,dx$. The $f(y)$ is just a pointwise evaluation and doesn't require any importance sampling in the usual sense. Dirac deltas due to point/directional lights or ideal mirrors or refractors simply collapse an integral in the continuous formulation. Numerical methods would not be able to handle the singularity, so you get rid of it in the continuous setting still.
lightxbulb
CC BY-SA 4.0
2022-01-13T16:35:47.700Z
To add to this I think you can also sample it as you would any other light and set the pdf to be very very high and multiply the value by that pdf as well. This ensures that the multiple importance sampling weight becomes ~1 and when you divide by the pdf the value is still the same. This should be equivelent to directly evaluating it as above but might be easier to implement if you have a system for lights you dont want to modify.
Peter
CC BY-SA 4.0
2022-01-14T13:22:37.833Z
@Peter This approach may run into numerical precision issues. Ideally you want to use analytical methods everywhere where it is possible. For example if you use a cosine weighted distribution you would ideally cancel out the cosines for the implementation as $0/0$ isn't handled well by floating point numbers. A Dirac delta is a much more problematic singularity (it's not even a function in the classical sense, i.e. it's not enough setting it to infinity at a point and zero everywhere else), you're supposed to get rid of it in the continuous setting.
lightxbulb
CC BY-SA 4.0
2022-01-14T17:06:56.927Z
@lightxbulb Yep I would recomend using your method where possible. Could you explain where you are getting the 0/0 from to me though? In out = MIS * bxdf * light / pdf
Peter
CC BY-SA 4.0
2022-01-14T17:40:15.307Z
@Peter $\frac{\cos\theta}{\cos\theta} \rightarrow \frac{0}{0}$ for $\theta \rightarrow \pm \frac{\pi}{2}$. Due to how floating point works you get issues even if $\cos\theta$ is not zero but small enough. Ideally you would cancel out the denominator analytically and then apply the numerical methods on the simplified expression. As far as the Dirac delta goes, I am not even sure what pdf you plan to use there.
lightxbulb
CC BY-SA 4.0
2022-01-16T23:16:47.300Z
@lightxbulb So you always set the light pdf to some arbitrary large value like 1x10^8 and you multiply your light value by this as well. Then when you sample the light, the NEE equation light_out= MIS * bxdf * light_value / light_pdf becomes  light_out= ~1 * bxdf * light_value * 1x10^8  / 1x10^8. The MIS evaluates to ~1 because 1x10^8 dominates the power heuristic and the terms cancels out so in the end you get light_out = bxdf * light_value.
Peter
<pathtracing><lighting><sampling><importance-sampling>
How are point and pure directional lights sampled in an unbiased path tracer?
SupaKoopaTroopa64
# How are point and pure directional lights sampled in an unbiased path tracer?

(Asked by: username_0 on 2022-01-12)

To perform importance sampling on a light source, a probability density function must be provided for the sampling distribution. For most light sources, a valid probability distribution can be found, but point lights and pure directional lights (directional lights which emit light exclusively in one direction, with 0 spread angle) do not have this property, as there is only one valid light path connecting them with any given point. This would require an infinite probability density, which would result in an infinitely small light contribution due to importance sampling. My question is: how can these light types be sampled without introducing bias?

I've asked more specifically about the mathematics behind this [on the Mathematics Stack Exchange](https://math.stackexchange.com/questions/4217966/what-would-be-the-probability-density-function-for-a-monte-carlo-sampling-strate), but seeing as I received no replies there, I think this would be a more appropriate place to ask.

**Tags:** pathtracing, lighting, sampling, importance-sampling

> **Comments:**
> **username_1**: There's nothing to integrate for those. You just directly evaluate the contribution. You can see this as having to compute $\int_{\Omega}f(x)g(x)\,dx$, where $g(x) =\delta(x-y) + h(x)$, and thus getting $f(y) + \int_{\Omega}f(x)h(x)\,dx$. The $f(y)$ is just a pointwise evaluation and doesn't require any importance sampling in the usual sense. Dirac deltas due to point/directional lights or ideal mirrors or refractors simply collapse an integral in the continuous formulation. Numerical methods would not be able to handle the singularity, so you get rid of it in the continuous setting still.  
> **username_2**: To add to this I think you can also sample it as you would any other light and set the pdf to be very very high and multiply the value by that pdf as well. This ensures that the multiple importance sampling weight becomes ~1 and when you divide by the pdf the value is still the same. This should be equivelent to directly evaluating it as above but might be easier to implement if you have a system for lights you dont want to modify.  
> **username_1**: @username_2 This approach may run into numerical precision issues. Ideally you want to use analytical methods everywhere where it is possible. For example if you use a cosine weighted distribution you would ideally cancel out the cosines for the implementation as $0/0$ isn't handled well by floating point numbers. A Dirac delta is a much more problematic singularity (it's not even a function in the classical sense, i.e. it's not enough setting it to infinity at a point and zero everywhere else), you're supposed to get rid of it in the continuous setting.  
> **username_2**: @username_1 Yep I would recomend using your method where possible. Could you explain where you are getting the 0/0 from to me though? In out = MIS * bxdf * light / pdf  
> **username_1**: @username_2 $\frac{\cos\theta}{\cos\theta} \rightarrow \frac{0}{0}$ for $\theta \rightarrow \pm \frac{\pi}{2}$. Due to how floating point works you get issues even if $\cos\theta$ is not zero but small enough. Ideally you would cancel out the denominator analytically and then apply the numerical methods on the simplified expression. As far as the Dirac delta goes, I am not even sure what pdf you plan to use there.  
> **username_2**: @username_1 So you always set the light pdf to some arbitrary large value like 1x10^8 and you multiply your light value by this as well. Then when you sample the light, the NEE equation light_out= MIS * bxdf * light_value / light_pdf becomes  light_out= ~1 * bxdf * light_value * 1x10^8  / 1x10^8. The MIS evaluates to ~1 because 1x10^8 dominates the power heuristic and the terms cancels out so in the end you get light_out = bxdf * light_value.  

---

## 0 answers

