Vixen
02b45cc4
csharp
public sealed class FoliageRenderer

Turning a volume of instances into indirect draws: cells culled as objects, instances culled within them.

Read the guide page for this →

Remarks

[docs/plan/31 § D9], both stages. A foliage cell is what the instancing feature sees as one object — tight bounds, one mesh, a few thousand of them for a forest — and is culled by the existing frustum path. That is enough for trees and not enough for grass, because a 32 m cell of grass is fifty thousand instances and the far half of it is behind a hill. So a second pass over the surviving cells' instances tests each one, compacts the survivors and fills a DrawIndexedIndirect command.

The LOD decision is in that second pass, and it is a deliberate divergence from LodRenderFeature. That feature is right for its case — a LOD group is several render objects and it clears bits — and it cannot express "these four thousand trees in this cell are at level 1 and those six hundred are at level 2", because its level is per object and here it is per instance. So the pass bins each instance into its level's own indirect command and a cell draws three or four times instead of once.

⚠ This is the CPU half, and the compute shader is the other one. The compaction, the binning and the fade are InstanceCuller's, which was built in [§ B2] precisely so that both halves could be the same arithmetic — the device form claims slots with an atomic add and is therefore unordered, which a seam test sorts away rather than asserts through. What runs here is what a headless test and a machine with no compute queue use, and it is the reference the dispatch is checked against.

Fields and properties (8)

  • public IReadOnlyList<FoliageBatch> Batches

    What each surviving cell drew, in the order they were gathered.

  • public ReadOnlySpan<Matrix4x4> Transforms

    Every surviving instance's transform, compacted across every cell.

  • public ReadOnlySpan<InstanceParameters> Parameters

    And their parameters, at the same indices.

  • public int CellsConsidered

    How many cells were tested.

  • public int CellsDrawn

    How many survived the first stage.

  • public int InstancesConsidered

    How many instances those cells held.

  • public int InstancesDrawn

    And how many survived the second.

  • public int Draws

    How many indirect draws the frame issues.

Methods (1)

Used by (1)

  • FoliageRendererTestsVixen.Rendering.Terrain.Tests