I've made a fluid simulation using particles in Unity, but now it is painfully slow because all computations are done using the CPU. In order to make it faster, I need to do computations on the GPU, and I learned that I would have to use compute shaders for that.
The problem is, to make a fluid simulation, I need to make and track each particle and perform collisions on each of them on a certain time interval, and I don't understand how this could be achieved using shaders when the concept of shaders (from what I currently understand) is performing calculations on one already made mesh. Also, I'm using prebuilt physics calculations (rigidbody) in Unity, and would using shaders mean that I would not be able to use these?
How can I make this effect more efficient?
ComputeBuffer
which is an array of a structure you define (say particle position, velocity, maybe some vorticity information, etc). You can then invoke a Compute Shader against that buffer and perform [some operation] for every element in the array. It's up to you to write the code that passes enough information to the compute shader for it to be able to calculate the movement. Ideally you'd just render the results but it's possible to copy them back to the CPU (copying back is VERY slow, so not viable for every frame). \$\endgroup\$