Tour of WGSL

Matrix constructors

Matrices have three kinds of constructors:

  1. Zero-value constructor: matCxRf() or matCxR<f32>()

    Example

    mat3x2f() constructs a mat3x2f with zero-values for each of the elements.

  1. Column-wise constructor: matCxR<f32>(column_0, column_1, …)

    Example

    mat2x4f(c0, c1) constructs a mat2x4<f32>, when both c0 and c1 are of type vec4<f32>.
    The first column is c0, and the second column is c1.

  2. Scalar-wise constructor: matCxR<f32>(column_0_row_0, column_0_row_1, …)

    Example

    mat2x3f(a, b, c, d, e, f) constructs a mat2x3<f32> with the given elements:

    ╭      ╮
    │ a  d │
    │ b  e │
    │ c  f │
    ╰      ╯