uniformArray
A node for efficiently passing a collection of same-typed data (e.g., colors, vectors) as a single unit from JavaScript to the shader.
Core Advantages
Greatly simplifies the management and transfer of batch data. It allows for dynamically scalable shader logic (e.g., handling a variable number of lights) without modifying and recompiling the shader code, enhancing flexibility.
Common Uses
Providing a color palette for cel/toon shading.
Passing the positions and colors of multiple light sources for multi-point lighting.
Defining complex, multi-stop color gradients.
How to adjust
Adjust in two ways: either modify its .value array in JS to change the entire dataset (e.g., swapping a color palette), or alter the index calculation logic in the shader to redefine how the data is used (e.g., coloring based on model height instead of lighting).
Code Examples
1// In JS: const celColors = [ color1, color2, color3 ];
2const colorsNode = uniformArray( celColors );
3
4// In TSL, calculate index from a light factor (0-1)
5const colorIndex = lightFactor.mul( colorsNode.count ).floor();
6
7// Get color from the array using the .element() method and index
8material.colorNode = colorsNode.element( colorIndex );