mat2
Constructs or converts a 2x2 matrix (mat2) from various inputs like vectors, a single float, or other matrices, essential for 2D transformations.
Core Advantages
Greatly simplifies the process of creating and using 2x2 transformation matrices within the node graph. It abstracts away the underlying GLSL matrix constructor syntax, making operations like rotating and scaling 2D vectors (e.g., UV coordinates) intuitive and less error-prone.
Common Uses
Building 2D rotation matrices to rotate texture coordinates (UVs)
Creating a uniform scale matrix from a single float input
Repacking the four components of a vec4 into a 2x2 matrix
Defining a custom 2D coordinate system for procedural pattern generation
How to adjust
This node has no adjustable parameters itself; its visual effect is entirely dictated by its input. Providing a static numerical input results in a fixed geometric transformation (e.g., rotating a texture by a fixed angle). Connecting its input to a dynamically changing value (like a `timer` node) produces continuous animations, such as causing a texture to rotate or scale smoothly over time.
Code Examples
1// Build a 2x2 rotation matrix from an angle
2const rotationMatrix = mat2(
3 cos( angle ), sin( angle ),
4 -sin( angle ), cos( angle )
5);
6
7// Apply the matrix to a 2D vector (like UV coordinates)
8const rotatedUV = rotationMatrix.mul( uv() );