Table of Contents

Class InstancedBillboardRenderer

Namespace
Map.Rendering
Assembly
MapAssembly.dll

Base class for GPU instanced billboard rendering. Renders thousands of billboarded sprites in a single draw call using Graphics.DrawMeshInstanced.

Architecture:

  • Maintains matrix lists for world positions
  • Uses MaterialPropertyBlock for per-instance data
  • Subclasses implement data source integration (event systems, polling, etc.)
  • Dirty flag system for efficient updates

Performance:

  • Single draw call for all instances
  • Billboard rotation in vertex shader (GPU-side)
  • Event-driven updates (no Update loop overhead)

Usage:

  • Inherit and implement abstract methods
  • Call MarkDirty() when data changes
  • RebuildInstances() is called automatically on dirty flag
public abstract class InstancedBillboardRenderer : MonoBehaviour
Inheritance
object
InstancedBillboardRenderer

Fields

autoCreateQuad

[SerializeField]
protected bool autoCreateQuad

Field Value

bool

initialCapacity

[Header("Configuration")]
[SerializeField]
protected int initialCapacity

Field Value

int

isDirty

protected bool isDirty

Field Value

bool

material

[SerializeField]
protected Material material

Field Value

Material

matrices

protected List<Matrix4x4> matrices

Field Value

List<Matrix4x4>

propertyBlock

protected MaterialPropertyBlock propertyBlock

Field Value

MaterialPropertyBlock

quadMesh

[Header("Rendering Setup")]
[SerializeField]
protected Mesh quadMesh

Field Value

Mesh

Methods

Awake()

protected virtual void Awake()

CreateQuadMesh()

Create a simple quad mesh for billboarded sprites. Centered at origin, 1x1 unit size.

protected virtual Mesh CreateQuadMesh()

Returns

Mesh

ForceRebuild()

Force immediate rebuild of all instances. Normally called automatically via dirty flag.

public void ForceRebuild()

LateUpdate()

protected virtual void LateUpdate()

MarkDirty()

Mark renderer as dirty to trigger rebuild on next LateUpdate. Call this when data changes (events, state changes, etc.).

protected void MarkDirty()

OnDestroy()

protected virtual void OnDestroy()

RebuildInstances()

Rebuild all instance matrices and properties. Called automatically when dirty flag is set.

Implementation should:

  1. Clear matrices list
  2. Query data source for current state
  3. Build Matrix4x4 for each instance
  4. Set per-instance properties in propertyBlock
protected abstract void RebuildInstances()