"Be not overcome with evil, but overcome evil with good."
- Romans 12:21

Framework 3 (Last updated: February 6, 2017)
Framework 2 (Last updated: October 8, 2006)
Framework (Last updated: October 8, 2006)
Libraries (Last updated: September 16, 2004)
Really old framework (Last updated: September 16, 2004)
Friday, December 19, 2003 | Permalink

Source code
Cloth.zip (474 KB)

This is one of my coolest demos so far in my own humble opinion.
The demo simulates the physics of cloth. It properly interacts with the spheres it falls over and slides off them due to weight. The code to do this is surprisingly simple. The cloth is a rectangular field of points. Each point connects to its neighbors in all directions through imagined springs. For each frame the force, speed and direction is computed through Newton's simple laws of physics, and the position of each point is updated accordingly. In a second pass the normals are evaluated from the position of each point. The result is a very realistic cloth simulation.

The physics is done on the CPU, but is simple enough to be evaluated on the GPU with the upcoming superbuffers extension.

The lighting is done with GLSL, but there's also a vertex lighting fallback for cards that don't support GLSL. This gives lower quality however, but all cards should be able to run this demo.

Updated with more springs, which makes the cloth less stretchable and behave better. A standard GL vertex lighting path was also added.