any
Returns true if any component of a boolean vector is true.
Test any in a live shader
Open the playground, start from a visual preset, and wire any into the fragment stage to see how it behaves with real values.
Open PlaygroundLive Demo Pending
The any function reduces a boolean vector to a single boolean by returning true if at least one component is true.
Signature
any :: (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 at least one component of x is true, otherwise returns false. Equivalent to x[0] || x[1] || ....
Example
pipeline BoundsCheck {
fragment {
float3 p = input.worldPos;
// Reject fragments outside a unit cube without multiple if statements.
bool3 outside = bool3(abs(p.x) > 1.0, abs(p.y) > 1.0, abs(p.z) > 1.0);
if (any(outside)) {
discard;
}
output.color = float4(p * 0.5 + 0.5, 1.0);
}
}Common Use Cases
Early-Out Bounds Rejection
bool3 outOfBounds = bool3(uv.x < 0.0, uv.x > 1.0, uv.y < 0.0 || uv.y > 1.0);
if (any(outOfBounds)) discard;NaN / Inf Guard
// Flag pixels where any channel blew up.
bool3 bad = bool3(isnan(color.r), isnan(color.g), isnan(color.b));
float3 safe = any(bad) ? float3(1.0, 0.0, 1.0) : color;
Triggering Effects on Any Match
// Light up when any of the tracked conditions fires.
bool3 alerts = bool3(temperature > threshold, pressure > maxPressure, flowRate < minFlow);
output.color = any(alerts) ? alertColor : baseColor;
Short-Circuit Semantics
any evaluates the whole vector — there is no short-circuit. Precompute the components you need into a bvecN; don't rely on skipping side effects inside the arguments.
Pair With Componentwise Comparisons
any is most useful on the results of componentwise comparisons or masks. Building a bvecN ad-hoc and then calling any keeps branching at a single well-defined point.
Compiled Output
When compiled to GLSL:
any(bvec3(a, b, c))
When compiled to HLSL:
any(x)
When compiled to Metal:
any(x)
When compiled to SPIR-V:
Uses the OpAny instruction directly.