beginner

#5 Shapes: Rectangles

Box SDF and combining shapes

The rectangle SDF cleverly uses abs() to fold all four quadrants into one, exploiting the shape's symmetry. But the real power of SDFs is combining them: min(a, b) merges two shapes together (union), max(a, b) keeps only their overlap (intersection), and max(a, -b) cuts one shape out of another (subtraction). These boolean operations let you build complex geometry from simple primitives.

Key Concepts

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

Source Code


    
← Previous Shapes: Circle Next → Patterns & Tiling

All Tutorials