element
A function node used to access (read) a specific element from an array-like node (such as `nodeArray` or `bufferAttribute`) using a dynamic integer index.
Core Advantages
Its core advantage is enabling dynamic data access within the shader. It allows the index to be a computable node, letting the shader decide which data to read based on runtime conditions (like vertex ID, noise values, or instance ID), which is fundamental for procedural effects and data-driven algorithms.
Common Uses
Picking a color from a color palette (nodeArray) based on a calculated index
Iterating through light data arrays in a multi-light shader using a loop counter as the index
Reading each particle's state from a `bufferAttribute` in a GPU particle system using `instanceID` as the index
Looking up a bone matrix in vertex skinning using the `skinIndex` attribute as the index
How to adjust
The primary way to adjust the effect of `element` is by changing its `index` input node. For example, in a color palette application, if the index is derived from `positionWorld.y`, it creates vertical color bands. If you change the index logic to be based on `uv().x`, `element` will then pick colors based on the horizontal texture coordinate, changing the visual effect to horizontal bands. This shows how controlling the index can completely remap data distribution on a model's surface.
Code Examples
1// Calculate a dynamic index based on world Y-position
2const index = floor( positionWorld.y.mul( 4 ) );
3
4// Use the dynamic index to access an element from the colorPalette (a nodeArray)
5const finalColor = element( colorPalette, index );