Folding or repeating UV coordinates multiplies SDF shapes without extra draw calls
Instead of calling an SDF function multiple times with different offsets, the input coordinate p can be transformed before being passed to the SDF to create geometric duplicates efficiently. opSymX replaces p.x with abs(p.x) to mirror a shape across the y-axis. opSymXY applies abs to both axes, producing four copies. opRep uses mod(p, c) - c*0.5 to tile the shape infinitely across one or more axes with spacing c. opRepLim constrains repetition to a finite count using clamp. These operations have zero performance cost for additional copies since a single SDF evaluation suffices per pixel. A common mistake is forgetting to offset the original shape before applying symmetry, which places it on the axis and produces unexpected half-shapes.
Examples
// Mirror across y-axis
vec2 opSymX(vec2 p) { p.x = abs(p.x); return p; }
// Infinite repeat with spacing c
vec2 opRep(vec2 p, vec2 c) { return mod(p, c) - c*0.5; }
float d = sdCircle(opSymX(uv - vec2(0.2, 0.0)), 0.1);
Assessment
Using opSymX, draw two circles symmetrically placed at x=±0.3. Then modify the code to use opRep to tile them infinitely with spacing 0.4.