This project is an implementation of an eulerian fluid simulation on GPU using OpenGL 4.3 compute shaders capabilities.
You will first need to clone the repository and then init the submodules
git clone https://github.com/cgurps/2DFluidSimulation.git [PROJECT_FOLDER]
cd [PROJECT_FOLDER]
git submodule update --init
To compile the project, you will need OpenGL with a version above 4.3 in order to get compute shader capabilities. You will also need Boost installed on your machine. To project uses CMake to generate the Makefile needed for the compilation. You can use these commands to build the executable
mkdir build
cd build
cmake ..
make -j [YOUR_NUMBER_OF_CORES]
You can query the program options using -h.
Each quantities is represented by a texture of 16bits floating points on the GPU. For exact texels query, I use the texelFetch method (which runs faster than using texture2D) and then handle the boundary cases by hand. The bilinear interpolation for the advection step is also computed by hand for better accuracy. The implementation contains three main classes:
GLFWHandleris the GLFW wrapper that contains the OpenGL initilization and the main program loopSimulationBasewhich is a pure virtual function that gives the interface for the simulation. The main loop of the program accesses theshared_texturevariable and display the associated texture on screen. This is where the various textures are created and stored.SimulationFactorywhich contains helpers for computing steps of the simulation (like advection, pressure projection, etc). This class does not allocate GPU memory, but is instead feeded by the simulation loop.
If you (ever) wish to play around this simulation, you should create a new class that inherits from SimulationBase and uses the
SimulationFactory to compute whatever you need to compute. This new class must overload Init(), Update(), AddSplat(),
AddSplat(const int) and RemoveSplat() for the simulation to work.
- LINK: a simple tutorial on fluid simulation
- LINK: this awesome books covers a lot of techniques for simulating fluids (classic!)
- LINK: 2D fluids from GPU gems 1
- LINK: 3D fluids from GPU gems 3
- LINK: the Maccormack method
- LINK: this article explains the reverse method to handle extremas generated by the Maccormack scheme
- LINK: The Runge Kutta method for the particle advection in the semi-Lagragian approach
- tunabrain/gpu-fluid: 2D fluid simulation on the GPU using an hydrid approach (FLIP)
- PavelDoGreat/WebGL-Fluid-Simulation: online fluid simulation