instancedArray
A node for creating an instance-bound, GPU-readable and writable data array, which is key for implementing GPU-driven dynamic systems like particle simulations and flocking behavior.
Core Advantages
Common Uses
High-performance GPU particle systems (updating particle state on the GPU)
Flocking and boids simulations (e.g., bird or fish schools)
GPU-driven cellular automata (e.g., Conway's Game of Life)
Interactive vegetation (e.g., grass bending and recovering)
How to adjust
Adjustments are made by changing the 'write logic' for this array in the shader. For example, in a particle system, changing the gravity vector written back from straight down to one pointing to a fixed point can transform a fountain effect into a pulsating explosion pulled back to a center, turning the renderer into a dynamic simulator.
Code Examples
1
2// Read the current particle's state
3const current = particleData.element( instanceIndex );
4
5// Calculate new position and velocity
6const newPos = current.position.add( current.velocity );
7const newVel = current.velocity.add( gravity ); // gravity is a vec3
8
9// Write the new state back to the array for the next frame
10current.assign( { position: newPos, velocity: newVel } );
11