nodeArray
Provides a mechanism to define and use arrays in TSL, which are compiled into GLSL uniform arrays, allowing for structured and scalable handling of data collections like multiple lights or color palettes.
Core Advantages
Its core advantage is support for dynamic indexing, allowing a computed integer from another node (like vertex ID or a noise result) to be used as an index to dynamically retrieve an element from the array. This is fundamental for complex algorithms and advanced visual effects.
Common Uses
Multi-light rendering (storing light positions and colors)
Color palette shading (as a color lookup table)
GPU instancing and particle systems (passing custom data per instance)
How to adjust
Adjusting the node logic used to generate the index completely changes how the data is mapped. For example, changing the index from being based on world Y-coordinate `floor(positionWorld.y * 4)` to the texture U-coordinate `floor(uv().x * 4)` would transform vertical color bands on an object into horizontal ones, without changing the palette data itself.
Code Examples
1// Create a color palette array
2const colorPalette = nodeArray([
3 color(0xff0000), // Red
4 color(0x00ff00), // Green
5 color(0x0000ff) // Blue
6]);
7
8// Calculate a dynamic index based on world Y-position
9const index = floor(positionWorld.y.mul(3));
10
11// Access an element from the array using the dynamic index
12const finalColor = element(colorPalette, index);