Implicit cloth integration (Baraff-Witkin)
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.
Also known as Large steps in cloth simulation
In the family Simulation & animation, cloth
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | SoftBody3D uses iterative position-based link constraints rather than Baraff-Witkin implicit Euler integration. |
| Unity | None found | |
| Unreal 5.7 | Built in | Chaos Cloth Simulation provides interactive implicit/XPBD garment solvers on Skeletal Meshes docs |
| Blender 5.2 | Built in | Physics Properties > Cloth uses an implicit mass-spring Baraff-Witkin integrator in source/blender/blenkernel/intern/cloth.cc docs |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
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
Choose it when you want physically grounded stiff cloth on CPU with large steps, e.g. offline garments. Prefer Position Based Dynamics / Extended Position-Based Dynamics for game-style cloth, Vertex Block Descent for fast stiff cloth on GPUs, and Verlet integration with relaxation constraints for flags and capes where accuracy does not matter.
Field marks
- 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
Presets
Implicit cloth integration (Baraff-Witkin) — 3D billowing woven drape over collider & stretch/shear stress map
{
"P_WIND_FORCE": 1,
"P_BEND_STIFF": 0.65,
"P_STRESS_SPLIT": 0.38,
"P_DRAPE_SPEED": 1
}Show GLSL (138 lines)
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).
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| implicit-cloth-integration-live | Tesla T4 1920x1080 | 26.3× baseline (heavy) · 0.826 ms / 0.898 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| implicit-cloth-integration-live | NVIDIA L4 1920x1080 | 24.4× baseline (heavy) · 0.385 ms / 0.389 ms · 2.1× faster on L4 | opengl-timer-query · Cross-architecture validation |
| implicit-cloth-integration-live | NVIDIA A100-SXM4-40GB 1920x1080 | 17.1× baseline (moderate) · 0.493 ms / 0.505 ms · 1.7× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Position Based Dynamics; cited by Shape matching (meshless deformation), Soft Step solver / substepping, Vertex Block Descent, Extended Position-Based Dynamics.
Sources
- primaryDavid Baraff, Andrew Witkin (1998). Large steps in cloth simulation. Proceedings of the 25th annual conference on Computer graphics and interactive techniques - SIGGRAPH '98.Verified via crossref · 2026-11-29doi:10.1145/280814.280821
- primaryTiantian Liu, Adam W. Bargteil, James F. O'Brien, Ladislav Kavan (2013). Fast simulation of mass-spring systems. ACM Transactions on Graphics.Verified via crossref · 2026-11-29doi:10.1145/2508363.2508406