subgroupOr
Performs a bitwise OR reduction of the integer input e across all active invocations in the same subgroup and returns the same result to every invocation.
Core Advantages
Aggregates per-lane bit flags in constant time using hardware subgroup ops, avoiding shared-memory loops and reducing divergence and sync overhead.
Common Uses
Convert a per-lane boolean to 0/1, then apply subgroup-wide 'any' via OR while keeping bitmask semantics.
Merge per-lane bitmasks into a single subgroup mask to gate shader logic or trigger a single write.
Combine with invocationSubgroupIndex so only lane 0 writes the reduced result to a buffer.
How to adjust
Takes a single integer argument e (int/uint). Cast booleans or floats via uint()/int() first. Build 0/1 flags or bitfields then reduce with subgroupOr; convert back to boolean with notEqual(result, uint(0)); use shiftLeft/bitOr to pack or unpack masks. The value is uniform within the subgroup, which helps avoid intra-subgroup divergence.
Code Examples
1// Map per-lane condition to 0/1 and reduce with subgroupOr; the result gates color for the whole subgroup
2<Canvas>
3 <mesh>
4 <sphereGeometry args={[0.4, 128, 128]} />
5 <meshStandardNodeMaterial
6 colorNode={
7 select(
8 vec3(0.25, 0.25, 0.3),
9 vec3(0.9, 0.4, 0.2),
10 notEqual(
11 subgroupOr(
12 uint(
13 greaterThan(
14 fract( positionLocal.x.mul(10.0) ),
15 0.5
16 )
17 )
18 ),
19 uint(0)
20 )
21 )
22 }
23 />
24 </mesh>
25</Canvas>