array
On this page

array

Function

An array groups a fixed number of values of one element type.

Compare examples

The listed elements fill the array in input order. With no arguments, the constructor fills each element with zero.

Example 1array(1., 2., 3.)
Result
[1, 2, 3]
Example 2array<f32, 3>()
Result
[0, 0, 0]
Example 3array(vec2(1., 0.), vec2(0., 1.))
Result
[[1, 0], [0, 1]]

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

When to use it

Use it for storing a short kernel, lookup table, or set of samples.

Inputs and limits

The constructor count must match the fixed length. A zero constructor fills with the element type's zero, not an identity matrix or an arbitrary default.

For shader input rules and precision, consult WGSL and GLSL ES 3.00.

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Builds an array<T, N> from exactly N values of type T.

Syntax

declare function array<V extends readonly unknown[]>(...values: V): array<[(V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never)] extends [never] ? V[number] : (V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never), V['length']>
declare function array<T, N extends number>(...values: readonly T[]): array<T, N>

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 number you write as a type is inferred from its uses, and f32, i32 and u32 fix a width; the TypeScript constructs page carries that row with the compiler's emit.

Parameters

  • ...values Vreadonly T[]

Return value

array<[(V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never)] extends [never] ? V[number] : (V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never), V['length']>array<T, N>

Description

Without type arguments, array(v1, v2, ..., vN) reads T and N off the values, as WGSL does; array<T, N>(v1, ..., vN) names them, and array<T, N>() is the zero value, every element the zero of its type. An array has the methods map, forEach, some, every and reduce, each a counted loop over its elements that calls the function it is handed with the element, its i32 index and the array.

Examples

See also

Edit this page Report a problem