Skip to content
SPH fluid simulation with advanced screen space fluid rendering, using pyopengl and pyopencl.
Python C
Find file
Latest commit 18347a8 @benma Update
typo in README


pysph screenshot

pysph is a demo of:

  • sph (smooth particle hydrodynamics) fluid simulation
  • screen space fluid rendering, based on Simon Green's paper Screen Space Fluid Rendering with Curvature Flow.
  • how to use Python for these kind of things using the excellent pyopengl and pyopencl libraries.
  • how to make and use bindings to the Cg runtime libraries in Python.

Also contained are ports of radix sort and bitonic sort to pyopencl. Based on enjalot's work.

Big thanks to Ian Johnson (enjalot) for the radix/bitonic sort and his excellent tutorial: "Adventures in PyOpenCL".


Run with python [number of particles]. Start with python 8000 and slowly scale the number of particles up.

You can disable the advanced rendering by using python --disable-advanced-rendering [number of particles]. For more options, run python --help.


On Debian Testing (sid): sudo apt-get install python-opengl python-pyside nvidia-cg-toolkit python-numpy python-mako python-pyopencl

And either package providing pyopencl-icd: nvidia-opencl-icd for nvidia users, amd-opencl-icd for ati users.

On Ubuntu: sudo apt-get install python-opengl python-pyside nvidia-cg-toolkit python-numpy python-mako

Unfortunately on Ubuntu (up to 12.04), the package python-pyopencl is outdated and is missing the --cl-enable-gl flag. Using pip also won't work, because it does not configure the package using the --cl-enable-gl flag. You will need to follow the official build instructions here:

If you want to isolate the installation of pyopencl, you can still install it in a virtualenv by using:

$ virtualenv --system-site-packages pysph_env
$ source pysph_env/bin/activate
$ git clone
$ cd pyopencl/
$ python ./ --cl-enable-gl
$ python build
$ python install --prefix=/path/to/pysph_env/ --optimize=1 

$ python /path/to/pysph/

On Windows


Screen space rendering is not complete. It is not optimized for speed. Also, the rendering at the boundaries is not properly dealt with yet, you can see the artefacts in the screenshots.

The program crashes when using an AMD card. I welcome pull requests from AMD users.

Something went wrong with that request. Please try again.