globalId
In a compute shader, provides a globally unique, 3D absolute coordinate (ID) for each thread, directly solving the problem of precise data addressing in massive parallel tasks.
Core Advantages
Its core advantage is immense code simplification. It encapsulates the common `workgroupId * workgroupSize + localId` calculation, allowing developers to intuitively access the global coordinate, which makes code cleaner, more readable, and reduces potential errors from manual computation.
Common Uses
As pixel coordinates for image processing and procedural texture generation.
As a one-dimensional array index for physics simulation in large-scale particle systems.
As 3D voxel coordinates for processing 3D textures or volumetric data.
As a unique work-item identifier in general-purpose parallel algorithms (e.g., matrix multiplication).
How to adjust
This node is a read-only built-in variable and cannot be adjusted. Its effect is understood through visualization: by normalizing `globalId` and outputting it as a color to a texture, you will see a smooth color gradient that covers the entire task area, intuitively demonstrating the global coordinate system.
Code Examples
1// Normalize the global ID to the [0, 1] range
2const normalizedId = globalId.xy.div( resolution );
3const finalColor = vec3( normalizedId.x, normalizedId.y, 0.5 ); // Visualize as color