How to make transformations in Godot shader language

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Juha Hollanti

Would like to understand how to apply transformations, like mentioned here in docs: Matrices and transforms — Godot Engine (stable) documentation in English
but with Godot shaders.

For example, after making an identity matrix, i.e. mat4(1), and multiplying it by 2 to duplicate the size, how can I apply it for example on UV, i.e. vec2, coordinates?

:bust_in_silhouette: Reply From: Tim Martin

Nothing too complicated, you just use the * multiplication operator. Note though that it only makes sense to multiply a mat4 by another mat4 (4x4), vec4 (4x1), or other 4x? matrix.

If you’re just aiming for 2D scaling and rotation, you probably want to start with a mat2. mat2 * vec2 = vec2

Just remembered about - this is a good way to visualise what’s actually going on during one of these operations.

Tim Martin | 2020-09-13 18:31