---
id: "sdf-csg-smooth-min"
title: "SDF Modeling: CSG and Smooth Minimum"
aliases: [smooth union, smin]
domain: "geometry"
stage: "geometry"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, cpu]
year_introduced: 2013
inputs: [sdf]
outputs: [sdf, normals]
style: "both"
dynamic: "dynamic"
cost: "medium"
authority: "Quilez"
url: "https://texelatlas.vercel.app/t/sdf-csg-smooth-min/"
sources_verified_at: "2026-11-29"
---
# SDF Modeling: CSG and Smooth Minimum (Quilez)

> Builds shapes as signed distance functions combined with min, max and negation for union, intersection and difference, plus smooth-min variants that blend primitives organically. The workhorse of shader-based modelling.

## Reach for it when

- combine shapes with union and subtraction in a shader
- want organic blobby blending between primitives
- animate procedural shapes by parameters
- hard edges where two shapes meet look harsh
- model objects entirely in code

## How it works

Each primitive (sphere, box, capsule, torus ...) is a function returning signed distance to its surface. Union is min(a,b), intersection is max(a,b), subtraction is max(a,-b); transforms apply to the sample point before evaluating (translation, rotation, repetition, bending). Replacing min with a smooth minimum, such as the polynomial form min(a,b) minus a bump of height k/4 when the two distances are within k, gives a rounded blend whose radius is k. Variants return a blend factor too, so materials and colours can be mixed. Normals are central or tetrahedral gradient differences. Rendering is by sphere tracing or by meshing the field with marching cubes or dual contouring.

## When to use it

