Niagara 2D Fluid Simulation
Updated: Feb 24
Lately I have been messing around with Niagara's Simulation Stages and boy is it powerful! I was able to do this fast 2D fluid simulation that generates its input with actors movements.
I have a blueprint component that sends the actor velocity and size parameters to niagara. Then I use Simulation stages that I call "New Frame Data" to draw the actors in a Grid2D. In the Red and Green channel I write the velocity and in the Blue channel I write the density. I also sample the render target from the last frame to have the actor draw a "trail" and not constantly overwrite the previous data.
In a second simulation stage I do the grid diffusion that is basically a blur. It's not the physically correct way of doing it, but it is very fast and produce acceptable results.
The third stage is where I do the fluid advection over time. I also have a noise texture input to give the simulation its swirls.
The last stage consists in taking the data from the Grid2D and writing it to a render target so it can be used in materials and what not.
As it can be seen in the video, this system costs about 0.5ms on my RTX 3070 at the moment with 5 interactors. You can add as many as you want for a minimal cost each.
It is the bare bone system at the moment, but I'm planning to add more stuff like additional velocity and density textures, blueprint auto register/unregister of actors etc....
I also want to make a more detailed post about the performances and why I used this instead of blueprint DrawMaterialToRenderTarget or scene capture 2D, so stay tuned.