LookHeavyweight · 8 uses
SDF
A shape stored as distance: every point knows how far the edge is.
A shape described by distance instead of by an outline: for any point, one number says how far the nearest edge is, negative inside. That number gives crisp edges at any zoom, outlines and glows for free, shapes that melt into each other, morphs between anything, and walls for particles to slide off. Raymarching is the same idea in 3D. Inigo Quilez’s distance-function pages are the reference.
Uses · 8Pick one to run it on the left
- Prompt
A navigation bar with a liquid cursor. A full-screen fragment shader under the nav (pointer-events: none) draws the five nav pills as rounded-box SDFs from uniforms, positions measured from the DOM on resize, and the cursor as a 14 px circle, joined with a polynomial smooth-min (k = 28 px) so the cursor necks into a pill as it approaches and snaps free as it leaves. Color by the smooth-min weight: the cursor in the accent color, blending into the pills’ ink where they merge. The cursor follows the pointer through a spring (stiffness 220, damping 22) and grows with speed. Anti-alias with fwidth. The labels stay real DOM text above the canvas.
- Prompt
Icon morphing with SDFs: six 2D icons (circle, rounded square, triangle, five-point star, heart, plus) as distance functions in one fragment shader. Morph between any two with mix(dA, dB, t), t driven by a spring; subtract 0.025 × sin(π t) at the midpoint so the in-between shape stays full. Draw the fill and a 1.5 px outline from the same distance, anti-aliased with fwidth, and a faint ghost of both end shapes. A click goes to the next icon; hovering previews it at t = 0.15.
- Prompt
Particles that collide with text, no physics engine. Draw the word to an offscreen canvas and run a two-pass chamfer distance transform (outside distance minus inside distance) to bake a field; or use an MSDF atlas. 3,000 grains fall from the top. Each frame per grain: d = field(p) − radius; if d < 0, move p out by −d along the normalized gradient (central differences), remove the velocity going into the surface plus 20% bounce, and damp the rest slightly. Respawn at the top when a grain leaves the screen. Draw the letters with faint contour lines of the field, and color grains that just touched in the accent color.
- Prompt
A raymarched infinite city in one fragment shader. Domain repetition: p.xz = mod(p.xz + c/2, c) − c/2 with c = 2.2 and a cell id from floor; each cell holds a rounded box whose height comes from hash(id), with windows from a repeated grid on its faces, some lit in the accent color. Keep an avenue clear with max(d, 1.25 − |p.x|). The camera flies forward at 2 units per second with a slow bank. 90 steps, fog to the background color by distance. Explain in a comment why repetition breaks the distance bound near cell edges, and the fix used (cap the step, or check the neighbour cells).
- Prompt
Turn a logo into a living contour map. Build the mark as a 2D SDF (or bake the SVG into a distance texture), then draw isolines with fract(d × 24 − time × 0.5) through smoothstep, every fifth line thicker and darker like a survey map, with a faint hill-shade from the gradient. The pointer adds a second blob with smooth-min so the contours bend around it. Ink lines on paper, the zero line in one accent color.
- Prompt
A UI kit rendered from SDFs: a button, a card and a toggle as rounded-box distances in a fragment shader. From the same d: fill = 1 − smoothstep(−aa, aa, d); stroke = 1 − smoothstep(w − aa, w + aa, |d|); glow = exp(−max(d, 0) × 18) × intensity; drop shadow = 1 − smoothstep(−blur, blur, d at p − offset). Hovering the button animates only uniforms (stroke width, glow intensity, shadow offset); no new geometry, no images. Show the five lines of shader that make the five effects beside it.
- Prompt
Show why SDF text stays sharp. Generate a multi-channel SDF atlas for one font with msdfgen (or msdf-bmfont), render a headline with troika-three-text or a small custom shader (median of the three channels, then smoothstep with screen-space derivatives). Fly the camera from far away to 40× magnification on one letter and keep it sharp, beside the same headline from an ordinary bitmap atlas that blurs. Then add an outline, a glow and a drop shadow by thresholding the same distance at different values.
- Prompt
Use 2D SDFs to draw shapes made of dots instead of pixels. On a halftone grid, each dot computes e = |mix(dSquare, dCircle, t)| for a shape near it and lights by exp(−e² / 2σ²), with σ about half the dot spacing, so the outline is a ring of dots on the zero line. Animate t with a bouncy ease to morph square → circle → triangle, scale in with an overshoot and out with 1 − t², and place several shapes on a golden-angle spiral. Cull each shape by its bounding box before evaluating the distance.
Learned from halftone-animation by atom63.
- Breaks when
- scaling or warping breaks the distances, so steps overshootsharp corners make the gradient jump; collisions jitter theremany SDFs raymarched per pixel kill mobile GPUs
- Also called
- signed distance field, signed distance function, distance field, MSDF, smooth min
More prompts
A 2D SDF toolkit with a debug view
Write a small GLSL library of 2D SDFs and a page that shows them: sdCircle, sdBox with corner radius, sdSegment, sdArc, sdStar5, sdTriangle; operators union (min), subtract (max(a, −b)), intersect (max), smooth union (polynomial smin with k), round (d − r), onion (|d| − w) and repeat (mod with a cell size). A debug view for any SDF: inside and outside in two tones, contour lines every 0.05 from fract(d × 20), the zero line anti-aliased with fwidth, and a probe at the pointer drawn as a circle of radius |d| with a line to the nearest point (p − ∇d × d).
From a mesh to a distance field
Bake a glTF mesh into a 64³ 3D texture of signed distances (three-mesh-bvh can generate one; or a compute pass that finds the closest point per voxel), then use it in shaders: particles that stream around the model without touching it, and a fog volume that thickens near its surface. Explain the resolution trade-off and how to clamp the field outside its bounds.
Related
Resources · 5
- halftone-animationA Canvas 2D halftone dot field: shockwave intro, carrier blobs, SDF shapes in dots, cursor ripples, a dial for every constant. MIT.atom63GitHub · code · demoOct 4, 2026
- Inigo Quilez: 2D distance functionsEvery 2D shape as an exact distance, each with a live Shadertoy. Where the star, heart and triangle here come from.iquilezlessite · code · demoOct 4, 2026
- msdfgen: multi-channel signed distance fieldsThe generator behind razor-sharp WebGL text at any size, corners included.ChlumskyGitHub · codeOct 4, 2026
- Distance functionsEvery SDF primitive with GLSL. Paste-ready.iquilezlessite · codeAug 28, 2026
- troika-three-textSDF text; the right answer for text in three.protectwiseGitHub · code · demoJun 14, 2026