Choose it for procedural modelling, organic blobs, motion graphics, editor tools and anything where the shape must be animated or edited by parameters. Prefer meshes with [Catmull-Clark Subdivision](https://texelatlas.vercel.app/t/catmull-clark-subdivision.md) for authored assets, [Segment Tracing](https://texelatlas.vercel.app/t/segment-tracing.md) or [Enhanced Sphere Tracing](https://texelatlas.vercel.app/t/enhanced-sphere-tracing.md) when the field is non-Euclidean (warped), and baked grid SDFs when the scene is too complex to evaluate per sample.

## Cost

medium — Cost per sample is the sum of all primitives evaluated; scene complexity multiplies with marching steps per pixel.
Measured GPU Weight: 59.62× baseline (heavy) — 1.9614 ms median / 1.9922 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 45.87× baseline (heavy) — 0.7293 ms median (2.69× faster on L4).
Ampere A100 scaling: 35.42× baseline (heavy) — 1.0202 ms median (1.92× faster on A100).

## Failure modes

- Smooth-min distances are not true distances: blended regions shorten or lengthen steps and may need a step scale below 1
- Min/max of two exact SDFs gives only a bound inside and near intersections, which slows or breaks tracing at shallow angles
- Different smooth-min formulations are not associative, so blend results depend on order
- Domain warping and twisting break Lipschitz-1 and cause missed hits or banding
- Evaluating a large tree per sample is slow unless bounding volumes cull primitives

## Engine support

- blender: builtin — `Math node > Smooth Minimum; Geometry Nodes > SDF Grid Boolean` (evidence: https://docs.blender.org/manual/en/5.2/render/shader_nodes/utilities/math/math.html, checked 2026-12-01)

## Dataflow

- Inputs: sdf
- Outputs: sdf, normals
- Platforms: webgl2, webgpu, desktop-gpu, cpu

## Presets

### Smooth-union SDF scene (orbiting blobs, rounded box, floor) (glsl-fragment; rendered 2026-11-29)

```json
{
  "blend_radius": 0.45,
  "max_steps": 96
}
```

```glsl
// GLSL ES 3.0, Shadertoy-style. Smooth-union SDF scene, sphere traced and shaded.
const float K = 0.45;        // smooth-union blend radius (world units)
const int   STEPS = 96;      // max sphere-tracing iterations
const float MAX_DIST = 30.0;
const float EPS = 0.0015;

float smin(float a, float b, float k) {
    // quadratic polynomial smooth minimum
    float h = max(k - abs(a - b), 0.0) / k;
    return min(a, b) - h * h * k * 0.25;
}
float sdSphere(vec3 p, float r) { return length(p) - r; }
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;
}
float map(vec3 p) {
    float t = iTime;
    float d = sdRoundBox(p - vec3(0.0, 0.0, 0.0), vec3(0.55, 0.35, 0.55), 0.12);
    for (int i = 0; i < 3; i++) {
        float a = t * 0.9 + float(i) * 2.0943951;
        vec3 c = vec3(cos(a) * 1.15, 0.25 * sin(t * 1.3 + float(i)), sin(a) * 1.15);
        d = smin(d, sdSphere(p - c, 0.45), K);
    }
    float floorD = p.y + 0.9;
    return smin(d, floorD, K * 0.6);
}
vec3 calcNormal(vec3 p) {
    vec2 e = vec2(1.0, -1.0) * 0.0015;
    return normalize(e.xyy * map(p + e.xyy) + e.yyx * map(p + e.yyx) +
                     e.yxy * map(p + e.yxy) + e.xxx * map(p + e.xxx));
}
float softShadow(vec3 ro, vec3 rd) {
    float res = 1.0, t = 0.03;
    for (int i = 0; i < 40; i++) {
        float h = map(ro + rd * t);
        res = min(res, 8.0 * h / t);
        t += clamp(h, 0.02, 0.4);
        if (res < 0.001 || t > 8.0) break;
    }
    return clamp(res, 0.0, 1.0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = (2.0 * fragCoord - iResolution.xy) / iResolution.y;
    vec3 ro = vec3(3.2, 1.8, 3.6);
    vec3 ta = vec3(0.0, -0.1, 0.0);
    vec3 w = normalize(ta - ro);
    vec3 u = normalize(cross(w, vec3(0.0, 1.0, 0.0)));
    vec3 v = cross(u, w);
    vec3 rd = normalize(uv.x * u + uv.y * v + 1.8 * w);

    vec3 col = mix(vec3(0.75, 0.85, 0.95), vec3(0.25, 0.4, 0.7), clamp(rd.y * 1.5 + 0.3, 0.0, 1.0));
    float t = 0.0;
    bool hit = false;
    for (int i = 0; i < STEPS; i++) {
        float d = map(ro + rd * t);
        if (d < EPS) { hit = true; break; }
        t += d;
        if (t > MAX_DIST) break;
    }
    if (hit) {
        vec3 p = ro + rd * t;
        vec3 n = calcNormal(p);
        vec3 l = normalize(vec3(0.6, 0.8, 0.3));
        float dif = clamp(dot(n, l), 0.0, 1.0) * softShadow(p + n * 0.01, l);
        float amb = 0.5 + 0.5 * n.y;
        float spe = pow(clamp(dot(reflect(-l, n), -rd), 0.0, 1.0), 32.0);
        vec3 base = p.y < -0.85 ? vec3(0.55) * (0.6 + 0.4 * mod(floor(p.x * 2.0) + floor(p.z * 2.0), 2.0))
                                : vec3(0.9, 0.45, 0.25);
        col = base * (dif * vec3(1.0, 0.95, 0.85) * 1.2 + amb * vec3(0.25, 0.3, 0.4)) + spe * 0.4 * dif;
        col = mix(col, vec3(0.75, 0.85, 0.95), 1.0 - exp(-0.0025 * t * t));
    }
    fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(0.4545)), 1.0);
}

```

Attribution: written for this index

## Combines with

- [Sphere Tracing](https://texelatlas.vercel.app/t/sphere-tracing.md): The SDF supplies the step size for ray marching.
- [Jump Flooding Algorithm](https://texelatlas.vercel.app/t/jump-flooding-algorithm.md): Voronoi/distance fields from JFA can be combined with analytic SDFs in the same scene.

## Combination ideas

- [Scanned objects as SDF primitives](https://texelatlas.vercel.app/ideas/captured-sdf-sculpting/)

## Sources

1. [primary] Inigo Quilez Smooth minimum. iquilezles.org. https://iquilezles.org/articles/smin (verified via http on 2026-11-29)
2. [tutorial] Inigo Quilez Distance functions. iquilezles.org. https://iquilezles.org/articles/distfunctions (verified via http on 2026-11-29)

## Cite this entry

Texel. "SDF Modeling: CSG and Smooth Minimum." https://texelatlas.vercel.app/t/sdf-csg-smooth-min/ (accessed 2026-12-01).
