Josh Klint said:
But I guess I can just sort of walk through the grid and round off the current floating point coordinate to the nearest integer coord. I think that is basically what your technique above is doing.
The motivation of the DDA method is to precalculate intervals for plane intersections for each dimension, which then remain constant. After that, we can find all intersections in order just by doing additions, and - if we need multiple levels of a hierarchy - multiplications (or bit shifts if using integer math).
So you get rid of ‘expensive’ divisions, which my ARM based mobile for example could not even do in hardware. Not sure how's the win on modern hardware in a situation where memory is the bottleneck, but should be still something.
The same idea is used for example to implement the standard slab test to intersect a ray vs. an AABB:
void DistanceRayAABBFrontAndBackface (float &ffd, float& bfd, const vec& rayOrigin, const vec& rayInvDirection, const vec& aaBoxMin, const vec& aaBoxMax) const
{
vec t0 = vec(aaBoxMin - rayOrigin).MulPerElem (rayInvDirection); // those vector class functions boil down to a single SIMD instruction
vec t1 = vec(aaBoxMax - rayOrigin).MulPerElem (rayInvDirection);
vec tMin = t0.MinPerElem (t1);
vec tMax = t0.MaxPerElem (t1);
ffd = tMin.MaxElem(); // front face distance (behind origin if inside box)
bfd = tMax.MinElem(); // back face distance
}
// we do division just once to set up the ray for traversal
vec rID (1.f / givenRayUnitDirection.x, 1.f / givenRayUnitDirection.y, 1.f / givenRayUnitDirection.z);
// traversal...
DistanceRayFrontAndBackface (ffd, bfd, givenRayOrigin, rID, aaBoxMin, aaBoxMax);
if ((ffd <= bfd) & (ffd >= 0.0f) & (ffd <= rayLength))
{
// box was hit
}
You see there is o need for a dot product, because our planes are axis aligned. (I've later found the exact same code in Newton Physics and other sources, seems everybody does it the same way.)
That's nice for BVH where boxes have arbitrary positions. But for Octree the box positions are also snapped to reguler intervals, so DDA is opportunity to optimize further.
Josh Klint said:
So tired…. XD
What do you do with this? Now when we have sooo awesome RT HW acceleration? :D