Is inverting a 4x4 matrix (context: webgpu) easy to implement from scratch, or something to just add an external dependency for ?

Well this is answered in this stackoverflow thread: c++ - Inverting a 4x4 matrix - Stack Overflow

So I’d say it’s not exactly straightforward, but feasible. But in the context of wgpu you’re probably already using a math library, maybe it already provides inversion of 4x4 matrices ?

Do you actually need the inverse or would you be happy with using a decomposition? What are you going to use the inverse for?

No, it's a bunch of handrolled {Vec, Mat}{2, 3, 4}

I have a screen space ray that I need to transform into a world space ray. I think (but not 100% sure) I need the matrix inverse for this.

I would highly suggest using an existing math library.

`glam`

is the rust graphics community's goto linalg library right now.

Indeed, you'd need the inverse projection matrix to acquire the view space ray.

The linked SO code is not great. Compared to Gaussian elimination, Cramer's rule requires more floating point operations and is less stable.

You might not need the inverse if you're working with projective coordinates, just the inverse up to a scalar multiple.