instance
Accesses unique per-instance data, such as its specific position, color, or size, for an InstancedMesh within TSL.
Core Advantages
Encapsulates the common 'get a specific attribute for the current instance' operation into a single call, greatly simplifying shader logic for instanced rendering, improving code readability and safety, and integrating seamlessly with the TSL ecosystem.
Common Uses
Large-scale procedural scenes (forests, cities)
High-performance particle systems (rain, snow, sparks)
Data visualization (3D bar charts)
Animated character crowds (crowds, schools of fish)
How to adjust
Switching the `attribute()` node referenced inside `instance()` changes the data source; for example, swapping a color attribute for a position attribute will make the object's color determined by its spatial position. A more advanced adjustment is to dynamically modify its index parameter, allowing an instance to read data from another, creating 'shuffling' or 'flowing' animation effects.
Code Examples
1// Get the unique color attribute for the current instance
2const instanceColor = instance( attribute( 'instanceColor', 'vec3' ) );
3
4// Assign the instance color to the material's final color
5material.colorNode = instanceColor;