BVH frustum culling over instances

Re-wires the BVH acceleration structure on top of the new instanced
renderer.  Per model, build a BVH over per-instance world AABBs at
finalize (and on sidecar apply).  Each frame, traverse the BVH against
the camera frustum to produce a visible-instance index list, bucket by
mesh_id, and upload to a per-model SSBO at binding=1.  The main and
pick vertex shaders do a double-indirection
`instances[visible[u_offset + gl_InstanceID]]` so draws only touch
instances that passed the frustum test.

Models with fewer than BVH_MIN_OBJECTS instances skip the BVH build
and fall back to a linear per-instance frustum test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-04-12 20:23:50 +10:00
parent ababb49ae7
commit 1f17d73f3e
4 changed files with 204 additions and 12 deletions
+6
View File
@@ -119,6 +119,12 @@ ModelBvh buildModelBvh(const std::vector<BvhItem>& items,
} // anonymous namespace
ModelBvh buildModelBvhOne(const std::vector<BvhItem>& items, uint32_t model_id) {
std::vector<uint32_t> idxs(items.size());
for (uint32_t i = 0; i < items.size(); ++i) idxs[i] = i;
return buildModelBvh(items, idxs, model_id);
}
std::shared_ptr<BvhSet> buildBvhSet(const std::vector<BvhItem>& items) {
auto bvh_set = std::make_shared<BvhSet>();