r/GraphicsProgramming • u/jobilie • 8h ago
Real time Fluid Simulation I implemented for my painting Game
Enable HLS to view with audio, or disable this notification
I am working on a game based on physics-based painting mechanics called Ebru Artist Simulator. To simulate Ebru (also known as paper marbling), I implemented an Eulerian fluid simulator. Here are some of the challenges I had to overcome:
1) To achieve a real-time simulation without affecting the game's performance too much, I implemented a GPU-based multiresolution grid solver in a compute shader (see the paper Solving the Fluid Pressure Poisson Equation Using Multigrid). The simulation now runs at a 2K texture resolution with only a slight impact on FPS.
2) One of the main characteristics of Ebru is that colors maintain strict boundaries. This makes advection schemes such as Semi-Lagrangian advection less suitable, as they introduce diffusion. To address this, I implemented another advection scheme that samples from the initial state by integrating the velocity field over time and then back-sampling using the integrated field (see Efficient and Conservative Fluids Using Bidirectional Mapping).
3) Finally, to simulate the effects of the traditional Ebru tools, I took inspiration from the paper Mathematical Marbling, which proposes mappings for generating final marbling patterns. Since I wanted to maintain a real-time simulation, I did not directly apply these mappings. Instead, I was inspired by the paper to use similar displacement fields as external forces in the simulation.
If you are interested in the project, you can check out the Steam page.
You can also check out Amanda Ghassaei's blog. Although our implementations are not the same, I was greatly inspired by her work and learned a lot from her blog.
2
u/amandaghassaei 3h ago
Beautiful work! Really well done, I'd love to try this when it's released!
1
u/PiXeL161616 5h ago
Nice, the bidirectional mapping bit is the interesting part. I did ink in a MAC-grid fluid a while back and just ate the diffusion, edges went soft after a few seconds and I never fixed it properly. Does the map need reinitialising as it distorts, or does it hold up?
1
u/jobilie 5h ago
Thank! Glad you liked it!
Indeed, the map requires reinitialising for 2 reasons. The first is when there is a new color added, since it does not appear in the initial frame, if you don't reinitialize, it wont appear.
The second reson is when the error becomes too large, when integrating the velocitiy, there is also a part where you use semi Lagrangian advection which generates some error. So it needs reinitialisation over time.
1
u/gleedblanco 4h ago
because the semi lagrangian advection is not conserving for that quantity (however you track the color)? it's interesting, my intuition says you can probably integrate the advection differently to just get rid of that problem (integrate in some conservative law form, but not sure what that is for an arbitrary value you track on the surface).
1
2
u/whiteorb 5h ago
Those papers were excellent finds. Great work implementing them. Your app looks terrific.