
Shader Sdf
- 83 installs
- 8 repo stars
- Updated August 4, 2026
- bbeierle12/skill-mcp-claude
shader-sdf is a Claude skill providing GLSL signed distance functions for 2D/3D shape primitives, boolean operations, and raymarching.
About
This skill is a GLSL reference for signed distance functions used to define procedural shapes in shaders. It covers 2D and 3D primitives, boolean operations, smooth blending, repetition, and raymarching fundamentals. A developer uses it when creating procedural shapes, text effects, smooth morphing, or raymarched 3D scenes in GLSL.
- GLSL signed distance function reference for 2D/3D shape primitives and boolean operations
- Covers smooth blending, repetition, transformations, and raymarching fundamentals
- Ships copy-ready SDF primitives (circle, box, torus, capsule) and union/intersection/subtraction ops
Shader Sdf by the numbers
- 83 all-time installs (skills.sh)
- Ranked #1,098 of 2,245 Frontend Development skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
shader-sdf capabilities & compatibility
- Capabilities
- shader noise · shader router · r3f materials
- Use cases
- frontend · ui design
What shader-sdf says it does
Signed Distance Functions (SDFs) in GLSL—2D/3D shape primitives, boolean operations (union, intersection, subtraction), smooth blending, repetition, and raymarching fundamentals.
Signed Distance Functions return the distance from a point to a shape's surface. Negative = inside, positive = outside, zero = on surface.
npx skills add https://github.com/bbeierle12/skill-mcp-claude --skill shader-sdfAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 83 |
|---|---|
| repo stars | ★ 8 |
| Last updated | August 4, 2026 |
| Repository | bbeierle12/skill-mcp-claude ↗ |
What it does
Define procedural shapes and raymarched scenes in GLSL using signed distance functions.
Who is it for?
Defining procedural shapes and raymarched scenes with SDFs in GLSL.
When should I use this skill?
Creating procedural shapes, text effects, smooth morphing, or raymarched 3D scenes.
By the numbers
- Includes 3 boolean operations (union, intersection, subtraction) plus smooth variants
- Covers both 2D and 3D primitive SDFs
Files
Shader SDFs
Signed Distance Functions return the distance from a point to a shape's surface. Negative = inside, positive = outside, zero = on surface.
Quick Start
// 2D circle SDF
float sdCircle(vec2 p, float r) {
return length(p) - r;
}
// Usage
float d = sdCircle(uv - 0.5, 0.3);
// Render
vec3 color = d < 0.0 ? vec3(1.0) : vec3(0.0); // Hard edge
vec3 color = vec3(smoothstep(0.01, 0.0, d)); // Soft edge
vec3 color = vec3(smoothstep(0.02, 0.0, abs(d))); // Outline2D Primitives
Circle
float sdCircle(vec2 p, float r) {
return length(p) - r;
}Box
float sdBox(vec2 p, vec2 b) {
vec2 d = abs(p) - b;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
}Rounded Box
float sdRoundedBox(vec2 p, vec2 b, float r) {
vec2 d = abs(p) - b + r;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r;
}Line Segment
float sdSegment(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a;
vec2 ba = b - a;
float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
return length(pa - ba * h);
}Triangle
float sdTriangle(vec2 p, vec2 p0, vec2 p1, vec2 p2) {
vec2 e0 = p1 - p0, e1 = p2 - p1, e2 = p0 - p2;
vec2 v0 = p - p0, v1 = p - p1, v2 = p - p2;
vec2 pq0 = v0 - e0 * clamp(dot(v0, e0) / dot(e0, e0), 0.0, 1.0);
vec2 pq1 = v1 - e1 * clamp(dot(v1, e1) / dot(e1, e1), 0.0, 1.0);
vec2 pq2 = v2 - e2 * clamp(dot(v2, e2) / dot(e2, e2), 0.0, 1.0);
float s = sign(e0.x * e2.y - e0.y * e2.x);
vec2 d = min(min(
vec2(dot(pq0, pq0), s * (v0.x * e0.y - v0.y * e0.x)),
vec2(dot(pq1, pq1), s * (v1.x * e1.y - v1.y * e1.x))),
vec2(dot(pq2, pq2), s * (v2.x * e2.y - v2.y * e2.x)));
return -sqrt(d.x) * sign(d.y);
}Ring
float sdRing(vec2 p, float r, float thickness) {
return abs(length(p) - r) - thickness;
}Polygon (N-sided)
float sdPolygon(vec2 p, float r, int n) {
float a = atan(p.x, p.y) + 3.141592;
float s = 6.283185 / float(n);
return cos(floor(0.5 + a / s) * s - a) * length(p) - r;
}Star
float sdStar(vec2 p, float r, int n, float m) {
float an = 3.141592 / float(n);
float en = 3.141592 / m;
vec2 acs = vec2(cos(an), sin(an));
vec2 ecs = vec2(cos(en), sin(en));
float bn = mod(atan(p.x, p.y), 2.0 * an) - an;
p = length(p) * vec2(cos(bn), abs(sin(bn)));
p -= r * acs;
p += ecs * clamp(-dot(p, ecs), 0.0, r * acs.y / ecs.y);
return length(p) * sign(p.x);
}3D Primitives
Sphere
float sdSphere(vec3 p, float r) {
return length(p) - r;
}Box
float sdBox(vec3 p, vec3 b) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}Rounded Box
float sdRoundBox(vec3 p, vec3 b, float r) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0) - r;
}Cylinder
float sdCylinder(vec3 p, float h, float r) {
vec2 d = abs(vec2(length(p.xz), p.y)) - vec2(r, h);
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0));
}Torus
float sdTorus(vec3 p, vec2 t) {
vec2 q = vec2(length(p.xz) - t.x, p.y);
return length(q) - t.y;
}Cone
float sdCone(vec3 p, vec2 c, float h) {
vec2 q = h * vec2(c.x / c.y, -1.0);
vec2 w = vec2(length(p.xz), p.y);
vec2 a = w - q * clamp(dot(w, q) / dot(q, q), 0.0, 1.0);
vec2 b = w - q * vec2(clamp(w.x / q.x, 0.0, 1.0), 1.0);
float k = sign(q.y);
float d = min(dot(a, a), dot(b, b));
float s = max(k * (w.x * q.y - w.y * q.x), k * (w.y - q.y));
return sqrt(d) * sign(s);
}Capsule
float sdCapsule(vec3 p, vec3 a, vec3 b, float r) {
vec3 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
return length(pa - ba * h) - r;
}Plane
float sdPlane(vec3 p, vec3 n, float h) {
return dot(p, n) + h;
}Boolean Operations
Union (OR)
float opUnion(float d1, float d2) {
return min(d1, d2);
}Intersection (AND)
float opIntersection(float d1, float d2) {
return max(d1, d2);
}Subtraction (NOT)
float opSubtraction(float d1, float d2) {
return max(-d1, d2);
}Smooth Union
float opSmoothUnion(float d1, float d2, float k) {
float h = clamp(0.5 + 0.5 * (d2 - d1) / k, 0.0, 1.0);
return mix(d2, d1, h) - k * h * (1.0 - h);
}Smooth Intersection
float opSmoothIntersection(float d1, float d2, float k) {
float h = clamp(0.5 - 0.5 * (d2 - d1) / k, 0.0, 1.0);
return mix(d2, d1, h) + k * h * (1.0 - h);
}Smooth Subtraction
float opSmoothSubtraction(float d1, float d2, float k) {
float h = clamp(0.5 - 0.5 * (d2 + d1) / k, 0.0, 1.0);
return mix(d2, -d1, h) + k * h * (1.0 - h);
}Transformations
Translation
// Move shape by offset
float d = sdCircle(p - offset, r);Rotation (2D)
mat2 rot2D(float a) {
float s = sin(a), c = cos(a);
return mat2(c, -s, s, c);
}
// Rotate point around origin
vec2 rotatedP = rot2D(angle) * p;
float d = sdBox(rotatedP, size);Rotation (3D)
mat3 rotateX(float a) {
float s = sin(a), c = cos(a);
return mat3(1, 0, 0, 0, c, -s, 0, s, c);
}
mat3 rotateY(float a) {
float s = sin(a), c = cos(a);
return mat3(c, 0, s, 0, 1, 0, -s, 0, c);
}
mat3 rotateZ(float a) {
float s = sin(a), c = cos(a);
return mat3(c, -s, 0, s, c, 0, 0, 0, 1);
}Scale
// Scale shape
float d = sdCircle(p / scale, r) * scale;Symmetry
// Mirror across Y axis
p.x = abs(p.x);
float d = sdCircle(p - vec2(0.3, 0.0), 0.1);Domain Operations
Repetition (Infinite)
float opRepeat(vec2 p, vec2 spacing) {
vec2 q = mod(p + spacing * 0.5, spacing) - spacing * 0.5;
return sdCircle(q, 0.1);
}Repetition (Limited)
float opRepeatLimited(vec3 p, float spacing, vec3 count) {
vec3 q = p - spacing * clamp(round(p / spacing), -count, count);
return sdSphere(q, 0.1);
}Twist
float opTwist(vec3 p, float k) {
float c = cos(k * p.y);
float s = sin(k * p.y);
mat2 m = mat2(c, -s, s, c);
vec3 q = vec3(m * p.xz, p.y);
return sdBox(q, vec3(0.5));
}Bend
float opBend(vec3 p, float k) {
float c = cos(k * p.x);
float s = sin(k * p.x);
mat2 m = mat2(c, -s, s, c);
vec3 q = vec3(m * p.xy, p.z);
return sdBox(q, vec3(0.5));
}Onion (Hollow)
float opOnion(float d, float thickness) {
return abs(d) - thickness;
}Round
float opRound(float d, float r) {
return d - r;
}2D Rendering Techniques
Anti-aliased Edge
float aa = fwidth(d) * 1.5;
float mask = smoothstep(aa, -aa, d);Outline
float outline = smoothstep(thickness + aa, thickness - aa, abs(d));Glow
float glow = exp(-d * falloff);Drop Shadow
float shadow = smoothstep(0.0, blur, sdShape(p - shadowOffset));3D Raymarching (Basic)
float map(vec3 p) {
float d = sdSphere(p, 1.0);
d = opSmoothUnion(d, sdBox(p - vec3(1.0, 0.0, 0.0), vec3(0.5)), 0.2);
return d;
}
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.001, 0.0);
return normalize(vec3(
map(p + e.xyy) - map(p - e.xyy),
map(p + e.yxy) - map(p - e.yxy),
map(p + e.yyx) - map(p - e.yyx)
));
}
float raymarch(vec3 ro, vec3 rd) {
float t = 0.0;
for (int i = 0; i < 100; i++) {
vec3 p = ro + rd * t;
float d = map(p);
if (d < 0.001) break;
if (t > 100.0) break;
t += d;
}
return t;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 0.0, 3.0); // Ray origin
vec3 rd = normalize(vec3(uv, -1.0)); // Ray direction
float t = raymarch(ro, rd);
vec3 color = vec3(0.0);
if (t < 100.0) {
vec3 p = ro + rd * t;
vec3 n = calcNormal(p);
vec3 light = normalize(vec3(1.0, 1.0, 1.0));
float diff = max(dot(n, light), 0.0);
color = vec3(diff);
}
fragColor = vec4(color, 1.0);
}File Structure
shader-sdf/
├── SKILL.md
├── references/
│ ├── 2d-primitives.md # All 2D shapes
│ ├── 3d-primitives.md # All 3D shapes
│ └── operations.md # All operations
└── scripts/
├── primitives/
│ ├── 2d.glsl # 2D shape functions
│ └── 3d.glsl # 3D shape functions
├── operations.glsl # Boolean & domain ops
└── examples/
├── logo.glsl # 2D logo example
└── raymarch.glsl # 3D raymarching exampleReference
references/2d-primitives.md— Complete 2D shape libraryreferences/3d-primitives.md— Complete 3D shape libraryreferences/operations.md— All boolean and domain operations
{
"name": "shader-sdf",
"description": "Signed Distance Functions (SDFs) in GLSL—2D/3D shape primitives, boolean operations (union, intersection, subtraction), smooth blending, repetition, and raymarching fundamentals. Use when creating procedural shapes, text effects, smooth morphing, or raymarched 3D scenes.",
"tags": [
"shaders",
"glsl",
"code-generation"
],
"sub_skills": [],
"source": "claude-user",
"type": "template",
"depends_on": [
"shader-fundamentals"
],
"enhances": [],
"last_reviewed_at": null,
"review_score": null,
"relevance_tier": null
}
2D SDF Primitives Reference
Complete collection of 2D signed distance functions.
Basic Shapes
Circle
float sdCircle(vec2 p, float r) {
return length(p) - r;
}Box
float sdBox(vec2 p, vec2 b) {
vec2 d = abs(p) - b;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
}Rounded Box
float sdRoundedBox(vec2 p, vec2 b, vec4 r) {
// r.x = top-right, r.y = bottom-right, r.z = bottom-left, r.w = top-left
r.xy = (p.x > 0.0) ? r.xy : r.wz;
r.x = (p.y > 0.0) ? r.x : r.y;
vec2 q = abs(p) - b + r.x;
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r.x;
}Segment
float sdSegment(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
return length(pa - ba * h);
}Rhombus
float sdRhombus(vec2 p, vec2 b) {
p = abs(p);
float h = clamp((-2.0 * ndot(p, b) + ndot(b, b)) / dot(b, b), -1.0, 1.0);
float d = length(p - 0.5 * b * vec2(1.0 - h, 1.0 + h));
return d * sign(p.x * b.y + p.y * b.x - b.x * b.y);
}
float ndot(vec2 a, vec2 b) { return a.x*b.x - a.y*b.y; }Isoceles Trapezoid
float sdTrapezoid(vec2 p, float r1, float r2, float h) {
vec2 k1 = vec2(r2, h);
vec2 k2 = vec2(r2 - r1, 2.0 * h);
p.x = abs(p.x);
vec2 ca = vec2(p.x - min(p.x, (p.y < 0.0) ? r1 : r2), abs(p.y) - h);
vec2 cb = p - k1 + k2 * clamp(dot(k1 - p, k2) / dot(k2, k2), 0.0, 1.0);
float s = (cb.x < 0.0 && ca.y < 0.0) ? -1.0 : 1.0;
return s * sqrt(min(dot(ca, ca), dot(cb, cb)));
}Parallelogram
float sdParallelogram(vec2 p, float wi, float he, float sk) {
vec2 e = vec2(sk, he);
p = (p.y < 0.0) ? -p : p;
vec2 w = p - e; w.x -= clamp(w.x, -wi, wi);
vec2 d = vec2(dot(w, w), -w.y);
float s = p.x * e.y - p.y * e.x;
p = (s < 0.0) ? -p : p;
vec2 v = p - vec2(wi, 0.0); v -= e * clamp(dot(v, e) / dot(e, e), -1.0, 1.0);
d = min(d, vec2(dot(v, v), wi * he - abs(s)));
return sqrt(d.x) * sign(-d.y);
}Equilateral Triangle
float sdEquilateralTriangle(vec2 p, float r) {
const float k = sqrt(3.0);
p.x = abs(p.x) - r;
p.y = p.y + r / k;
if (p.x + k * p.y > 0.0) p = vec2(p.x - k * p.y, -k * p.x - p.y) / 2.0;
p.x -= clamp(p.x, -2.0 * r, 0.0);
return -length(p) * sign(p.y);
}Isoceles Triangle
float sdTriangleIsoceles(vec2 p, vec2 q) {
p.x = abs(p.x);
vec2 a = p - q * clamp(dot(p, q) / dot(q, q), 0.0, 1.0);
vec2 b = p - q * vec2(clamp(p.x / q.x, 0.0, 1.0), 1.0);
float s = -sign(q.y);
vec2 d = min(vec2(dot(a, a), s * (p.x * q.y - p.y * q.x)),
vec2(dot(b, b), s * (p.y - q.y)));
return -sqrt(d.x) * sign(d.y);
}Pentagon
float sdPentagon(vec2 p, float r) {
const vec3 k = vec3(0.809016994, 0.587785252, 0.726542528);
p.x = abs(p.x);
p -= 2.0 * min(dot(vec2(-k.x, k.y), p), 0.0) * vec2(-k.x, k.y);
p -= 2.0 * min(dot(vec2(k.x, k.y), p), 0.0) * vec2(k.x, k.y);
p -= vec2(clamp(p.x, -r * k.z, r * k.z), r);
return length(p) * sign(p.y);
}Hexagon
float sdHexagon(vec2 p, float r) {
const vec3 k = vec3(-0.866025404, 0.5, 0.577350269);
p = abs(p);
p -= 2.0 * min(dot(k.xy, p), 0.0) * k.xy;
p -= vec2(clamp(p.x, -k.z * r, k.z * r), r);
return length(p) * sign(p.y);
}Octagon
float sdOctagon(vec2 p, float r) {
const vec3 k = vec3(-0.9238795325, 0.3826834323, 0.4142135623);
p = abs(p);
p -= 2.0 * min(dot(vec2(k.x, k.y), p), 0.0) * vec2(k.x, k.y);
p -= 2.0 * min(dot(vec2(-k.x, k.y), p), 0.0) * vec2(-k.x, k.y);
p -= vec2(clamp(p.x, -k.z * r, k.z * r), r);
return length(p) * sign(p.y);
}N-sided Polygon
float sdPolygon(vec2 p, float r, int n) {
float a = atan(p.x, p.y) + 3.141592;
float s = 6.283185 / float(n);
return cos(floor(0.5 + a / s) * s - a) * length(p) - r;
}Star (5-pointed)
float sdStar5(vec2 p, float r, float rf) {
const vec2 k1 = vec2(0.809016994375, -0.587785252292);
const vec2 k2 = vec2(-k1.x, k1.y);
p.x = abs(p.x);
p -= 2.0 * max(dot(k1, p), 0.0) * k1;
p -= 2.0 * max(dot(k2, p), 0.0) * k2;
p.x = abs(p.x);
p.y -= r;
vec2 ba = rf * vec2(-k1.y, k1.x) - vec2(0, 1);
float h = clamp(dot(p, ba) / dot(ba, ba), 0.0, r);
return length(p - ba * h) * sign(p.y * ba.x - p.x * ba.y);
}Heart
float sdHeart(vec2 p) {
p.x = abs(p.x);
if (p.y + p.x > 1.0)
return sqrt(dot(p - vec2(0.25, 0.75), p - vec2(0.25, 0.75))) - sqrt(2.0) / 4.0;
return sqrt(min(dot(p - vec2(0.0, 1.0), p - vec2(0.0, 1.0)),
dot(p - 0.5 * max(p.x + p.y, 0.0), p - 0.5 * max(p.x + p.y, 0.0))))
* sign(p.x - p.y);
}Cross
float sdCross(vec2 p, vec2 b, float r) {
p = abs(p); p = (p.y > p.x) ? p.yx : p.xy;
vec2 q = p - b;
float k = max(q.y, q.x);
vec2 w = (k > 0.0) ? q : vec2(b.y - p.x, -k);
return sign(k) * length(max(w, 0.0)) + r;
}Rounded X
float sdRoundedX(vec2 p, float w, float r) {
p = abs(p);
return length(p - min(p.x + p.y, w) * 0.5) - r;
}Ellipse
float sdEllipse(vec2 p, vec2 ab) {
p = abs(p); if (p.x > p.y) { p = p.yx; ab = ab.yx; }
float l = ab.y * ab.y - ab.x * ab.x;
float m = ab.x * p.x / l; float m2 = m * m;
float n = ab.y * p.y / l; float n2 = n * n;
float c = (m2 + n2 - 1.0) / 3.0; float c3 = c * c * c;
float q = c3 + m2 * n2 * 2.0;
float d = c3 + m2 * n2;
float g = m + m * n2;
float co;
if (d < 0.0) {
float h = acos(q / c3) / 3.0;
float s = cos(h);
float t = sin(h) * sqrt(3.0);
float rx = sqrt(-c * (s + t + 2.0) + m2);
float ry = sqrt(-c * (s - t + 2.0) + m2);
co = (ry + sign(l) * rx + abs(g) / (rx * ry) - m) / 2.0;
} else {
float h = 2.0 * m * n * sqrt(d);
float s = sign(q + h) * pow(abs(q + h), 1.0 / 3.0);
float u = sign(q - h) * pow(abs(q - h), 1.0 / 3.0);
float rx = -s - u - c * 4.0 + 2.0 * m2;
float ry = (s - u) * sqrt(3.0);
float rm = sqrt(rx * rx + ry * ry);
co = (ry / sqrt(rm - rx) + 2.0 * g / rm - m) / 2.0;
}
vec2 r = ab * vec2(co, sqrt(1.0 - co * co));
return length(r - p) * sign(p.y - r.y);
}Vesica (Lens)
float sdVesica(vec2 p, float r, float d) {
p = abs(p);
float b = sqrt(r * r - d * d);
return ((p.y - b) * d > p.x * b) ? length(p - vec2(0.0, b)) : length(p - vec2(-d, 0.0)) - r;
}Moon
float sdMoon(vec2 p, float d, float ra, float rb) {
p.y = abs(p.y);
float a = (ra * ra - rb * rb + d * d) / (2.0 * d);
float b = sqrt(max(ra * ra - a * a, 0.0));
if (d * (p.x * b - p.y * a) > d * d * max(b - p.y, 0.0))
return length(p - vec2(a, b));
return max((length(p) - ra), -(length(p - vec2(d, 0.0)) - rb));
}Arc
float sdArc(vec2 p, vec2 sc, float ra, float rb) {
// sc is vec2(sin, cos) of the arc's aperture angle
p.x = abs(p.x);
return ((sc.y * p.x > sc.x * p.y) ? length(p - sc * ra) : abs(length(p) - ra)) - rb;
}Ring
float sdRing(vec2 p, vec2 n, float r, float th) {
p.x = abs(p.x);
p = mat2(n.x, n.y, -n.y, n.x) * p;
return max(abs(length(p) - r) - th * 0.5,
length(vec2(p.x, max(0.0, abs(r - p.y) - th * 0.5))) * sign(p.x));
}Rendering Functions
Anti-aliased Fill
vec3 sdfFill(float d, vec3 color) {
float aa = fwidth(d) * 1.5;
float alpha = smoothstep(aa, -aa, d);
return color * alpha;
}Outline
vec3 sdfOutline(float d, vec3 color, float thickness) {
float aa = fwidth(d) * 1.5;
float alpha = smoothstep(aa, -aa, abs(d) - thickness);
return color * alpha;
}Glow
vec3 sdfGlow(float d, vec3 color, float intensity, float falloff) {
float glow = exp(-d * falloff) * intensity;
return color * glow;
}