For the last project, we built a particle simulation based on Newton's law of universal gravitation. Now, we convert it to a fluid simulation based on Smoothed Particle Hydrodynamics. The particle system simulates an SPH-based gas, meaning it incorporates the effects of pressure, buoyancy, and viscosity.
We do an initial shader pass which calculates the mass density of the gas at the location of each particle. Next, we do our compute shader pass, which incorporates the mass density calculation to compute the pressure, buoyancy, and viscosity forces on each particle in our simulation. Finally, we do some bounds checking to ensure that our particles stay within the bounding box we have defined (drawn in white above), and use GL 4.2's imageStore() to update values if a bounce does occur. After the computation shader runs, we draw the particles to the screen, followed by a quick Gaussian blur pass and a simple compositing motion blur. Adding these two effects slightly decreases frame rate, but leads to a much more gaseous-looking visualization.
Despite some attempts at optimization, the simulation's frame rate was a relatively constant 14fps with 10,000 particles. One possibility for the slowness is the use of glReadBuffer to put my particle positions into a VBO for drawing, instead of binding the FBO to a texture and getting the particle positions using texture lookups.