Skip to content

Vertex Formats and GPU Instancing

GPU instancing 2.2.0

GPU-instanced particles previewed in the maximized editor

The instance project exercises the particle instance format while the full editor keeps Scene, Inspector, Resources, and Timeline visible.

Photon batches equal geometry/material state and draws many instances together. Base mesh vertices describe a quad, model, or trail segment; per-instance records supply transform, color, UV, light, and optional data.

Render Variants

DefineGeometryBase instance content
PARTICLE_INSTANCEbillboard/tile quadposition, rotation, size, color, UV/light
PARTICLE_MODEL_INSTANCEmodel meshtransform, color, UV/light with model attributes
TRAIL_INSTANCEflat/tube trail segmentendpoints, width/color/UV per point
BEAM_INSTANCEray/beam segmentstart/end, width/color/UV
ARATRAIL_INSTANCEphysics trail segmentadjacent point data and interpolation

Non-instanced CPU paths still expose Particle Data, but Additional and Custom Data graph accessors return zero there. Enable GPU instancing when a graph relies on those streams.

Two Data Layouts

The legacy attribute layout contains only inspector-enabled channels, in registry order. Turning a channel on can move later attribute locations. A hand-written shader and emitter configuration must therefore agree exactly.

Shader Graph uses a fixed vec4 slot layout per emitter kind, indexed by gl_InstanceID. The compiler records which channels are read and uploads the effective mask. One compiled graph can serve emitters with different inspector toggles.

Batching Limits

A draw batch breaks when geometry, material program, texture/sampler state, render layer, or required layout differs. Multi-material models require separate passes. Large custom data and many transparent layers also increase upload and sorting cost even when instance count is low.

Use the profiler and render statistics rather than assuming instancing is always faster. For a handful of particles, setup cost may dominate; for hundreds of identical quads/models, it normally wins.

Shader Author Checklist

  • Shader Graph uses Photon accessors. The legacy Custom Shader Material path must declare attribute locations matching the emitter toggles.
  • Do not index PhotonData with vertex id; it is indexed by gl_InstanceID.
  • Treat unsupported channels as zero and provide a sensible fallback.
  • Keep transparent sort/layer requirements consistent so emitters can batch.
  • Test tile, model, trail, and beam separately; their base inputs are not interchangeable.

See Additional GPU Data for the Custom Data location formula and complete shader code.

Released under the MIT License.