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

Fitler function for User Defined Geometry

Jianbo_Q_
Beginner
702 Views

Hello everyone,

   I meet a problem when setting filter function for a user defined geometry. I searched on the internet and it says I should invoke filter function by myself in the intersect function (https://software.intel.com/en-us/forums/embree-photo-realistic-ray-tracing-kernels/topic/707268). What I want to do is just to collect all the intersected points along a ray. 

   I don't how this goal is achieved, Is my code correct? Can anybody help me, thank you!

void cellIntersectFunc(void* cell_i, RTCRay& ray, size_t item) {
    cout << "intersect" << 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);
//    int nearAxis = -1, farAxis = -1;
    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);
            if (t1 > ray.tnear) {
                ray.tfar = t1;
            }
            /*if (t2 < ray.tfar) {
                ray.tfar = t2;
            }*/
        }
    }
    if (!(ray.tnear <= ray.tfar))
        return;
    ray.geomID = cell.geomID;
    ray.primID = (unsigned int)item;
    intersectionFilter(cell_i, ray);
    return;
}

 

void intersectionFilter(void* ptr, RTCRay& ray_i)
{
    RTCRay2& ray = (RTCRay2&)ray_i;
    ray.hit_geomIDs[ray.lastHit] = ray.geomID;
    ray.lastHit++;
    ray.geomID = RTC_INVALID_GEOMETRY_ID;
    ray.primID = RTC_INVALID_GEOMETRY_ID;
    cout << "hello" << endl;
}

0 Kudos
4 Replies
SvenW_Intel
Moderator
702 Views

Code looks good to me. What is the problem with that code?

0 Kudos
Jianbo_Q_
Beginner
702 Views

At the first intersection, it works. but I have set geomID to invalid in my filter function. But the ray does not go further. There is no second intersection. But I am sure there should be. So I am not very sure whether there are some problems about how to invoke this function.

0 Kudos
SvenW_Intel
Moderator
702 Views

Ok I found the issue. You should not update any information in the ray if you reject the hit. Just do not change the ray at all and your code will work.

0 Kudos
Jianbo_Q_
Beginner
702 Views

Thank you very much. I tested your comments, it works. Another solution is to set  ray.tfar = inf in the filter function.

0 Kudos
Reply