GLSL built-in function
inverse()
Returns the inverse of a nonsingular square matrix.
Demo version: GLSL ES 3.00 / WebGL 2Demo stage: Fragment
Syntax
mat inverse(mat m)Parameters
- m
- Input declared in the signature; match its type and dimensions
Return value
A square matrix that multiplies m to the identity; the result is undefined for singular or poorly conditioned inputs.
Live example
Edit the code and the preview updates as you type.
What inverse does
Returns the inverse of a nonsingular square matrix.
Read the preview
inverse(mat2(1.0,0.5,0.0,1.0)) shears the coordinate grid in the opposite direction to the original matrix. Set 0.5 to 0.0 to recover an axis-aligned grid.
Core call
inverse(mat2(1.0,0.5,0.0,1.0))*vec2(x,y);
Results for singular or poorly conditioned matrices are undefined.
Experiment
Change that off-diagonal 0.5 to -0.5. The diagonal grid lines lean the other way; the determinant remains 1, so this modified matrix is still invertible.