<blockquote>
  <p>I want to know if there is a better way to check for self intersection, other than checking the original position?</p>
</blockquote>

<p>Since cubes are convex solids, a self-intersection check shouldn't introduce artefacts in your case, while it would in a more general ray-tracer (see <a href="https://computergraphics.stackexchange.com/a/4987/2041">my answer about the shadow terminator problem</a> for more about that). In general, it's a good idea for your ray object to have a reference of some kind to the object it came from, as well as the kind of ray it is (primary, shadow, reflection, refraction). Normally the reference should be to the exact polygon, not just the whole object; in your case, it should be the particular cube. You could identify it by the co-ordinates of the cube, if you're using spatial hashing to store your voxel grid.</p>

<p>Then, in your intersection test, if your ray is a shadow ray, you should check whether the origin cube is the same as the cube being intersected, and discard that intersection if so.</p>

CC BY-SA 4.0
2018-07-24T08:37:03.713Z
I'm not sure this is totally robust. What happen if we have 2 adjacent cubes forming a rectangle and our ray slightly penetrates one cube near the shared boundary of both these cubes, while we ignore the cube we penetrate we can still hit the neighbour cubes side on the way out to the light. For this case (cubes) it may be easier to determine which cube face the initial ray enters and only consider the voxels on the opposite side of that plane altogether.
PaulHK
CC BY-SA 4.0
2018-07-24T08:41:17.670Z
Yeah, I still think getting the offset right is best, especially if the non-voxel raytracer is spawning rays from the real geometry to be traced against the voxelisation. That's never going to be perfect.
Dan Hulme
CC BY-SA 4.0
2018-07-24T08:08:41.727Z
2018-07-24T08:08:41.727Z
Dan Hulme
<p>I am developping a voxel raytracer for global illumination.</p>
<p>I have been successful in multiple aspects but there is a problem I am not sure how to solve.</p>
<p>The model works as most other Voxelization based algorithms work. We use rasterization to store the scene in a 3D volumetric structure and then we raytrace inside of said 3D structure.</p>
<p>In the &quot;pure&quot; model (only voxels) I can generate prety decent shadows (ignore the circular artifacts):</p>
<p><a href="https://i.sstatic.net/b76Fa.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/b76Fa.jpg" alt="enter image description here" /></a></p>
<p>However when I try to create a combined scene (normal rendering for colors, voxels for shadows) I sometimes get self intersection based artifacts:</p>
<p><a href="https://i.sstatic.net/sIamK.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sIamK.jpg" alt="enter image description here" /></a></p>
<p>I can improve the image a bit by using an epsilon tolerance (considering that if we are too close to the original starting position we haven't collided with anything yet):</p>
<p><a href="https://i.sstatic.net/ngtYt.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ngtYt.jpg" alt="enter image description here" /></a></p>
<p>However doing this creates poor shadows by eliminating certain collissions (look at the archs for example, where the areas too close to the source should be darkened but are instead lightened).</p>
<p>I want to know if there is a better way to check for self intersection, other than checking the original position?</p>
<p>i.e I want to be able to get as close to the shadows in the first image as possible.</p>

CC BY-SA 4.0
2018-07-24T08:02:59.817Z
I don't think your question is quite a duplicate, but my answer to [Ray Tracing Shadows: The Shadow Line Artifact](https://computergraphics.stackexchange.com/questions/4986/ray-tracing-shadows-the-shadow-line-artifact) should help you.
Dan Hulme
<opengl><raytracing><antialiasing><ray>
Self intersection artifacts in 3D image raytracing
Makogan
# Self intersection artifacts in 3D image raytracing

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

I am developping a voxel raytracer for global illumination.

I have been successful in multiple aspects but there is a problem I am not sure how to solve.

The model works as most other Voxelization based algorithms work. We use rasterization to store the scene in a 3D volumetric structure and then we raytrace inside of said 3D structure.

In the "pure" model (only voxels) I can generate prety decent shadows (ignore the circular artifacts):

[![enter image description here](https://i.sstatic.net/b76Fa.jpg)](https://i.sstatic.net/b76Fa.jpg)

However when I try to create a combined scene (normal rendering for colors, voxels for shadows) I sometimes get self intersection based artifacts:

[![enter image description here](https://i.sstatic.net/sIamK.jpg)](https://i.sstatic.net/sIamK.jpg)

I can improve the image a bit by using an epsilon tolerance (considering that if we are too close to the original starting position we haven't collided with anything yet):

[![enter image description here](https://i.sstatic.net/ngtYt.jpg)](https://i.sstatic.net/ngtYt.jpg)

However doing this creates poor shadows by eliminating certain collissions (look at the archs for example, where the areas too close to the source should be darkened but are instead lightened).

I want to know if there is a better way to check for self intersection, other than checking the original position?

i.e I want to be able to get as close to the shadows in the first image as possible.

**Tags:** opengl, raytracing, antialiasing, ray

> **Comments:**
> **username_1**: I don't think your question is quite a duplicate, but my answer to [Ray Tracing Shadows: The Shadow Line Artifact](https://computergraphics.stackexchange.com/questions/4986/ray-tracing-shadows-the-shadow-line-artifact) should help you.  

---

## 1 answers

### Answer by username_1 on 2018-07-24. Score: 1 | Accepted answer

> I want to know if there is a better way to check for self intersection, other than checking the original position?

Since cubes are convex solids, a self-intersection check shouldn't introduce artefacts in your case, while it would in a more general ray-tracer (see [my answer about the shadow terminator problem](https://computergraphics.stackexchange.com/a/4987/2041) for more about that). In general, it's a good idea for your ray object to have a reference of some kind to the object it came from, as well as the kind of ray it is (primary, shadow, reflection, refraction). Normally the reference should be to the exact polygon, not just the whole object; in your case, it should be the particular cube. You could identify it by the co-ordinates of the cube, if you're using spatial hashing to store your voxel grid.

Then, in your intersection test, if your ray is a shadow ray, you should check whether the origin cube is the same as the cube being intersected, and discard that intersection if so.

> **Comments:**
> **username_2**: I'm not sure this is totally robust. What happen if we have 2 adjacent cubes forming a rectangle and our ray slightly penetrates one cube near the shared boundary of both these cubes, while we ignore the cube we penetrate we can still hit the neighbour cubes side on the way out to the light. For this case (cubes) it may be easier to determine which cube face the initial ray enters and only consider the voxels on the opposite side of that plane altogether.  
> **username_1**: Yeah, I still think getting the offset right is best, especially if the non-voxel raytracer is spawning rays from the real geometry to be traced against the voxelisation. That's never going to be perfect.  

---

