Class TreeInstanceRenderer
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
-
objectTreeInstanceRenderer
Methods
SetEnabled(bool)
Enable/disable tree rendering
public void SetEnabled(bool enabled)
Parameters
enabledbool
SetRenderBounds(Bounds)
Update rendering bounds if needed (e.g., camera moved far from map)
public void SetRenderBounds(Bounds bounds)
Parameters
boundsBounds
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
matrixBufferComputeBufferTree transform matrices
countBufferComputeBufferTree count (for indirect args)
maxTreesintMaximum tree count (buffer capacity)
mapWidthfloatMap width for bounds calculation
mapHeightfloatMap height for bounds calculation