mx_rotate3d
mx_rotate3d
Rotates a vec3 around a given 3D axis by an angle in degrees. Implements Rodrigues’ rotation formula. Works for directions and positions.
Core Advantages
Matrix-free; degree-based input; axis is auto-normalized; usable in vertex or fragment stages.
Common Uses
Rotate normals/tangents to drive anisotropy or flowing highlights.
Rotate UV or 3D noise coordinates for spinning textures and domain warping.
Rotate local positions in the vertex stage for simple spin animations.
Perturb reflection/view directions slightly to break repetition.
How to adjust
amount is in degrees; sign controls direction via the right-hand rule. axis is normalized internally and must be non-zero. To rotate around a pivot p, use pos.sub(p) → rotate → add(p). Convert radians to degrees before passing if needed.
Code Examples
1// Rotate world normal 45° around Y and visualize
2const axisY = vec3( 0, 1, 0 );
3const rotatedN = mx_rotate3d( normalWorld, 45.0, axisY );
4material.colorNode = rotatedN.mul( 0.5 ).add( 0.5 );
5
6// Vertex-stage rotation of local positions around Y (about origin)
7material.positionNode = mx_rotate3d( positionLocal, 30.0, vec3( 0, 1, 0 ) );