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

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

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

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.

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 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.

  • 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 Jul 24 at 8:37
  • 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 Jul 24 at 8:41

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.