<p>It is mainly personal preference, but it does have some logic behind it which would make it a better option. It should not have any big impact on your final image, though.</p>

<p>When the discriminant is 0, then that means that there is only one solution. For a sphere, when there is only one solution, that means that the ray is tangent to the sphere. When a line or ray is tangent to a sphere, that means that there is a 90° angle between the line/ray and the normal of the sphere at the intersection. When comparing that situation to ray-triangle and ray-plane intersections, they always ignore the hit when it has an angle of 90° with the normal. This is because the ray would then not really be able to hit it, and in real life you cannot see an infinitely thin plane or triangle that is perfectly parallel to your viewing direction.</p>

<p>Discarding hits when the angle is 90° could also help with shading. Depending on the shader, a 90° angle might always return black or start giving funky results, while when the angle is less than 90° it is just perfectly fine. Also as @Rahul has said, if you would calculate a reflected ray, it would end up in the same direction as your original ray and with most shaders that reflection ray would contribute to 100% of the ray's colour and not be coloured, so it would give the exact same colour as if you just discarded the ray.</p>

<p>The thing that makes this basically personal preference, is the fact that it would practically not happen that a ray would hit the sphere perfectly tangent, in an average render engine (as Rahul has also said). When looking at a sphere from a certain point, there would be a single circle with an infinitely small thickness that could create the occurrence of the discriminant being 0.</p>

<p>In short, it basically does not matter a single bit if you discard those hits or not. </p>

CC BY-SA 4.0
2018-10-07T17:36:59.567Z
2018-10-07T17:36:59.567Z
bram0101
<p>To give context to the question, I am reading Peter Shirley's Ray Tracing in one weekend. In his code for sphere/ray intersection, when the quadratic formula returns only 1 solution, he discards it, which strikes me as odd. Is there any graphics theory that support it or is it just his personal preference?</p>

<p>Here is the link to the code I am talking about on github.
<a href="https://github.com/petershirley/raytracinginoneweekend/blob/master/sphere.h" rel="nofollow noreferrer">https://github.com/petershirley/raytracinginoneweekend/blob/master/sphere.h</a></p>

<raytracing>
why doesn't a ray hitting a sphere at only 1 point count as a hit in sphere/ray intersection?
Manh Nguyen
# why doesn't a ray hitting a sphere at only 1 point count as a hit in sphere/ray intersection?

(Asked by: username_0 on 2018-10-07)

To give context to the question, I am reading Peter Shirley's Ray Tracing in one weekend. In his code for sphere/ray intersection, when the quadratic formula returns only 1 solution, he discards it, which strikes me as odd. Is there any graphics theory that support it or is it just his personal preference?

Here is the link to the code I am talking about on github.
<https://github.com/petershirley/raytracinginoneweekend/blob/master/sphere.h>

**Tags:** raytracing


---

## 1 answers

### Answer by username_1 on 2018-10-07. Score: 6 | Accepted answer

It is mainly personal preference, but it does have some logic behind it which would make it a better option. It should not have any big impact on your final image, though.

When the discriminant is 0, then that means that there is only one solution. For a sphere, when there is only one solution, that means that the ray is tangent to the sphere. When a line or ray is tangent to a sphere, that means that there is a 90° angle between the line/ray and the normal of the sphere at the intersection. When comparing that situation to ray-triangle and ray-plane intersections, they always ignore the hit when it has an angle of 90° with the normal. This is because the ray would then not really be able to hit it, and in real life you cannot see an infinitely thin plane or triangle that is perfectly parallel to your viewing direction.

Discarding hits when the angle is 90° could also help with shading. Depending on the shader, a 90° angle might always return black or start giving funky results, while when the angle is less than 90° it is just perfectly fine. Also as @Rahul has said, if you would calculate a reflected ray, it would end up in the same direction as your original ray and with most shaders that reflection ray would contribute to 100% of the ray's colour and not be coloured, so it would give the exact same colour as if you just discarded the ray.

The thing that makes this basically personal preference, is the fact that it would practically not happen that a ray would hit the sphere perfectly tangent, in an average render engine (as Rahul has also said). When looking at a sphere from a certain point, there would be a single circle with an infinitely small thickness that could create the occurrence of the discriminant being 0.

In short, it basically does not matter a single bit if you discard those hits or not.


---

