I've been attempting to write a Navier Stokes fluid simulation using the Cg language in Unity for a few times now with no luck. Every attempt has only resulted in a blank result. I don't really know how to fix the problem but from what I see, I think the problem might lie in the rendering-to-texture aspect and not the shader themselves so this question might be more Unity-related the shader-related. But just in case, I've read Chapter 38 from GPU Gems and while I don't understand the maths, I do understand the implementation of it. If I'm correct, the order for each timestep of the simulation is:
1. Advection
2. Force application
3. Projection (computing divergence, solving Poisson equations using Jacobi iterations, gradient subtraction)
So there's that. Multiple shaders would be required for each step and I need to have multiple textures to represent the state of fluid such as velocity, density and pressure. Those states each need to have two textures to read and write to, so I can swap them around after each step has been outputted to the correct texture. I also need a temporary divergence texture and a texture to display the final result. My first question is, what format should my textures be in? I've heard that you should use RGBA floating-point textures for each one but I don't know if that's really the case.
Now about the implementation. Like I've said before, I think all my shaders have been written properly as I've compared them to numerous sources including GPU Gems codes and it looks similar. My shaders are based on this three.js implementation and this one. I want my simulation to be setup so that the user can click on the screen to add 'ink' and drag the mouse around to 'add force and velocity' to it. While the second implementation is a working example of a Unity implementation, it's not setup to how I want it to be and the three.js implementation does exactly that. So I combined the Splat shader from the three.js implementation to my own project to achieve the 'add force' that I want but I'm not sure if it's working properly. I've attached my shaders below along with a Unity package file for those who have Unity.
If my shaders have all been written properly, then the problem lies in how to actually display it. Currently, I'm just inputting a density texture into my Render shader to display it but it's giving me a blank result. I don't know if there's anything I had to do first before displaying the fluid so if anyone knows, please let me know.