Skip to content

gmmo/forge_demo

Repository files navigation

Cloth Physics Demo - Real-Time Simulation

A cloth physics demonstration using Position-Based Dynamics and Verlet integration, built on The Forge rendering framework.


🎬 Demo Video

Watch the Demo in Action!

Cloth Physics Demo

▶️ Click here to watch the full demo on YouTube

🔥 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

🚀 Quick Start

Setup & Run

  1. Unzip the bundle to your desired location
  2. Navigate to the demo directory:
   cd C:\gmmo\forge\goliveira_demo_cloth
  1. Run the PowerShell script:
   powershell -ExecutionPolicy Bypass -File .\goliveira_demo.ps1

The demo will launch with a hanging cloth mesh, collision sphere, and interactive controls.


🎮 Keyboard 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

✨ Key Features

✅ 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


📁 Architecture Overview

01_Transformations.cpp - Main Application

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)

Physics.h - Cloth Simulation Module

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)

Meshes.h - Procedural Geometry Module

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

Basic.vert.fsl - Vertex Shader

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

Basic.frag.fsl - 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

🛠️ Built With

The Forge - Cross-platform rendering framework

  • Modern graphics API abstraction (DirectX 12, Vulkan, Metal)
  • High-performance resource management
  • Cross-platform shader compilation (FSL)

📚 References

Based on: "Advanced Character Physics" by Thomas Jakobsen (GDC 2001)


👤 Author

Gustavo Oliveira
Powered by The Forge Framework


📺 Watch the Demo

Don't forget to check out the full video demo on YouTube!

About

Cloth simulation with Forge framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors