A cloth physics demonstration using Position-Based Dynamics and Verlet integration, built on The Forge rendering framework.
🔥 Features Showcased:
- Real-time cloth simulation with 4,096 particles (64×64 grid)
- Interactive sphere collision detection
- Dynamic cloth manipulation (pin/release, edge control)
- Blinn-Phong lighting with directional light rotation
- Built entirely with The Forge rendering framework
- Unzip the bundle to your desired location
- Navigate to the demo directory:
cd C:\gmmo\forge\goliveira_demo_cloth- Run the PowerShell script:
powershell -ExecutionPolicy Bypass -File .\goliveira_demo.ps1The demo will launch with a hanging cloth mesh, collision sphere, and interactive controls.
| Key | Action |
|---|---|
| I | Nudge cloth top edge forward (+Z direction) |
| K | Nudge cloth top edge backward (-Z direction) |
| O | Move collision sphere forward (+Z direction) |
| L | Move collision sphere backward (-Z direction) |
| R | Release cloth pins (top/bottom edges become free) |
| , (comma) | Rotate light direction counter-clockwise |
| . (period) | Rotate light direction clockwise |
| WASD | Camera movement (forward/left/back/right) |
| Mouse | Camera look/rotation |
✅ Real-time cloth physics with 4,096 particles (64×64 grid)
✅ Iterative constraint solver with configurable iterations
✅ Sphere collision detection and response
✅ Dynamic vertex buffer updates (CPU → GPU every frame)
✅ Texture atlas for efficient multi-material rendering
✅ Interactive controls for physics manipulation
✅ Built with The Forge cross-platform rendering framework
Real-time cloth simulation with collision detection
- Scene Objects: 64x64 cloth mesh, collision sphere, directional light marker, floor grid (1x1 to 8x8 tiles)
- CPU Vertex Morphing: Updates cloth vertex positions/normals every frame via physics simulation
- GPU Upload: Copies modified vertices to GPU buffers (positions at offset 0, normals at offset 16)
- Controls: I/K (nudge cloth top edge), O/L (move sphere), R (release pins), , / . (rotate light)
Position-Based Dynamics using Verlet integration
- Algorithm: AccumulateForces() → Verlet() → SatisfyConstraints() → RecalculateNormals()
- Constraints: Horizontal, vertical, and diagonal stick constraints maintain cloth structure
- Collision: Ground plane (Y=0) and sphere collision with projection-based resolution
- Edge Pinning: Top/bottom edges fixed at world positions (configurable release)
Parametric mesh generation with texture atlas support
- Mesh Generators: Planes (XZ/XY/YZ), UV spheres, low-poly arrows, multi-tile floor grids
- Texture Atlas: 2x2 layout (marble, cloth, floor, checkerboard) with UV remapping and bleed prevention
- GPU Upload: Vertex/index buffer creation with CPU-side copies for dynamic animation
- Physics Integration: Extracts edge/center vertex indices for constraint setup
Transforms geometry from model to clip space
- Input: Position, normal, vertex color, UV from CPU-updated buffers
- World Transform: Applies per-object world matrix (gUniformBlock.toWorld)
- Clip Transform: MVP matrix (projection * view * model)
- Output: World position, world normal, vertex color, UV for fragment shader
Blinn-Phong lighting with texture atlas sampling
- Texture Sampling: Reads from 2x2 atlas using interpolated UVs
- Self-Lit Mode: Emits direct color when gUniformBlock.color.w < 0.01 (light marker)
- Lighting: Ambient (20%) + Diffuse (N·L) + Specular (Blinn-Phong, shininess=32)
- Final Color: (ambient + diffuse + specular) × texColor × vertexColor × uniformColor
The Forge - Cross-platform rendering framework
- Modern graphics API abstraction (DirectX 12, Vulkan, Metal)
- High-performance resource management
- Cross-platform shader compilation (FSL)
Based on: "Advanced Character Physics" by Thomas Jakobsen (GDC 2001)
- Paper developed for IO Interactive's Hitman: Codename 47
- Original technique for real-time cloth and ragdoll physics
- Tutorial: https://www.youtube.com/watch?v=erLT9HsllJU&t=278s
Gustavo Oliveira
Powered by The Forge Framework
Don't forget to check out the full video demo on YouTube!
