This API is experimental
Its behavior may change in a future version of p5.js.
Returns the index of the current instance when drawing multiple copies of a shape with model(count). The first instance has an ID of 0, the second has 1, and so on.
This lets each copy of a shape behave differently. For example, you can use the ID to place instances at different positions, give them different colors, or animate them at different speeds.
instanceID() can only be used inside a p5.strands shader callback.
If you are using WebGPU mode, a common pattern is to use instanceID() to look up data made with createStorage(). This lets you give each instance different properties.
This can be paired with buildComputeShader to update the data being read.
Examples
Syntax
instanceID()
Parameters
Returns
The index of the current instance.
Notice any errors or typos? Please let us know. Please feel free to edit src/strands/p5.strands.js and open a pull request!