mat4
Function
mat4 builds a matrix with 4 columns and 4 rows. Each column describes the image of one input basis direction.
Compare examples
Compare the zero matrix with distinct columns and a diagonal pattern. Read the displayed matrix across rows and the constructor down columns.
Example 1mat4()
0000000000000000 - Result
[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
Example 2mat4(1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16.)
15913261014371115481216 - Result
[[1,5,9,13],[2,6,10,14],[3,7,11,15],[4,8,12,16]]
Example 3mat4(1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.)
1000010000100001 - Result
[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,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 a matrix to represent a linear transformation. Reading it by columns makes the constructor order visible.
Inputs and limits
Components are supplied in column-major order. An argument-free constructor makes a zero matrix. Rectangular matrices do not have a determinant.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Builds a mat4x4, 4 columns of 4 components in column-major order, from 4 vec4 columns, from 16 components column by column, from a larger matrix by truncation, or with no arguments for the zero matrix (§40).
Syntax
declare function mat4(): mat4x4declare function mat4(c0: vec4, c1: vec4, c2: vec4, c3: vec4): mat4x4declare function mat4(e0: number, e1: number, e2: number, e3: number, e4: number, e5: number, e6: number, e7: number, e8: number, e9: number, e10: number, e11: number, e12: number, e13: number, e14: number, e15: number): mat4x4declare function mat4(m: mat4x4): mat4x4A 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
-
c0optionalvec4 -
e0optionalnumber -
moptionalmat4x4 -
c1optionalvec4 -
e1optionalnumber -
c2optionalvec4 -
e2optionalnumber -
c3optionalvec4 -
e3optionalnumber -
e4optionalnumber -
e5optionalnumber -
e6optionalnumber -
e7optionalnumber -
e8optionalnumber -
e9optionalnumber -
e10optionalnumber -
e11optionalnumber -
e12optionalnumber -
e13optionalnumber -
e14optionalnumber -
e15optionalnumber
Return value
Description
It is square, so determinant applies and transpose maps it to itself.