Skip to main content

Module culling

Module culling 

Source
Expand description

Frustum culling of the PBR batches, on the CPU.

Each frame, the instances of every batch are tested against the CullingCamera and each shadow cascade. Their visible instances are written to their own region of the PbrSsboInstanceToTransform buffer, and the passes draw that range only.

§Levels

  1. Groups: a CullGroup gives world-space bounds to a set of meshes, e.g. a village or a character. A group outside of a view hides all its meshes from it, and a group fully inside shows them all, both without testing them one by one.
  2. Meshes: the remaining meshes (in a group crossing the view edge, or in no group) are tested with the bounds of their mesh, moved by their transform.

§Levels of detail

Each visible instance is drawn with the coarsest of the Mesh::lods whose error, projected on the screen of the culling camera from the nearest point of its bounds, stays under LodSettings::max_pixel_error. The shadow cascades use the level of the camera.

§Usage

// Spawn the group, and keep its bounds up to date
let group = commands.spawn(CullGroup(Aabb::new(Vec3::splat(-20.0), Vec3::splat(20.0)))).id();
// Every mesh of the village is in the group
commands.spawn((Transform::default(), CullGroupMember(group)));

Levels can be toggled with the CullingSettings and LodSettings resources, editable in the PBR/Culling editor window along with the CullingStats. The MeshDebugViews and the wireframe of LodSettings show the drawn levels and the size of their triangles on screen.

Structs§

CullGroup
World-space bounds of a group of meshes, culled together before being tested one by one. Empty bounds disable the group test, so its meshes are only tested one by one.
CullGroupMember
Puts the meshes of this entity and of its descendants in the CullGroup of the given entity. The nearest one among the mesh and its ancestors wins.
CullingSettings
CullingStats
CullingStatsShared
CullingStats of the last rendered frame, shared between the main and render worlds.
InCullGroup
Cull group of a mesh, resolved from the CullGroupMember of itself or of its ancestors.
LodSettings
Selection of the levels of detail of the meshes (see Mesh::lods).

Enums§

MeshDebugView
Coloring of the meshes, to check their levels of detail.

Constants§

CULL_VIEW_COUNT
Culling views: the camera, then each shadow cascade.