<p>This is generally difficult (or even, impossible) to derive a closed form sampling method. The original uniform solid angle sampling in a cone is perfectly rotation-symmetric around the cone axis, meaning that <span class="math-container">$\theta$</span> and <span class="math-container">$\phi$</span> can be discussed independently, with <span class="math-container">$\phi$</span> (azimuth angle) being sampled uniformly in <span class="math-container">$[0, 2 \pi)$</span>. Yet in this case, <span class="math-container">$\theta$</span> and <span class="math-container">$\phi$</span> are tightly coupled, meaning that we are sampling from a &quot;PDF-inseparable&quot; joint distribution. The projected curve on the camera plane (if we want to first uniformly sample <span class="math-container">$\phi$</span> and sample <span class="math-container">$\theta$</span> according to <span class="math-container">$\phi$</span>, the projected curve should be considered) is difficult to discuss, check <a href="https://mathworld.wolfram.com/Cone-SphereIntersection.html" rel="nofollow noreferrer">this post (sphere cone intersection)</a> out. Even if the curve has a simple form, the resulting samples won't be uniform in the visible solid angle.</p>
<p>You may have already guessed that there are a few numerical solution to this problem:</p>
<ul>
<li><p>Rejection sampling (<strong>recommended</strong>): use the original uniform cone sampling and for every sample, check whether it is visible in an easier way, for example: check the angle between the occlusion plane normal and the spherical direction of the sample. This basically means that you should keep sampling until you have a visible sample. This way is recommended because rejection sampling can produce valid PDF for MIS. Then you may improve the variance performance by apply MIS with visible sphere sampling (if the visible part of the sphere is small, this might be helpful). The PDF produced should be the PDF of the cone sampling, <strong>conditioned</strong> on the sample being visible, which can be computed in closed form.</p>
</li>
<li><p>RIS. This effectively means that you should generate N candidate samples at once, and weight them by their visibility, then resample using the weight. RIS might be preferred if speed is of concern (on CPU the candidate sampling can be easily SIMD-vectorized). RIS won't produce valid PDF for MIS, btw. Check out <a href="https://chat.stackexchange.com/rooms/154146/discussion-between-enigmatisms-and-tom-clabault">this discussion: (search RIS in the page)</a>. RIS can fail, if all samples are unluckily occluded.</p>
</li>
</ul>

CC BY-SA 4.0
2024-08-09T21:09:01.693Z
I think that rejection sampling would be pretty painful on the GPU, where every thread in the warp would have to pay the price of the worst case, and any spikes in runtime would be very painful. Would it be viable to reconsider the partially occluded case as acting as if fully visible, but just with a "fast miss" where if the sample is >90 from normal, I save the effort of having to cast a ray? I think in the MC sense, this should still qualify as taking a sample, so MIS would still work as usual?
Puppy
CC BY-SA 4.0
2024-08-08T02:43:37.770Z
2024-08-08T02:43:37.770Z
Enigmatisms
<p>I'm looking at sampling a spherical light source, which may be partially occluded by the plane of the geometry. I've implemented a detection for this case, and skipped sampling if it's all occluded, and uniform sampled the cone in the case of no occlusion, however it's not really clear how to handle the case of <em>partial</em> occlusion. In this case I want to uniformly sample the part that is visible. However since the uniform cone sample calls for the sample to be expressed in spherical co-ordinates, it's not clear how to modify it to handle a partial case. There's a few discussions of a truncated cone, but these seem to have the plane as perpendicular to the cone's direction, rather than truncating it from the side.<a href="https://i.sstatic.net/rVuNO5kZ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rVuNO5kZ.png" alt="enter image description here" /></a></p>
<p>How can I obtain uniform samples of the partial cone? Can uniform samples of the cone be considered uniform samples of a circle at a specific distance, so perhaps the partial cone could be considered uniform samples of a circular segment?</p>

<sampling><monte-carlo>
Sampling a partial cone
Puppy
# Sampling a partial cone

(Asked by: username_0 on 2024-08-06)

I'm looking at sampling a spherical light source, which may be partially occluded by the plane of the geometry. I've implemented a detection for this case, and skipped sampling if it's all occluded, and uniform sampled the cone in the case of no occlusion, however it's not really clear how to handle the case of *partial* occlusion. In this case I want to uniformly sample the part that is visible. However since the uniform cone sample calls for the sample to be expressed in spherical co-ordinates, it's not clear how to modify it to handle a partial case. There's a few discussions of a truncated cone, but these seem to have the plane as perpendicular to the cone's direction, rather than truncating it from the side.[![enter image description here](https://i.sstatic.net/rVuNO5kZ.png)](https://i.sstatic.net/rVuNO5kZ.png)

How can I obtain uniform samples of the partial cone? Can uniform samples of the cone be considered uniform samples of a circle at a specific distance, so perhaps the partial cone could be considered uniform samples of a circular segment?

**Tags:** sampling, monte-carlo


---

## 1 answers

### Answer by username_1 on 2024-08-08. Score: 1 | Accepted answer

This is generally difficult (or even, impossible) to derive a closed form sampling method. The original uniform solid angle sampling in a cone is perfectly rotation-symmetric around the cone axis, meaning that $\theta$ and $\phi$ can be discussed independently, with $\phi$ (azimuth angle) being sampled uniformly in $[0, 2 \pi)$. Yet in this case, $\theta$ and $\phi$ are tightly coupled, meaning that we are sampling from a "PDF-inseparable" joint distribution. The projected curve on the camera plane (if we want to first uniformly sample $\phi$ and sample $\theta$ according to $\phi$, the projected curve should be considered) is difficult to discuss, check [this post (sphere cone intersection)](https://mathworld.wolfram.com/Cone-SphereIntersection.html) out. Even if the curve has a simple form, the resulting samples won't be uniform in the visible solid angle.

You may have already guessed that there are a few numerical solution to this problem:

* Rejection sampling (**recommended**): use the original uniform cone sampling and for every sample, check whether it is visible in an easier way, for example: check the angle between the occlusion plane normal and the spherical direction of the sample. This basically means that you should keep sampling until you have a visible sample. This way is recommended because rejection sampling can produce valid PDF for MIS. Then you may improve the variance performance by apply MIS with visible sphere sampling (if the visible part of the sphere is small, this might be helpful). The PDF produced should be the PDF of the cone sampling, **conditioned** on the sample being visible, which can be computed in closed form.
* RIS. This effectively means that you should generate N candidate samples at once, and weight them by their visibility, then resample using the weight. RIS might be preferred if speed is of concern (on CPU the candidate sampling can be easily SIMD-vectorized). RIS won't produce valid PDF for MIS, btw. Check out [this discussion: (search RIS in the page)](https://chat.stackexchange.com/rooms/154146/discussion-between-username_1-and-tom-clabault). RIS can fail, if all samples are unluckily occluded.

> **Comments:**
> **username_0**: I think that rejection sampling would be pretty painful on the GPU, where every thread in the warp would have to pay the price of the worst case, and any spikes in runtime would be very painful. Would it be viable to reconsider the partially occluded case as acting as if fully visible, but just with a "fast miss" where if the sample is >90 from normal, I save the effort of having to cast a ray? I think in the MC sense, this should still qualify as taking a sample, so MIS would still work as usual?  

---

