Table of Contents

Class TreeInstanceRenderer

Namespace
Map.Rendering
Assembly
MapAssembly.dll

GPU-driven tree rendering using DrawMeshInstancedIndirect.

Architecture:

  • Renders trees from GPU buffer (no CPU array transfer)
  • Single draw call for all trees (millions possible)
  • Receives transform matrices from TreeInstanceGenerator
  • Fully GPU-driven (instance count read from buffer)

Performance:

  • Zero CPU overhead per frame
  • GPU reads instance count and matrices directly
  • Frustum culling handled by GPU
  • Supports shadows and LOD

Usage:

  • Call SetTreeData() to bind matrix buffer
  • Update() automatically renders each frame
public class TreeInstanceRenderer : MonoBehaviour
Inheritance
object
TreeInstanceRenderer

Methods

SetEnabled(bool)

Enable/disable tree rendering

public void SetEnabled(bool enabled)

Parameters

enabled bool

SetRenderBounds(Bounds)

Update rendering bounds if needed (e.g., camera moved far from map)

public void SetRenderBounds(Bounds bounds)

Parameters

bounds Bounds

SetTreeData(ComputeBuffer, ComputeBuffer, int, float, float)

Set tree rendering data from generator. Must be called after TreeInstanceGenerator.GenerateTrees()

public void SetTreeData(ComputeBuffer matrixBuffer, ComputeBuffer countBuffer, int maxTrees, float mapWidth, float mapHeight)

Parameters

matrixBuffer ComputeBuffer

Tree transform matrices

countBuffer ComputeBuffer

Tree count (for indirect args)

maxTrees int

Maximum tree count (buffer capacity)

mapWidth float

Map width for bounds calculation

mapHeight float

Map height for bounds calculation