Original Post
I''m creating a raytracer and I wish to use octrees as a spatial coherence optimization. I get the basic idea - split the scene into an octree and each leaf holds a list of objects present in its space. Very well.
A ray is tracked through the octree by first finding the leaf which would hold the starting point of the ray. All objects in that leaf are tested with the ray. If there are no intersections, the ray must be tracked to the next leaf. This is done by finding the nearest intersection of the ray with the current leaf''s space (thus finding the point of entry to an adjacent leaf). To easily check which leaf the ray advances to, the found point is advanced a very small amount along the ray''s direction so that a point is found that would be entirely within an adjacent leaf''s space. All fine in principle, yes?
OK, what I can''t figure out is the following cases:
1. What if we advance out of a cube into an adjacent cube and our minute advancement strategy puts us all the way through the corner of one cube and into another? (I''m speaking of a case where the ray would pass out of a space VERY close to a vertex or edge - so close that the small advancement would pass through the corner of the adjacent space).
2. Even worse, what if our ray intersects the space at a vertex or edge, leaving us with little way to decide WHICH adjacent space to select for testing?