inverse
Returns the inverse of a matrix (mat2/mat3/mat4). Use it to undo a linear transform, swap coordinate spaces, or build normal‑matrix style math.
Core Advantages
A TSL wrapper around GLSL’s inverse(): type‑safe and composable, evaluated on the GPU for any dynamic matrix node—no JS‑side inversion or uniform syncing.
Common Uses
World↔Local: inverse(modelWorldMatrix).mul( positionWorld ) to recover object‑space coordinates.
Build a normal matrix mathematically as the inverse‑transpose when non‑uniform scale is present.
Undo custom 2D/3D transforms (UV transform matrices, skinning/instance matrices).
Derive mappings from target space back to source space in projection/reconstruction or post effects.
How to adjust
This is a pure function; adjust its input matrix. Make sure the matrix is invertible (non‑zero determinant). Near‑singular transforms (e.g., scale ≈ 0) lead to unstable results—avoid degenerate scales and clamp tiny values to an EPSILON when constructing matrices.
Code Examples
1
2// Recover local‑space position from a world‑space point
3const localPos = inverse( modelWorldMatrix ).mul( positionWorld );
4
5// (Optional) Normal matrix idea: transpose( inverse( mat3( modelViewMatrix ) ) )
6
7// Color blend driven by local Y
8const t = localPos.y.remap( -1.0, 1.0 ).saturate();
9material.colorNode = mix( bottomColor, topColor, t );
10