Skip to content

Commit

Permalink
Merge pull request #40 from pshriwise/fix-primitive-cull
Browse files Browse the repository at this point in the history
Fix primitive culling
  • Loading branch information
pshriwise authored Dec 25, 2024
2 parents 17fac93 + f489e78 commit a8a00ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/triangle_intersect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ bool orientation_cull(const Direction& ray_dir, const Direction& normal, HitOrie
return false;
}

bool primitive_mask_cull(RTCDRayHit* rayhit) {
bool primitive_mask_cull(RTCDRayHit* rayhit, int primID) {
if (!rayhit->ray.exclude_primitives) return false;

RTCDRay& ray = rayhit->ray;
RTCDHit& hit = rayhit->hit;


// if the primitive mask is set, cull if the primitive is not in the mask
return std::find(ray.exclude_primitives->begin(), ray.exclude_primitives->end(), hit.primID) != ray.exclude_primitives->end();
return std::find(ray.exclude_primitives->begin(), ray.exclude_primitives->end(), primID) != ray.exclude_primitives->end();
}

void TriangleBoundsFunc(RTCBoundsFunctionArguments* args)
Expand Down Expand Up @@ -79,7 +80,7 @@ void TriangleIntersectionFunc(RTCIntersectFunctionNArguments* args) {

if (rayhit->ray.rf_type == RayFireType::VOLUME) {
if (orientation_cull(rayhit->ray.ddir, normal, rayhit->ray.orientation)) return;
if (primitive_mask_cull(rayhit)) return;
if (primitive_mask_cull(rayhit, primitive_ref.primitive_id)) return;
}

// if we've gotten through all of the filters, set the ray information
Expand Down
11 changes: 11 additions & 0 deletions tests/test_ray_fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,15 @@ TEST_CASE("Test Ray Fire Mesh Mock")
intersection = rti->ray_fire(volume_tree, origin, direction, 5.1);
REQUIRE(intersection.second != ID_NONE);
REQUIRE_THAT(intersection.first, Catch::Matchers::WithinAbs(5.0, 1e-6));

// Test excluding primitives, fire a ray from the origin and log the hit face
// By providing the hit face as an excluded primitive in a subsequent ray fire,
// there should be no intersection returned
std::vector<MeshID> exclude_primitives;
intersection = rti->ray_fire(volume_tree, origin, direction, INFTY, &exclude_primitives);
REQUIRE_THAT(intersection.first, Catch::Matchers::WithinAbs(5.0, 1e-6));
REQUIRE(exclude_primitives.size() == 1);

intersection = rti->ray_fire(volume_tree, origin, direction, INFTY, &exclude_primitives);
REQUIRE(intersection.second == ID_NONE);
}

0 comments on commit a8a00ac

Please sign in to comment.