Culling (visibility helpers)
Mibo.Elmish.Culling is a tiny helper module that keeps visibility math separate from your renderer and your spatial partitioning.
It operates on MonoGame primitives:
BoundingFrustumBoundingSphereBoundingBoxRectangle
3D: frustum culling
Culling works with any BoundingFrustum - from either camera:
Elmish Camera3D:
let frustum = Camera3D.boundingFrustum camera
Rendering3D Camera:
let frustum = Camera.boundingFrustum camera
Both return same BoundingFrustum type, so culling works the same:
if Culling.isVisible frustum entitySphere then
// submit draw commands
()
Or for AABBs:
if Culling.isGenericVisible frustum nodeBounds then
()
2D: rectangle overlap
Uses Camera2D.viewportBounds with generic rectangle overlap test:
let viewBounds = Camera2D.viewportBounds camera viewport
if Culling.isVisible2D viewBounds spriteBounds then
()
What this is not
This module doesn’t try to be your spatial index.
- If you have many objects: use a grid / quadtree / BVH / octree.
- Use these helpers at the edge: “is this node/object worth considering for rendering?”
val frustum: obj
val viewBounds: obj
Mibo