Vixen
02b45cc4
csharp
public sealed class IrradianceField

An indirection grid, a pool of bricks, and the one way to read them.

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

Remarks

This is the storage and sampling layer of docs/plan/19 § 3, and its defining property is that it does not know what filled it. A brick is a brick whether a compute shader traced rays into it this frame or an offline cube capture wrote it at build time. That is what lets doc 19 § 7 promise a phone and a desktop the same lighting model at different update rates: nothing above this branches on which filler ran.

Bricks come in sizes, and every one of them holds sixty-four probes. A brick of size eight covers five hundred and twelve times the volume of a brick of size one for the same memory, and its probes are eight times further apart. Refining near geometry — coarse where there is nothing to shade, fine where a wall is — is what makes the memory affordable and what makes a wall more than one probe thick, which is the only real defence against a leak.

Borders are maintained, not written. A filler fills the sixty-four probes a brick owns; SyncBorders fills the plane that stands in for its neighbour. The border is not data — it is a second copy of somebody else's data, which is why SetProbe refuses to address it.

There is no field-wide probe lattice, and there cannot be one. Two bricks of different sizes have probes at different spacings, so "the probe next door" is a question about world positions rather than about indices. Everything that walks probes — dilation, a filler — walks bricks and asks the field where a position lands.

Fields and properties (8)

  • public IrradianceIndirection Indirection

    Which brick covers each cell.

  • public IrradianceBrickPool Pool

    Where the bricks live.

  • public BoundingBox Bounds

    The box the field covers.

  • public int BrickCount

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

  • public IEnumerable<IrradianceBrick> Bricks

    Every brick, once each, in the order the indirection grid holds them.

  • public Vector3 FinestProbeSpacing

    How far apart two probes of the finest brick there could be are.

  • public float NormalBias

    How far off a surface a shading lookup moves, in probe spacings.

  • public float ViewBias

    How far toward the camera a shading lookup moves as well, in probe spacings.

Methods (21)

  • public IrradianceField(BoundingBox bounds, Int3 cells, IrradianceBrickPool? pool = null)

    Builds a field over a box, with an indirection grid and a pool for it.

  • public Vector3 ProbeSpacingOf(int size)

    How far apart two neighbouring probes of a brick of a given size are.

  • public bool TryAllocate(Int3 cell, int size, out IrradianceBrick brick)

    Gives a cell a brick of a given size, or answers with the one already covering it.

  • public int Allocate(BoundingBox region, int size = 1)

    Gives every empty cell overlapping a box a brick of a given size.

  • public int AllocateAll(int size = 1)

    Gives every empty cell of the field a brick of a given size.

  • public int Refine(BoundingBox region, int size = 1)

    Subdivides every brick overlapping a box until it is no coarser than a given size.

  • public int Split(Int3 cell)

    Replaces the brick covering a cell with eight of half its size.

  • public bool TryMerge(Int3 cell)

    Replaces an aligned group of equal-size bricks with one of twice the size.

  • public bool Release(Int3 cell)

    Takes a cell's brick away and gives the slot back.

  • public void Clear()

    Empties the field of every brick.

  • public BoundingBox BrickBounds(IrradianceBrick brick)

    The box a brick covers.

  • public Vector3 ProbePosition(IrradianceBrick brick, int x, int y, int z)

    Where one probe of one brick is, in world space.

  • public void SetProbe(IrradianceBrick brick, int x, int y, int z, IrradianceProbe probe)

    Writes one of the sixty-four probes a brick owns.

  • public IrradianceProbe GetProbe(IrradianceBrick brick, int x, int y, int z)

    Reads one texel of a brick, border planes included.

  • public void SyncBorders()

    Fills every brick's border planes from whatever is beyond them.

  • public int Dilate(int passes = 1)

    Replaces probes nothing could fill with what their neighbours saw.

  • public bool TrySample(Vector3 world, out IrradianceProbe probe)

    The probe a field holds at a world position, or nothing where no brick does.

  • public bool TrySample(Vector3 world, Vector3 normal, out IrradianceProbe probe)

    The probe a surface sees, biased off the surface it stands on.

  • public bool TrySample(Vector3 world, Vector3 normal, Vector3 view, out IrradianceProbe probe)

    The probe a surface sees, biased off the surface and toward the eye.

  • public Vector3 Irradiance(Vector3 world, Vector3 normal)

    The diffuse lighting a surface at a position receives, divided by π.

  • public Vector3 Irradiance(Vector3 world, Vector3 normal, Vector3 view)

    The same, for a caller that knows where the camera is.

Used by (33)

  • ArenaThirdPersonShooter
  • CapturedIrradianceFillerVixen.Rendering
  • CapturedIrradianceFillerTestsVixen.Rendering.Tests
  • CompositorAssetTestsVixen.Rendering.Tests
  • CompositorBuilderVixen.Rendering
  • IndirectDiffuseImageTestsVixen.Graphics.Golden.Tests
  • IrradianceBounceDeviceTestsVixen.Graphics.Golden.Tests
  • IrradianceBrickCursorVixen.Rendering.IrradianceFields
  • IrradianceCaptureDeviceTestsVixen.Graphics.Golden.Tests
  • IrradianceCoarseningTestsVixen.Rendering.IrradianceFields.Tests
  • IrradianceConvergenceTestsVixen.Rendering.IrradianceFields.Tests
  • IrradianceFieldFillVixen.Rendering
  • IrradianceFieldRendererVixen.Rendering
  • IrradianceFieldRepairVixen.Rendering
  • IrradianceFieldTestsVixen.Rendering.IrradianceFields.Tests
  • IrradianceFieldTextureVixen.Rendering
  • IrradianceFieldTextureTestsVixen.Rendering.Tests
  • IrradianceFillDeviceTestsVixen.Graphics.Golden.Tests
  • IrradianceRefinementPolicyVixen.Rendering.IrradianceFields
  • IrradianceRefinementPolicyTestsVixen.Rendering.IrradianceFields.Tests
  • IrradianceRefinementTestsVixen.Rendering.Tests
  • IrradianceRepairDeviceTestsVixen.Graphics.Golden.Tests
  • IrradianceShadingDeviceTestsVixen.Graphics.Golden.Tests
  • LeakTestsVixen.Rendering.IrradianceFields.Tests
  • ReflectionTraceDeviceTestsVixen.Graphics.Golden.Tests
  • SamplingConventionTestsVixen.Rendering.IrradianceFields.Tests
  • ScreenProbeTraceDeviceTestsVixen.Graphics.Golden.Tests
  • TracedIrradianceFillerVixen.Rendering.IrradianceFields
  • TracedIrradianceFillerTestsVixen.Rendering.IrradianceFields.Tests
  • TracedReflectionTestsVixen.Rendering.Reflections.Tests
  • TracedReflectionsVixen.Rendering.Reflections
  • TracedScreenProbeGatherVixen.Rendering.ScreenProbes
  • TracedScreenProbeGatherTestsVixen.Rendering.ScreenProbes.Tests