<p>The issue was that I'm computing the top and bottom of the sphere relative to the plane. But the point &quot;views&quot; the sphere from a certain perspective, so the apparent top and bottom aren't necessarily at the same place.
<a href="https://i.sstatic.net/JptXCTZ2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JptXCTZ2.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2024-07-16T20:56:52.357Z
2024-07-16T20:56:52.357Z
Puppy
<p>I'm looking at using multiple importance sampling for path tracing, and doing some lighting calculations relating to spherical lights. I'm trying to decide, given a triangle and a point on that triangle, how the sphere should appear. This should mean calculating how much of the sphere is above the plane (if any) and where in the &quot;sky&quot; it should be so that I can sample and weight rays heading there appropriately.</p>
<p>So far I've done this:</p>
<pre><code>float top = dot(normal, normalize((lightPosition + (normal * size)) - origin));
float bottom = dot(normal, normalize((lightPosition - (normal * size)) - origin));
</code></pre>
<p>where <code>normal</code> is the triangle's normal, <code>origin</code> is my point on that triangle, <code>lightPosition</code> is the center of the sphere and <code>size</code> is the radius. My simple strategy was to decide the &quot;highest and lowest&quot; points on the sphere and measure their angles. But I had a surprising result which is that some <code>origin</code>s report that the <code>top</code> is above the triangle (i.e. &gt;0) and others report it as below the triangle (i.e. &lt;0). At first I thought this must be some mistake of the data, but employing the debugger, all origins agree on the normal, position, and size, and sampling a few origins and computing the normal gives the expected result.</p>
<p>To be clear in this case, there is no bump mapping or other shenanigans with the <code>normal</code>, it is computed with the standard <code>normalize(cross(b - a, c - a))</code> method from the vertices of the triangle so all <code>origin</code>s always see exactly the same <code>normal</code>.</p>
<p>Any thoughts on how to improve this measurement so that all <code>origin</code>s agree on how much of the sphere is above or below the triangle?</p>

<3d><pathtracing>
Measuring sphere angles to triangle
Puppy
# Measuring sphere angles to triangle

(Asked by: username_0 on 2024-07-12)

I'm looking at using multiple importance sampling for path tracing, and doing some lighting calculations relating to spherical lights. I'm trying to decide, given a triangle and a point on that triangle, how the sphere should appear. This should mean calculating how much of the sphere is above the plane (if any) and where in the "sky" it should be so that I can sample and weight rays heading there appropriately.

So far I've done this:

```
float top = dot(normal, normalize((lightPosition + (normal * size)) - origin));
float bottom = dot(normal, normalize((lightPosition - (normal * size)) - origin));

```

where `normal` is the triangle's normal, `origin` is my point on that triangle, `lightPosition` is the center of the sphere and `size` is the radius. My simple strategy was to decide the "highest and lowest" points on the sphere and measure their angles. But I had a surprising result which is that some `origin`s report that the `top` is above the triangle (i.e. >0) and others report it as below the triangle (i.e. <0). At first I thought this must be some mistake of the data, but employing the debugger, all origins agree on the normal, position, and size, and sampling a few origins and computing the normal gives the expected result.

To be clear in this case, there is no bump mapping or other shenanigans with the `normal`, it is computed with the standard `normalize(cross(b - a, c - a))` method from the vertices of the triangle so all `origin`s always see exactly the same `normal`.

Any thoughts on how to improve this measurement so that all `origin`s agree on how much of the sphere is above or below the triangle?

**Tags:** 3d, pathtracing


---

## 1 answers

### Answer by username_0 on 2024-07-16. Score: 0 | Accepted answer

The issue was that I'm computing the top and bottom of the sphere relative to the plane. But the point "views" the sphere from a certain perspective, so the apparent top and bottom aren't necessarily at the same place.
[![enter image description here](https://i.sstatic.net/JptXCTZ2.png)](https://i.sstatic.net/JptXCTZ2.png)


---

