Vixen
02b45cc4
csharp
public struct InstanceParameters

The four per-instance numbers that are not the transform.

Read the guide page for this →

Remarks

One vector, and the four things in it were chosen because a forest needs all four and nothing else. A field of instances that share a mesh, a material and a transform layout still has to not look stamped, and the ways it stops looking stamped are: tint each copy a little differently, start each copy's wind at a different phase, grow them to different sizes, and fade the ones crossing a level boundary. See [docs/plan/31 § B3].

A parallel buffer rather than an interleaved field — and parallel is meant literally. An instance's parameters sit at the same index as its transform, so a shader reaches them with the gl_InstanceIndex it already has and no second offset travels in the draw. Keeping that true is why SetInstances writes Neutral for a batch that supplied none rather than writing nothing: two buffers that could drift apart would need a per-draw delta to reconcile them, and the one frame they drifted would draw every forest with another tree's wind.

That costs sixteen bytes per instance whether the instance uses them or not — 25 % on top of the transform's sixty-four. Against this feature's actual callers, which are trees and props in the tens of thousands rather than the grass in [docs/plan/31 § T6] that scatters into a buffer of its own, it is under a megabyte.

The half of the separation that does pay is binding: a pass wanting only positions binds one buffer, so a shadow cascade and a depth prepass never read this at all.

⚠ A default-constructed value is not neutral, and that is deliberate. Neutral is Neutral — fade 1, scale 1 — because a zero fade is invisible and a zero scale is a point. A batch that forgot to fill this draws nothing rather than drawing something subtly wrong, which is the failure that gets noticed. This is [docs/memory zero-value traps] as a design rule rather than a lesson.

Fields and properties (6)

  • public float Tint

    A per-instance variation the material maps how it likes. Conventionally 0…1.

  • public float WindPhase

    A phase offset in radians, added to whatever drives the instance's motion.

  • public float Scale

    A per-instance scale, multiplying the transform's own. 1 is unchanged.

  • public float Fade

    The LOD cross-fade weight, 0…1. 1 is fully present.

  • public static InstanceParameters Neutral

    The value that changes nothing: no tint, no phase, full size, fully present.

  • public static int SizeInBytes

    How many bytes one of these is.

Used by (11)

  • FoliageCullParityTestsVixen.Rendering.Terrain.Tests
  • FoliageCullPassVixen.Rendering.Terrain
  • FoliageRendererVixen.Rendering.Terrain
  • FoliageRendererTestsVixen.Rendering.Terrain.Tests
  • GrassDispatchTestsVixen.Rendering.Terrain.Tests
  • GrassRendererVixen.Rendering.Terrain
  • GrassRendererTestsVixen.Rendering.Terrain.Tests
  • InstanceCullerVixen.Rendering
  • InstanceCullingTestsVixen.Rendering.Tests
  • InstancingRenderFeatureVixen.Rendering
  • SkinningAndInstancingTestsVixen.Rendering.Tests