all
Returns true if every component of a boolean vector is true.
Test all in a live shader
Open the playground, start from a visual preset, and wire all into the fragment stage to see how it behaves with real values.
Open PlaygroundLive Demo Pending
The all function reduces a boolean vector to a single boolean by returning true only if every component is true.
Signature
all :: (bvecN x) -> bool {...}
Where bvecN is bool2, bool3, or bool4.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | bvecN | Boolean vector to reduce |
Return Value
Returns true if every component of x is true, otherwise returns false. Equivalent to x[0] && x[1] && ....
Example
pipeline InUnitCube {
fragment {
float3 p = input.worldPos;
// Keep fragments strictly inside a unit cube.
bool3 inside = bool3(abs(p.x) < 1.0, abs(p.y) < 1.0, abs(p.z) < 1.0);
if (!all(inside)) {
discard;
}
output.color = float4(p * 0.5 + 0.5, 1.0);
}
}Common Use Cases
Inclusive Range Check
bool2 inRange = bool2(uv.x >= 0.0 && uv.x <= 1.0, uv.y >= 0.0 && uv.y <= 1.0);
if (!all(inRange)) discard;Validating Multiple Conditions
// Enable feature only when every requirement is met.
bool4 ready = bool4(sceneLoaded, shadowsReady, assetsStreamed, frameStable);
float factor = all(ready) ? 1.0 : 0.0;
Masked Write
// Write to output only if every channel of a validity mask passes.
bool3 valid = bool3(color.r >= 0.0, color.g >= 0.0, color.b >= 0.0);
if (all(valid)) {
output.color = float4(color, 1.0);
}
Short-Circuit Semantics
all evaluates the whole vector — there is no short-circuit. Build up the bvecN from the conditions you want to test, then call all once.
Complement of any
all(x) is equivalent to !any(!x) (De Morgan's law). Pick the form that reads most naturally for the thing you're testing.
Compiled Output
When compiled to GLSL:
all(bvec3(a, b, c))
When compiled to HLSL:
all(x)
When compiled to Metal:
all(x)
When compiled to SPIR-V:
Uses the OpAll instruction directly.