Tour of WGSL

Vectors

WGSL supports 2-element, 3-element and 4-element vectors of scalar types.

Vectors are declared with the form vecN<T> , where N is the number of elements in the vector, and T is the element type.

Example
vec2<f32>A two-element vector of f32.
vec3<u32>A three-element vector of u32.
vec4<bool>A four-element vector of bool.

WGSL also predeclares the aliases vecNS , where S is one of i, u or f:

  • vecNi is an alias to vecN<i32>
  • vecNu is an alias to vecN<u32>
  • vecNf is an alias to vecN<f32>
Example
vec2fis an alias to vec2<f32>.
vec3uis an alias to vec3<u32>.
vec4iis an alias to vec4<i32>.