O'Reilly logo

OpenGL 4 Shading Language Cookbook Second Edition by David Wolff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the compute shader for cloth simulation

The compute shader is well suited for harnessing the GPU for physical simulation. Cloth simulation is a prime example. In this recipe, we'll implement a simple particle-spring based cloth simulation using the compute shader. The following is a screenshot of the simulation of a cloth hanging by five pins. (You'll have to imagine it animating.)

Using the compute shader for cloth simulation

A common way to represent cloth is with a particle-spring lattice. The cloth is composed of a 2D grid of point masses, each connected to its eight neighboring masses with idealized springs. The following figure represents one of the point masses (center) connected ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required