Fitler function for User Defined Geometry

Fitler function for User Defined Geometry

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 ( 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 =[i];
        const float minVal = cell.left_bottom[i], maxVal = upper_right[i];
        if (ray.dir[i] == 0) {//The ray is parallel to the planes.
            if (origin < minVal || origin > maxVal) {
        else {
            float t1 = (minVal - origin) * dRcp[i];
            float t2 = (maxVal - origin) * dRcp[i];
            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))
    ray.geomID = cell.geomID;
    ray.primID = (unsigned int)item;
    intersectionFilter(cell_i, ray);


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

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

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.

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.

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today