WasmGPU.math.mat4.sub¶
Summary¶
WasmGPU.math.mat4.sub computes component-wise subtraction ( - b). It is commonly used for deltas, offsets, and residual computation.
Syntax¶
WasmGPU.math.mat4.sub(matr1: number[], matr2: number[]): number[]
const result = wgpu.math.mat4.sub(matr1, matr2);
Precision-Specific Wasm Forms¶
WasmGPU.math.mat4f.sub(out: WasmPtr, a: WasmPtr, b: WasmPtr): void
WasmGPU.math.mat4d.sub(out: WasmPtr, a: WasmPtr, b: WasmPtr): void
These forms use caller-owned pointers to 16-element matrix blocks in WasmGPU driver memory: binary32 for mat4f and binary64 for mat4d. Methods with an output pointer write that block instead of allocating a JavaScript array. See WasmGPU.math for allocation, views, aliasing, and release requirements.
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
matr1 |
number[] |
Yes | First 4x4 matrix input (16 numbers in column-major order). |
matr2 |
number[] |
Yes | Second 4x4 matrix input (16 numbers in column-major order). |
Returns¶
number[] - New 4x4 matrix as a 16-number column-major array.
Type Details¶
Example¶
const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);
const matr1 = wgpu.math.mat4.identity();
const matr2 = wgpu.math.mat4.rotateY(wgpu.math.mat4.identity(), Math.PI / 6);
const result = wgpu.math.mat4.sub(matr1, matr2);
console.log(result);