How to make a Matrix4 from uv transform?

Hi,
I want to use Matrix4 to represent uv transform in shader:

vec2 uv = (uvMatrix4 * vec4(vUv.xy, 0, 1)).xy;

How to set uv transform on Matrix4 like Matrix3.setUvTransform?

You may think why not use Matrix3, Matrix3 is good but I need to multiply my matrix with a given matrix from other software. The software use Matrix4 to represent uv transform and I don’t know how to extract the 3D matrix from 4D matrix.
It will be nice to know how to extract Matrix3 from a Matrix4 which only contains transform on x and y, then I don’ t need Matrix4.setUvTranform any longer.

Thanks!

Extract Matrix3 from a Matrix4 which only contains transform on x and y:

[a, b, c, d,
e, f,g, h,
x, x, x, x,
x, x, x, x]

=>

[a, b, d,
e, f, h,
0, 0, 1]

PS. The arrays above are in row-major order.
PPS. Matrix’s fromArray method uses column-major order.

1 Like