referenceBuffer
A node for efficiently passing a data array (e.g., colors, vectors) from JavaScript to the shader as a Uniform Buffer, supporting dynamic access via an index within the shader.
Core Advantages
Its core advantage is using Uniform Buffer Objects (UBOs) for efficient bulk data transfer, significantly reducing communication overhead, and creating a true, indexable array in the shader, which provides the foundation for advanced algorithms like looping through multiple lights.
Common Uses
Storing and processing position and color information for multiple lights
Providing unique attributes for large-scale instanced rendering
Serving as a switchable color palette or Look-Up Table (LUT)
How to adjust
Adjust by directly modifying the source data array it references in JavaScript. For example, changing a single color in the array precisely alters the corresponding instance's appearance, while replacing the entire array property with a new one achieves a global theme or data switch (e.g., swapping the entire color palette).
Code Examples
1
2// Reference a color array property named 'colors'
3const colorBuffer = referenceBuffer( 'colors', 'color', INSTANCE_COUNT, material );
4
5// In the shader, use the instance ID to index a color from the buffer
6material.colorNode = colorBuffer.element( instanceId );
7