toMat3: Dimensional Matrix Projection
Homogeneous to Euclidean Transformation Kernel Extraction
The toMat3
function extracts the essential 3×3 transformation kernel from a 4×4 homogeneous matrix by projecting away the translational and perspective components. This operation preserves the linear transformation characteristics: rotation, scaling, and shearing while discarding positional information.
Mathematically, for a 4×4 matrix :
The function extracts the upper-left 3×3 submatrix:
This operation is fundamental in computer graphics for separating orientation from position, enabling normal vector transformations without translational artifacts.
const fragment = () => { const baseMatrix = mat4( iTime.cos(), iTime.sin().negate(), 0, 0, iTime.sin(), iTime.cos(), 0, 0, 0, 0, 1, 0, 0.5, 0.3, 0.2, 1 ) const rotationOnly = toMat3(baseMatrix) const direction = vec3(uv, 0.5).normalize() const transformed = rotationOnly.mul(direction) const intensity = transformed.z.abs() const colorPhase = transformed.y.atan2(transformed.x) const color = vec3( colorPhase.add(iTime).sin().mul(0.5).add(0.5), colorPhase.add(iTime).add(2.0).sin().mul(0.5).add(0.5), intensity ).mul(intensity) return vec4(color, 1) }
This visualization demonstrates how toMat3
isolates rotational transformation from a complete 4×4 matrix. The extracted 3×3 matrix transforms directional vectors while preserving their angular relationships, creating fluid color rotations without positional drift that would occur with the full 4×4 matrix transformation.