---
id: "implicit-cloth-integration"
title: "Implicit cloth integration (Baraff-Witkin)"
aliases: [Large steps in cloth simulation]
domain: "simulation"
stage: "simulation"
realtime: "interactive"
platforms: [cpu, cuda, desktop-gpu]
year_introduced: 1998
inputs: [mesh]
outputs: [mesh]
style: "photoreal"
dynamic: "dynamic"
cost: "heavy"
authority: "Baraff & Witkin, 1998"
url: "https://texelatlas.vercel.app/t/implicit-cloth-integration/"
sources_verified_at: "2026-11-29"
---
# Implicit cloth integration (Baraff-Witkin) (Baraff & Witkin, 1998)

> Cloth simulation with implicit Euler on a triangle mesh with stretch/shear/bend energies, solved by modified conjugate gradient so large time steps stay stable.

## Reach for it when

- cloth simulation explodes with large time steps
- stiff fabric needs stable integration
- garment simulation jitters or blows up at low frame rates
- want realistic cloth that stretches and bends properly

## How it works

Cloth is a triangle mesh whose internal forces come from condition functions (stretch and shear in the UV plane, bend across edges). Rather than integrate explicitly, the method uses implicit Euler and linearises forces, so each step solves a sparse system `(M - dt df/dv - dt^2 df/dx) dv = dt (f0 + dt df/dx v0)`. The authors solve it with a conjugate gradient variant that enforces per-vertex constraints (pins, contact planes) through a filtering step. Damping forces are included in the Jacobian. Collision is handled with penalty or constraint-filtered response. The result: stable, relatively stiff cloth at time steps of the order of a frame.

## When to use it

