The handkerchief demo demonstrates self‑collision and crease preservation in the DRIE engine.
*Ricardo Tomasi's three‑week native engine delivers deterministic, crease‑preserving cloth with two‑way collision. The GPU version cuts stutter while keeping CPU‑level accuracy.*
Ricardo Tomasi has spent the last few weeks building a native 3D engine he calls DRIE, aiming to push cloth simulation into real‑time territory. Using sokol_gfx for rendering, he implemented an extended position‑based dynamics (XPBD) solver that now runs in compute shaders. The shift from CPU to GPU shaved the performance gap enough to make stutter a non‑issue, while preserving the deterministic behavior needed for replayable game scenes. DRIE’s feature set—crease preservation, two‑way collision, aerodynamic drag, and a sleep mode—targets developers who need high‑fidelity cloth without sacrificing frame rates. The engine’s demos, from a fluttering handkerchief to a draped sofa, expose both the breakthroughs and the lingering challenges of real‑time physics.
The public demos require a WebGPU‑enabled browser and showcase a suite of visual effects: volumetric fog, dynamic shadows, ambient occlusion, and more. Tomasi’s approach blends low‑level C3 code with AI‑assisted development, turning what would be days of work into five‑minute experiments. The result is a compact, open‑source testbed that pushes the envelope of what GPU‑based cloth can achieve today.
The DRIE engine runs an extended position‑based dynamics (XPBD) solver in compute shaders. Originally a CPU prototype, the GPU port narrowed the performance gap and eliminated noticeable stutter. Features include a deterministic solver for replayable scenes, crease‑preserving logic that lets pleated curtains retain shape, and a tunable coarse‑simulation/fine‑display split for efficiency. Two‑way collision handles both objects and other cloth pieces, a rarity among real‑time engines. Aerodynamic drag adds realism, while a sleep mode shuts down calculations when the cloth is idle, conserving compute cycles.
Tangles arise when point‑based collision lets individual vertices slip through gaps, causing irreversible folds. Tomasi manually tuned a setup that blocks most tangles; the crease‑remembering feature further reduces the risk. When two sheets merge, a spatial hash detects points sharing a region and pushes them apart, keeping layers distinct. The “Handkerchief” demo showcases self‑collision handling, proving the system can keep pleats intact under user interaction.
Rips happen when points slip through sharp corners or thin features; demo spacing is roughly 1.7 cm between points. Drag handles act as tethers, pulling connected points directly toward the force, which feels jello‑like if cascaded through every vertex. Accurate simulations would recompute the entire mesh each frame, a cost too high for real‑time. Tomasi is experimenting with Signed Distance Fields (SDFs) to replace collision meshes, as SDFs naturally round corners. The furniture demo lets users drag cloth across a small table, exposing the unresolved ripping issue.
All demos are written in C3 and compiled to WebGPU via sokol_gfx and the native c3c compiler with Emscripten output. They run in any WebGPU‑enabled browser—Firefox, Chrome, Helium, Safari on Mac and iPhone. The Handkerchief demo also displays sunlight, volumetric fog, dynamic and contact shadows, ambient occlusion, and displacement maps. Controls use WASD + Q/E for camera movement, right‑mouse drag for view, and mouse interaction to pick up cloth. Additional demos let users fire spheres, cut them, or switch bend models with the B key. Development leaned heavily on Claude Code and a mix of LLMs, turning speculative ideas into five‑minute experiments.
He built a small native 3D engine called DRIE that uses sokol_gfx for rendering.
It uses a manually tuned setup, crease‑preserving logic, and a spatial hash that pushes points apart when they occupy the same region.
Points can slip through sharp corners or thin features, especially with a spacing of roughly 1.7 cm, and current tether handling makes the cloth feel jello‑like.
DRIE proves that a compact, GPU‑driven XPBD solver can deliver deterministic, crease‑aware cloth with two‑way collision, all while keeping stutter at bay. The remaining hurdles—tangling under extreme folds and ripping at sharp edges—are being tackled with spatial hashes and Signed Distance Fields. As WebGPU matures, Tomasi’s engine could become a reference point for studios seeking real‑time cloth that doesn’t compromise visual fidelity or performance.
Sources: [Hacker News – Cloth Simulation with XBPD]