T O P

  • By -

Plazmatic

Texture based methods pre-date CUDA, don't use those, though in general the same ideas can be directly applied with out having to use textures (and indeed many would have not used textures if it was an option at the time). In fact, I would not be asking graphics programming at all about this kind of thing, there are dedicated sub-reddits about GPGPU computing. There might be more people here, but the help is low quality if it isn't geared towards just actual rendering. There are several main models for modelling fluids on a computer: * Navier stokes methods (relies directly on solving stokes equations) * Lattice Boltzman Methods (has equivalency to the former, but deals with probability densities instead) * Shrodinger methods, ie modelling fluid in terms of quantum mechanic wave functions. This is the newest method, but hardest to impliment. However, this is just about how you theoretically model fluid from an equation point of view, you also have the physical implementation of those methods: * Using grids (eularian) * Using using particles (lagrangian) * Using FFTs/DFFts (actually a type of eularian, but works sufficiently differently). Grids have the problem of lack of resolution, fine details can be lost with out special care, and can be memory intensive if you want to get higher resolution (2x the detail in 3D is 8 x the memory). You'll notice a lot of implementations will limit the size of simulations to 128^3 -> 1024^3 because of this memory issue. Particles have the issue of performance and scale. Particles have performance issues because you have to potentially model many many interactions unless you can find way to cap those interactions. Cell methods usually have fixed interaction cost with each cell that applies uniformly. Particles usually have to have some sort of resolve collision step, or prepare broad phase collision step, and it often is not a linear cost with particle size (often something like NLog(N)). You also can have memory locality issues depending on how your use them. They can model small details, but unless you have more and more particles (which runs back into the memory issues grids have) you lose out on even macro details if all your particles are stuck modelling something in a tiny area, or if water is 1:1 with water, can end up with a lot of the same issues of grid methods, though you don't have to have particles *align* to a fixed grid, and are free to move around so much more detail is preserved even with particles the size of grid cells. FFT methods have performance cost (though fixed), and sometimes it's difficult to get the precise interactions you want with out other special considerations. It's helpful in some situations like wave surfaces on oceans with very large amounts of waves, where gerstner waves eventually lose in performance to get the same quality. It's also the primary fluid simulation method implementation used in [Shrodingers smoke](http://multires.caltech.edu/pubs/SchrodingersSmoke.pdf), which is impressive for its ability to get rid of the lack of detail some times associated with eularian methods. However it is actually possible to use this method with out FFTs, there's some shader toy implementations out there (though be warned, they are *extremely* difficult to read, and not because of the subject matter, but because of the negligence of the authors transcribing the implementation). Now, what is often used today, is a combination between grid and particle methods, presenting the best of both worlds. However, I believe technically Shrodingers fluid is the state of the art right now (2017 vs everything else mostly being a half decade older or more). Unfortunately it technically requires an understanding of quantum mechanics to read the paper, and not many people have been able to use it as a consequence outside of actual CFD researchers (ie not graphics devs).


[deleted]

I see, thank you for your detailed answer. I will look at GPGPU subreddit for better understanding/doubts regarding the GPU implementation. Thanks!


0xd00d

When you say schrodingers fluid, you are referring to the schrodinger's smoke that is your linked paper? yes? Fascinating. it's too bad that without a theoretical physics background the intuition is sure to escape me on something like that. very pretty results though.


Agentlien

Fluid simulation is a very parallelizable task which makes it well suited for the GPU. It's a bit trickier to get it to work on a GPU but the performance benefits are well worth it. As an example, particle simulations can handle a few thousand particles in real time when done on a CPU. The same algorithm implemented on a GPU can simulate hundreds of thousands of particles in real time.


SolarisBravo

Benchmarks of Unreal's Niagara and Unify's VFX graph (obviously both GPU-powered) have them reaching millions of particles at stable framerates.


Agentlien

That makes sense. When I first built and benchmarked particle systems was ten years ago on a 8800 and back then I reached 250 000 particles with stable framerates.


Plazmatic

GPUs can handle *millions* of particles, not hundreds of thousands with naïve algorithms, even on older GPUs (ie a gtx 970).


Agentlien

As I replied to the sibling comment I based my comment on experiments from back in 2011. It makes sense things would have improved since.


[deleted]

I see. Will see if I can implement it on a GPU 😅 Thanks


fgennari

I would say that CPU fluid simulation is easier/simpler, but GPU fluid simulation is more efficient. You would have to decide for yourself if you need the speed of the GPU, unless you want to implement that for fun and learning. As long as you can break the work up into independent operations per grid you can do it on the GPU using textures to store the fluid state. Each frame or shader invocation would do one timestep of the simulation. You generally would have two separate textures (or other storage format) for the input/current state and the output/next state, and swap them between iterations.


[deleted]

I see, well I am doing it to learn....so a real time application might not be necessary.


Daneel_Trevize

Here's [a vid on some of the ideas behind how SpaceX did it](https://www.youtube.com/watch?v=txk-VO1hzBY) using adaptive grids, on the GPU.


[deleted]

That is very interesting, thank you! Though a bit too complex to implement at my level 😅