home/ atoms/ iq-2d-sdf-library-offset

A reference-list SDF is dropped into a shader by adding an offset parameter subtracted from p

Inigo Quilez maintains a public reference page of signed distance functions for 2D shapes — stars, boxes, segments, bezier curves, polygons, and many others. To reuse one in Shadertoy you don’t derive it: copy the function verbatim, then add an offset parameter and subtract it from p at the top of the function so the shape can be positioned anywhere, and call it with the desired position and size. Some 2D functions depend on utility functions from IQ’s 3D SDF page (e.g., dot2), which must be copied as well. This offset-adaptation is the standard workflow for reusing community SDFs and removes the need to derive distance formulas from scratch.

Examples

// From IQ's site — Star 5 exact, with offset added:
float sdStar5(in vec2 p, in float r, in float rf) { ... }
// Usage with offset:
float d = sdStar5(uv - offset, 0.3, 0.5);
float col = step(0.0, -d);

Assessment

Look up the sdBox function on IQ’s 2D SDF list, add an offset parameter, and add it to a Shadertoy shader. Position it at (0.2, 0.1) and combine it with a circle using union.

“With only a few small tweaks, we can pick many 2D SDFs from Inigo Quilez's website and draw them to the canvas with an offset.”
corpus · shadertoy-tutorial-nathan-vaughn-inspirnathan · chunk 5