attributeArray
A node for creating and accessing a Storage Buffer, allowing for efficient reading and writing of large-scale, arbitrarily structured, general-purpose datasets in any shader stage (vertex, fragment, compute).
Core Advantages
Its core advantage lies in its massive data capacity and writability, making it a cornerstone of GPGPU. It abstracts complex low-level SSBO setup into a simple function, enabling developers to easily handle thousands of data points for complex simulations and interactions impossible with traditional uniforms.
Common Uses
GPU particle systems (storing and updating particle states)
Large-scale instanced rendering (providing unique attributes per instance)
Skinned animation (as a lookup table for bone matrices)
Physics simulations like cloth and fluids (as the core state container)
How to adjust
By modifying its `.buffer.array` content in JavaScript and setting `.buffer.needsUpdate = true`, you can update massive amounts of data from the CPU to the GPU in real-time. This enables large-scale interactive effects, such as listening to the mouse position to dynamically change the color and scale of thousands of instances, creating a live, interactive ripple.
Code Examples
1
2// Create a structured buffer for 10,000 particles
3const particleBuffer = attributeArray( 10000, new StructType( {
4 position: 'vec3',
5 velocity: 'vec3'
6} ) );
7
8// In a shader, access a specific particle's position using an index
9const particlePosition = particleBuffer.element( particleIndex ).position;
10