PhysX 3 Flag Demo (Windows, Mac OS X)

PhysX 3 Cloth/Flag Demo for Windows and Mac OS X

Article index:

1 – The Demo

Here is a small PhysX demo for testing purposes, created with GLSL Hacker. This demo, based on the latest beta version of PhysX 3.3, uses the cloth module of the PhysX engine and shows animated flags made up of 50×50 vertices. The demo also displays some information about the PhysX device using functions available in PhysX 3 SDK. The demo is coded in Lua and shows the use of Lua modules.

PhysX 3 Cloth/Flag Demo, Windows version
PhysX 3 flag demo for Windows, CPU PhysX

This demo is available for Windows 64-bit and Mac OS X 10.{7, 8, 9}. On Windows, the flag simulation can be done with the CPU or the GPU (you can switch between both modes with the G key). On OS X, only the CPU mode is available…

And the Linux version ? It should be available shortly, as soon as I will have fixed a linking issue with the PhysX libs.

PhysX 3 Cloth/Flag Demo, Mac OS X version
PhysX 3 flag demo for Mac OS X

Two words about GPU PhysX. GPU PhysX in the current PhysX 3.3 SDK is only available for cloth and particle modules. And GPU PhysX is available only under Windows. But good news, a trusted source told me that GPU PhysX is also planned for Linux and OS X (the bad news: the release date is not yet planned…).

Now GPU PhysX on Windows. To take advantage of GPU PhysX for clothes, a PhysX application should create more cloth instances than the number of SMX (streaming multiprocessors). The GeForce GTX 780, for example, has 12 SMX, that’s why the demo creates 12 flags to fully exploit the GK110, each cloth being simulated by a SMX (192 CUDA cores). Here are some framerates for the GTX 780 testbed (Intel i5-4670K):
– CPU PhysX: 180 FPS
– GPU PhysX: 280 FPS

And for a GeForce GTX 660 with 5 SMX (then 5 flags) we have:
– CPU PhysX: 270 FPS
– GPU PhysX: 370 FPS

Nice speed boost!

But there is a constraint: the number of vertices of the flag. To get the max performance, the grid that shapes the flag must have around 2500 vertices (50×50) to fit in GPU shared memory. As soon as you use a grid with more vertices (80×80 for example), there’s no difference between the GPU and the CPU. It’s even worse, GPU PhysX getting slower than CPU PhysX!

In the demo, the each flag is made up of 50×50 vertices. You can change this number in the demo (file: PhysX3_Flag_Demo/demo/physx3_flag_v2_gl3.xml, line 100).

CPU PhysX is perfect for low number of clothes or for clothes with more than 3000 vertices. But for many clothes with around 2000 vertices, GPU PhysX is the solution.

PhysX 3 Cloth/Flag Demo, Windows version
PhysX 3 flag demo for Windows, GPU PhysX

I often see, on forums, people saying that PhysX requires a NVIDIA hardware. This is WRONG. If you have a NVIDIA GPU, PhysX can use it (if the developer enabled this feature) to accelerate some simulations. But if you do not have a NVIDIA GPU or do not want to run GPU simulations, all PhysX simulations are done on CPU. That way, you can run a PhysX-based app with any graphics card because only CPU is used for physics computations. The following screenshots show the demo running with a Radeon HD 5770 and with Intel HD Graphics 4000:

PhysX 3 Cloth/Flag Demo, AMD Radeon HD 5770
PhysX 3 flag demo on Radeon HD 5770 using the CPU for simulations

PhysX 3 Cloth/Flag Demo, Intel HD Graphics 4000
PhysX 3 flag demo on Intel HD Graphics 4000 using the CPU for simulations


You can download the PhysX 3 flag demo for Windows and Mac OS X here:
Webmasters: hotlinking is not allowed, please use the post url as download link.

Windows 64-bit
Download PhysX 3 Flag Demo (win64)

Mac OS X 10.7, 10.8, 10.9
Download PhysX 3 Flag Demo (OS X)

Unzip the archive somewhere, and launch PhysX3_Flag_Demo.exe (Win64) or (OS X). The source code (Lua + GLSL) is available in the demo/ folder.

PhysX 3 Cloth/Flag Demo, Windows version
PhysX 3 flag demo for Windows, GPU PhysX

7 thoughts on “PhysX 3 Flag Demo (Windows, Mac OS X)”

  1. Mark

    hah this is fun to play with, thx! I’m using the demo on my 3770k @ 4.5ghz and have been playing around with the amount of flags and the vertices.
    For me at 25 flags with 80×80 they start to do a wave like interaction with each other (getting ~40fps). I’ve also tried 100 and 50 flags. I was wondering where I could modify how much wind there is.

  2. JeGX Post Author

    You can change the wind in
    PhysX3_Flag_Demo/demo/mod_physx3.lua at line 88:
    gh_physx3.cloth_set_external_acceleration(cloth_id,x,y,z) where x,y,z is the acceleration. If you find a cool wind acceleration, don’t hesitate to share it 😉

  3. JeGX Post Author

    The GTX660M supports GPU PhysX so I see two options:
    1/ your graphics drivers
    2/ the mapping of the G key does not work on your machine (???). Try other keys, maybe you will find the right one.

  4. MoT

    ah thanx man, just installed the latest drivers from september and working now… but didnt thought a 2 months earlier driver wont work so i was surprised 😀


  5. -Tj-


    I have a 570GTX and with 15flags it stresses only ~ 60% of my gpu, how can force more flags? for example 18 or 20.

Comments are closed.