select
On this page

select

Function

Returns trueValue where cond is true and falseValue where it is false, in WGSL's argument order: the condition comes last.

The signature and the sentence under each name are the compiler's own text at commit 26de7be8.

Syntax

declare function select<V extends vec2 | vec3 | vec4 | vec2i | vec3i | vec4i | vec2u | vec3u | vec4u | vec2b | vec3b | vec4b>(a0: V, a1: V, a2: (V extends { readonly [vecTag]: readonly [unknown, 2] } ? vec2b : V extends { readonly [vecTag]: readonly [unknown, 3] } ? vec3b : vec4b)): V
declare function select<V extends vec2 | vec3 | vec4 | vec2i | vec3i | vec4i | vec2u | vec3u | vec4u | vec2b | vec3b | vec4b>(a0: V, a1: V, a2: bool): V
declare function select<P0 extends number | boolean, P1 extends number | boolean>(a0: P0, a1: P1, a2: bool): ([P0] extends [boolean] ? bool : typeof f32Tag extends keyof P0 ? f32 : typeof i32Tag extends keyof P0 ? i32 : typeof u32Tag extends keyof P0 ? u32 : typeof f64Tag extends keyof P0 ? f64 : ([P1] extends [boolean] ? bool : typeof f32Tag extends keyof P1 ? f32 : typeof i32Tag extends keyof P1 ? i32 : typeof u32Tag extends keyof P1 ? u32 : typeof f64Tag extends keyof P1 ? f64 : number))
declare function select<T extends Numeric | bool | BoolVec | Vec64Any | f64>(
falseValue: T,
trueValue: T,
cond: bool | BoolVec,
): T

A number in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.

type f32 = number & { readonly [f32Tag]?: true }

A declaration you write still needs a width, and a bare number on a field or a parameter is refused; the TypeScript constructs page carries that row with the compiler's own message.

A signature may name a type the ambient file declares for its own use. These are those declarations.

BoolVec
type BoolVec = vec2b | vec3b | vec4b
Vec64Any
type Vec64Any = vec2f64 | vec3f64 | vec4f64
Numeric
type Numeric = number | vec2 | vec3 | vec4 | vec2i | vec3i | vec4i | vec2u | vec3u | vec4u

Parameters

  • falseValue VP0T
  • trueValue VP1T
  • cond (V extends { readonly [vecTag]: readonly [unknown, 2] } ? vec2b : V extends { readonly [vecTag]: readonly [unknown, 3] } ? vec3b : vec4b)boolbool | BoolVec

Return value

V([P0] extends [boolean] ? bool : typeof f32Tag extends keyof P0 ? f32 : typeof i32Tag extends keyof P0 ? i32 : typeof u32Tag extends keyof P0 ? u32 : typeof f64Tag extends keyof P0 ? f64 : ([P1] extends [boolean] ? bool : typeof f32Tag extends keyof P1 ? f32 : typeof i32Tag extends keyof P1 ? i32 : typeof u32Tag extends keyof P1 ? u32 : typeof f64Tag extends keyof P1 ? f64 : number))T

Description

Compiles to the same code as a ternary over cond.

Targets

WGSL
select(a, b, c)
GLSL ES 3.00
(c ? b : a)

Examples

See also

Edit this page Report a problem