Intrinsics2 min read

any

Returns true if any component of a boolean vector is true.

Reading Time
2 min
Word Count
185
Sections
10
Try It Live

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 Playground

Live Demo Pending

This intrinsic does not yet have a self-contained interactive preview. Compute-only and external-resource intrinsics need a different demo path than the current fragment and 3D showcases.

The any function reduces a boolean vector to a single boolean by returning true if at least one component is true.

Signature

bwsl
any :: (bvecN x) -> bool {...}

Where bvecN is bool2, bool3, or bool4.

Parameters

ParameterTypeDescription
xbvecNBoolean 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

bwsl
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

bwsl
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

bwsl
// 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

bwsl
// 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:

glsl
any(bvec3(a, b, c))

When compiled to HLSL:

hlsl
any(x)

When compiled to Metal:

msl
any(x)

When compiled to SPIR-V:

Uses the OpAny instruction directly.

See Also

  • all - True if every component is true
  • select - Branchless conditional selection
  • wave_any - True if any lane in the wave is true