Transform Feedback Particle System

 

Download the executable

 

The video above demonstrates a particles system running 700,000 particles fully intractable in real time. This application is written in C++ with OpenGL and all calculations are being done on the GPU in shader files through transform feedback.

 

The primary concept in how transform feedback works is by using two vertex buffer objects and only rendering to the screen every other frame. One buffer is a calculation buffer in which rasterization is turned off and rendered to the buffer rather than the screen. The vertex buffers are then swapped and drawing to the screen happens from the buffer where new calculations happened. This process allows for two different shader files to be developed. The first one only handling calculations while the second one handling drawing.

 

In this implementation, gravity constantly affects all particles on the screen while when the mouse is pressed particles near the mouse will be drawn in. Particles are drawn in slowly when near the edge of the mouse's range and accelerate as they get closer. Movement for mouse gravity is done linear in Y and quadratic in X. Color is based on the distance of the particle from the mouse. Interpolation of color goes from Blue to Red skipping as much green as possible. This is done by having blue and red take up a zone of 40% while green only takes up a zone of 20%. When the mouse is released particles explode out from the mouse point in random directions and velocities.