invocationLocalIndex
In a compute shader, provides the current thread with a unique, one-dimensional integer index starting from 0 within its local Workgroup.
Core Advantages
Its core value is enabling efficient collaboration between threads within a workgroup. Threads can use this unique index to coordinate operations, especially when accessing shared memory, making it a cornerstone for high-performance parallel algorithms like parallel reduction.
Common Uses
In image processing, as a data address calculator to locate the pixel to be processed.
In particle systems, as a data indexer to precisely locate particle data to be read/written in a buffer.
In algorithms like parallel reduction, as an algorithm coordinator to determine the role a thread should play in each step.
How to adjust
This node is a read-only built-in variable and cannot be adjusted. Its effect is understood through visualization: normalize the index value to a grayscale color and output it to a texture. The result will be a repeating linear gradient pattern from black to white within each workgroup's tile, clearly revealing its 'local' nature.
Code Examples
1// Normalize the index from the [0, 255] range to [0.0, 1.0]
2const factor = invocationLocalIndex.tofloat().div( 255.0 );
3
4// Create a grayscale color for debugging based on the factor
5const debugColor = vec3( factor );