Choose it when you want physically grounded stiff cloth on CPU with large steps, e.g. offline garments. Prefer [Position Based Dynamics](https://texelatlas.vercel.app/t/position-based-dynamics.md) / [Extended Position-Based Dynamics](https://texelatlas.vercel.app/t/xpbd.md) for game-style cloth, [Vertex Block Descent](https://texelatlas.vercel.app/t/vertex-block-descent.md) for fast stiff cloth on GPUs, and [Verlet integration with relaxation constraints](https://texelatlas.vercel.app/t/verlet-integration-constraints.md) for flags and capes where accuracy does not matter.

## Cost

heavy — A sparse linear solve per step; cost grows with mesh size and stiffness. Not frame-budget friendly at film resolution.
Measured GPU Weight: 26.31× baseline (heavy) — 0.826 ms median / 0.8981 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 24.37× baseline (heavy) — 0.385 ms median (2.15× faster on L4).
Ampere A100 scaling: 17.11× baseline (moderate) — 0.4927 ms median (1.68× faster on A100).

## Failure modes

- Implicit Euler adds numerical damping: cloth looks heavy and loses wrinkles
- CG solves with few iterations give rubbery or uneven stretch
- Collision handling is the weak part: cloth interpenetrates or locks
- Tuning stretch vs bend stiffness ratios is unintuitive

## Engine support

- blender: builtin — `Physics Properties > Cloth uses an implicit mass-spring Baraff-Witkin integrator in source/blender/blenkernel/intern/cloth.cc` (evidence: https://github.com/blender/blender/blob/main/source/blender/blenkernel/intern/cloth.cc, checked 2026-12-01)
- unreal: builtin — `Chaos Cloth Simulation provides interactive implicit/XPBD garment solvers on Skeletal Meshes` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/cloth-simulation-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: mesh
- Outputs: mesh
- Platforms: cpu, cuda, desktop-gpu

## Presets

### Implicit cloth integration (Baraff-Witkin) — 3D billowing woven drape over collider & stretch/shear stress map (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_WIND_FORCE": 1,
  "P_BEND_STIFF": 0.65,
  "P_STRESS_SPLIT": 0.38,
  "P_DRAPE_SPEED": 1
}
```

```glsl
const float P_WIND_FORCE = 1.0; // P Wind Force [0.1, 2.2, 0.05]
const float P_BEND_STIFF = 0.65; // P Bend Stiffness [0.15, 1.4, 0.04]
const float P_STRESS_SPLIT = 0.38; // P Stress Map Split [0.0, 1.0, 0.02]
const float P_DRAPE_SPEED = 1.0; // P Motion Speed [0.0, 2.5, 0.05]

// Evaluate hanging cloth z-displacement (pinned at top corners y = +0.72, draped over sphere at origin)
float clothSurfaceZ(vec2 xy, float t, float wind, float stiff, out float strainOut) {
  // Pin factor: 0 at top corners (-0.65, 0.72) and (0.65, 0.72), 1 freely billowing below
  float dPinL = length(xy - vec2(-0.62, 0.68));
  float dPinR = length(xy - vec2(0.62, 0.68));
  float freeMask = smoothstep(0.04, 0.36, min(dPinL, dPinR));

  // Stable Baraff-Witkin implicit-damped billowing harmonics (high stiffness dampens fine ripples)
  float damp = exp(-stiff * 0.65);
  float w1 = sin(xy.x * 3.4 - t * 2.1) * cos(xy.y * 2.5 - t * 1.45) * 0.14 * wind;
  float w2 = sin(xy.x * 6.8 + xy.y * 4.2 - t * 3.2) * 0.055 * wind * damp;
  float w3 = cos(xy.x * 11.2 - xy.y * 8.4 + t * 4.1) * 0.018 * wind * damp * damp;
  // Natural catenary drape sag between pins
  float catenary = -0.14 * (1.0 - (xy.x * xy.x) * 1.8) * smoothstep(-0.7, 0.7, xy.y);

  float z = (w1 + w2 + w3 + catenary) * freeMask;

  // Collision bulge over orbiting obsidian sphere behind cloth
  vec2 spXY = vec2(0.24 * sin(t * 0.65), -0.08 + 0.12 * cos(t * 0.85));
  float rSp = length(xy - spXY);
  float bulge = 0.28 * exp(-rSp * rSp * 7.5);
  // Radial compression folds radiating around the collider bulge
  float radialFolds = 0.024 * cos(atan(xy.y - spXY.y, xy.x - spXY.x) * 7.0 + t * 0.8) * exp(-rSp * 3.2) * smoothstep(0.06, 0.24, rSp);
  z += bulge + radialFolds;

  // Approximate warp/weft tensile strain (highest near pin anchors and over collider dome)
  float pinTension = exp(-min(dPinL, dPinR) * 4.2);
  float domeTension = exp(-rSp * rSp * 6.5);
  strainOut = clamp(pinTension * 0.92 + domeTension * 0.78 + abs(w2) * 3.2, 0.0, 1.0);
  return z;
}

// Signed distance to finite cloth sheet with thickness
float mapCloth(vec3 p, float t, float wind, float stiff) {
  float st;
  vec2 clampedXY = clamp(p.xy, vec2(-0.68, -0.68), vec2(0.68, 0.68));
  float zSurf = clothSurfaceZ(clampedXY, t, wind, stiff, st);
  vec2 edgeD = abs(p.xy) - vec2(0.68, 0.68);
  float outXY = length(max(edgeD, 0.0));
  float dz = abs(p.z - zSurf) - 0.014;
  return (outXY > 0.0) ? sqrt(outXY * outXY + max(dz, 0.0) * max(dz, 0.0)) : dz;
}

vec3 calcClothNormal(vec3 p, float t, float wind, float stiff) {
  float e = 0.008;
  float s0, sx, sy;
  float z0 = clothSurfaceZ(p.xy, t, wind, stiff, s0);
  float zx = clothSurfaceZ(p.xy + vec2(e, 0.0), t, wind, stiff, sx);
  float zy = clothSurfaceZ(p.xy + vec2(0.0, e), t, wind, stiff, sy);
  return normalize(vec3(-(zx - z0) / e, -(zy - z0) / e, 1.0));
}

vec3 stressPalette(float s) {
  s = clamp(s, 0.0, 1.0);
  vec3 c0 = vec3(0.08, 0.24, 0.56);
  vec3 c1 = vec3(0.14, 0.84, 0.72);
  vec3 c2 = vec3(0.98, 0.74, 0.18);
  vec3 c3 = vec3(0.98, 0.22, 0.34);
  if (s < 0.35) return mix(c0, c1, s / 0.35);
  if (s < 0.70) return mix(c1, c2, (s - 0.35) / 0.35);
  return mix(c2, c3, (s - 0.70) / 0.30);
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float tAnim = iTime * max(P_DRAPE_SPEED, 0.0);
  float wind = clamp(P_WIND_FORCE, 0.05, 2.4);
  float stiff = clamp(P_BEND_STIFF, 0.1, 1.6);
  float split = clamp(P_STRESS_SPLIT, 0.0, 1.0);

  vec3 ro = vec3(0.18 * sin(tAnim * 0.28), 0.04, 2.25);
  vec3 rd = normalize(vec3(uv, -1.55));

  vec3 col = mix(vec3(0.03, 0.04, 0.065), vec3(0.09, 0.115, 0.165), smoothstep(-0.55, 0.55, uv.y));

  float t = 0.4;
  bool hit = false;
  for (int i = 0; i < 64; i++) {
    float d = mapCloth(ro + rd * t, tAnim, wind, stiff);
    if (d < 0.0025) { hit = true; break; }
    t += d * 0.65;
    if (t > 6.5) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    vec3 n = calcClothNormal(p, tAnim, wind, stiff);
    if (dot(n, -rd) < 0.0) n = -n;

    float strain;
    clothSurfaceZ(p.xy, tAnim, wind, stiff, strain);

    // Fine procedural twill weave + structural warp/weft spring mesh lines
    vec2 wuv = p.xy * 26.0;
    float twill = 0.5 + 0.5 * sin(wuv.x * 3.14159 + sin(wuv.y * 3.14159)) * cos(wuv.y * 3.14159);
    vec2 springG = abs(fract(p.xy * 11.0 - 0.5) - 0.5);
    float springWire = smoothstep(0.055, 0.012, min(springG.x, springG.y));

    vec3 l1 = normalize(vec3(0.62, 0.78, 0.68));
    vec3 l2 = normalize(vec3(-0.72, -0.25, 0.55));
    float diff1 = max(dot(n, l1), 0.0);
    float diff2 = max(dot(n, l2), 0.0);
    // Charlie / velvet sheen grazing highlight characteristic of woven cloth
    float sheen = pow(1.0 - max(dot(n, -rd), 0.0), 2.6) * 0.46;

    // Rich crimson-burgundy woven cloth (right) vs Baraff-Witkin warp/weft strain & spring grid (left)
    vec3 fabricAlb = mix(vec3(0.58, 0.14, 0.18), vec3(0.76, 0.24, 0.26), twill * 0.55);
    // Gold embroidered border hem
    float hem = smoothstep(0.61, 0.65, max(abs(p.x), abs(p.y)));
    fabricAlb = mix(fabricAlb, vec3(0.88, 0.70, 0.28), hem * 0.85);
    vec3 fabricCol = fabricAlb * (0.24 + 0.86 * diff1 + 0.24 * diff2) + vec3(0.95, 0.68, 0.62) * sheen;

    vec3 stressCol = stressPalette(strain) * (0.34 + 0.76 * diff1) + vec3(0.35, 0.55, 0.85) * sheen * 0.5;
    stressCol = mix(stressCol, vec3(0.95, 0.98, 1.0), springWire * 0.42);

    col = (screenX < split) ? stressCol : fabricCol;

    // Highlight pinned top corner anchor grommets
    float dPin = min(length(p.xy - vec2(-0.62, 0.68)), length(p.xy - vec2(0.62, 0.68)));
    col = mix(col, vec3(1.0, 0.88, 0.38), smoothstep(0.055, 0.03, dPin));
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.97, 1.0), sep);

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).

## Sources

1. [primary] David Baraff, Andrew Witkin (1998) Large steps in cloth simulation. Proceedings of the 25th annual conference on Computer graphics and interactive techniques  - SIGGRAPH '98. https://doi.org/10.1145/280814.280821 (verified via crossref on 2026-11-29)
2. [primary] Tiantian Liu, Adam W. Bargteil, James F. O'Brien, Ladislav Kavan (2013) Fast simulation of mass-spring systems. ACM Transactions on Graphics. https://doi.org/10.1145/2508363.2508406 (verified via crossref on 2026-11-29)

## Cite this entry

Texel. "Implicit cloth integration (Baraff-Witkin)." https://texelatlas.vercel.app/t/implicit-cloth-integration/ (accessed 2026-12-01).
