Vixen
02b45cc4
csharp
public sealed class IrradianceIndirection

Which brick, if any, covers each cell of a world-space grid — and how big it is.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The whole lookup is: divide, floor, fetch, divide again. A world position becomes a cell, the cell becomes a brick and that brick's size, and the position within the brick follows from the size. Two fetches and integer arithmetic, and on a GPU it is a point-sampled index texture followed by a linearly-filtered pool fetch.

This is the shape doc 06's tetrahedral light probes failed at, chosen because it cannot fail the same way. A Delaunay tetrahedralisation needs robust predicates, degenerates on co-planar probes, and answers a "which cell am I in" question with a walk. Every one of those is a way to be wrong that a grid does not have. Doc 19 § 3 makes that explicit: no Delaunay, no predicates, no repeat.

The grid is at the finest resolution, and a coarse brick repeats itself. A brick of size four writes its slot into all sixty-four cells it covers, so no lookup ever searches or climbs a tree — the cost of a coarse brick is memory in this grid, which is one integer pair a cell, and the saving is sixty-four probes instead of four thousand. Epic's volumetric lightmap stores it exactly this way and for exactly this reason.

A cell here is a box, not a grid point — unlike MeshDistanceField, where samples sit on the lattice and the cell count is one less than the sample count. Both conventions are right for what they hold and mixing them up is an off-by-half-a-cell everywhere, so: CellSize divides by Resolution, and the probe lattice that lives inside a brick is the one with the grid-point convention.

Fields and properties (8)

  • public const int Empty

    What a cell holds when no brick covers it.

  • public BoundingBox Bounds

    The box the grid covers.

  • public Int3 Resolution

    How many cells along each axis, at the finest brick size.

  • public Vector3 CellSize

    How big one finest cell is, in world units.

  • public ReadOnlySpan<IrradianceCell> Cells

    Every cell, in the order a volume copy wants them.

  • public int Covered

    How many cells a brick covers.

  • public int BrickCount

    How many bricks there are, counting a coarse one once.

  • public IrradianceCell this[Int3 cell]

    What one cell holds.

Methods (12)

  • public IrradianceIndirection(BoundingBox bounds, Int3 resolution)

    Builds an indirection grid covering a box, with nothing in it.

  • public bool IsOrigin(Int3 cell)

    Whether a cell is the origin of the brick covering it.

  • public bool TryBrick(Int3 cell, out IrradianceBrick brick)

    The brick covering a cell, if one does.

  • public void Assign(IrradianceBrick brick)

    Writes a brick into every cell it covers.

  • public void Revoke(IrradianceBrick brick)

    Empties every cell a brick covers.

  • public bool Holds(Int3 cell)

    Whether a cell is inside the grid.

  • public BoundingBox CellBounds(Int3 cell)

    The box one finest cell covers.

  • public bool TryVoxel(Vector3 world, out Vector3 voxel)

    Where a world position sits in the grid, measured in finest cells.

  • public bool TryCell(Vector3 world, out Int3 cell)

    Which cell a world position falls in.

  • public bool TryLocate(Vector3 world, out IrradianceBrick brick, out Vector3 local)

    Which brick covers a world position, and where in it.

  • public void Clear()

    Gives every cell back to nothing.

  • public static Int3 Origin(Int3 cell, int size)

    The origin of the brick of a given size covering a cell.

Used by (11)

  • IrradianceBrickCursorVixen.Rendering.IrradianceFields
  • IrradianceCellVixen.Rendering.IrradianceFields
  • IrradianceCoarseningTestsVixen.Rendering.IrradianceFields.Tests
  • IrradianceFieldVixen.Rendering.IrradianceFields
  • IrradianceFieldTestsVixen.Rendering.IrradianceFields.Tests
  • IrradianceFieldTextureVixen.Rendering
  • IrradianceFieldTextureTestsVixen.Rendering.Tests
  • IrradianceIndirectionTestsVixen.Rendering.IrradianceFields.Tests
  • IrradianceRefinementPolicyVixen.Rendering.IrradianceFields
  • LeakTestsVixen.Rendering.IrradianceFields.Tests
  • SamplingConventionTestsVixen.Rendering.IrradianceFields.Tests