intermediate

#11 Rotation & Transforms

Rotating shapes with 2D matrix rotation

In shaders, you don't move shapes — you transform the coordinate space and the shapes come along for the ride. A 2D rotation matrix mat2(cos, -sin, sin, cos) spins the entire coordinate system around the origin. Apply it to your UVs before evaluating an SDF, and the shape appears rotated. To rotate around a specific point instead of the center, translate first by subtracting an offset, then rotate. Animating the angle with iTime makes shapes spin continuously.

Key Concepts

Try this shader live in the Shader Sandbox editor with real-time preview.
Open in Sandbox

Source Code


    
← Previous Intro to Raymarching Next → Color Spaces

All Tutorials