Intel® Embree Ray Tracing Kernels
Discussion forum on the open source ray tracing kernels for fast photo-realistic rendering on Intel® CPU(s)
285 Discussions

User defined geometry bouding box overlapping

Jianbo_Q_
Beginner
447 Views

Hello, 

      I meet a problem when defining the user defined geometry.  I simply defined a box, i.e. its bouding box is the same as the box itself.

I implemented the intersection function as following:

The problem is when I put two boxes up and down with one common face, i.e. they are aligned perfectly.

For example, the center of the two boxes are: (0,0,0), (0, 10,0). while the edge length of them is 10. 

When I shoot a ray from top: org (0, 100, 0), dir (0, -1, 0). The 'cellIntersectFunc' function will be called two times:

intersect 0
intersect 0
p: (0, 5, 0)
p1: (0, 5, 0)

The two intersected points (tnear and tfar) is the same, which is the common edge of the two boxes.

If I seperate them slighly. (0,0,0), (0, 10.001,0), The results is correct:

intersect 0
p: (0, 15.001, 0)
p1: (0, 5.001, 0)

Does anyone know what's wrong with this problem. I don't want any gaps between boxes, because some

rays may just go through this gaps and then produce errors.

 

Thank you!

 

void cellIntersectFunc(void* cell_i, RTCRay& ray, size_t item) {
    cout << "intersect " << item<< endl;

    const Cell* cells = (const Cell*)cell_i;

    const Cell& cell = cells[item];

    Vec3fa dRcp = 1/ray.dir;
    Vec3fa upper_right = cell.left_bottom + Vec3fa(cell.xzExtent, cell.yExtent, cell.xzExtent);
    for (int i = 0; i < 3; i++) {
        const float origin = ray.org;
        const float minVal = cell.left_bottom, maxVal = upper_right;
        if (ray.dir == 0) {//The ray is parallel to the planes.
            if (origin < minVal || origin > maxVal) {
                return;
            }
        }
        else {
            float t1 = (minVal - origin) * dRcp;
            float t2 = (maxVal - origin) * dRcp;
            bool flip = t1 > t2;
            if (flip)
                swap(t1, t2);
            
            ray.tnear = std::max(t1, ray.tnear);
            ray.tfar = std::min(t2,  ray.tfar);
            if (!(ray.tnear <= ray.tfar))
                return;
        }
    }
    ray.geomID = cell.geomID;
    ray.primID = (unsigned int)item;
    return;
}

0 Kudos
1 Reply
BenthinC_Intel
Employee
447 Views

That the intersection callback is called twice for the same object is very strange. Could you send us a more complete reproducer (including geometry setup) to embree_support@intel.com.

Thanks.

0 Kudos
Reply