Culling (visibility helpers)
Mibo.Elmish.Culling is a helper module that keeps visibility math separate from your renderer and your spatial partitioning.
It operates on geometric primitives such as:
- Bounding frustums (computed from camera matrices)
BoundingSphere/BoundingBox(defined inMibo.Elmish/System.Numerics)- 2D
Rectangleoverlap
3D: frustum culling
Create a Frustum from the camera's View * Projection matrix and test geometry:
// Extract frustum from camera matrices
let frustum = Frustum(Matrix4x4.Multiply(cam.View, cam.Projection))
if Culling.isVisible frustum entitySphere then
// submit draw commands
()
Or for axis-aligned bounding boxes:
if Culling.isGenericVisible frustum nodeBounds then
()
2D: rectangle overlap
Use Camera2D.viewportBounds with Culling.isVisible2D:
let viewBounds = Camera2D.viewportBounds camera viewportWidth viewportHeight
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?"
See also: Camera and Rendering overview.
val frustum: obj
val viewBounds: obj
Mibo.Raylib