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
+4
View File
@@ -63,4 +63,8 @@ struct BvhSet {
// vector — callers providing a single model's items will see 0..N-1.
std::shared_ptr<BvhSet> buildBvhSet(const std::vector<BvhItem>& items);
// Build a single-model BVH over `items`. model_id is stored on the result
// for identification; item_indices will be 0..items.size()-1.
ModelBvh buildModelBvhOne(const std::vector<BvhItem>& items, uint32_t model_id);
#endif // BVHACCEL_H