subgroupBallot
Performs a subgroup-wide vote over a boolean predicate and returns a 128-bit vec4<u32> mask with bits set for invocations where pred is true.
Core Advantages
O(1) access to subgroup voting results, enabling warp/subgroup-level algorithms and branching.
Common Uses
Subgroup any/all checks and early exits
Counting threads that satisfy a condition
Mask-driven material parameter switching or shading branches
Filtering/locating lanes together with subgroupInvocationID
How to adjust
Shape the pred expression as needed: normals, depth, lighting, random, etc. any check: any(notEqual(mask, uvec4(0))). all check: all(equal(mask, uvec4(0xffffffffu))). To get a population count, sum per-component bit counts (use countOneBits/bitCount when available). Note: requires backend subgroup support; typically unavailable on WebGL.
Code Examples
1<Canvas>
2 <mesh>
3 <sphereGeometry args={[0.4, 128, 128]} />
4 <meshStandardNodeMaterial
5 colorNode={
6 cond(
7 any( notEqual( subgroupBallot( gt( dot( normalView, vec3(0, 1, 0) ), 0.5 ) ), uvec4(0) ) ),
8 vec3(1.0, 0.25, 0.25),
9 vec3(0.2, 0.2, 1.0)
10 )
11 }
12 />
13 </mesh>
14</Canvas>