I’ve tried many different approaches to make the shader, watched many different tutorials and read many different articles. But they were simply good waters but not the one I wanted.
So I’ve tried to watch more water refences to map the visuals with the shader knowledge I already had, and noticed I need to use a flowmap to direct the flow of the water then add the current water effect I have and move it along the flowmap direction.
A flowmap is a texture that stores direction only in 2 channels, red and green. almost like the way normal map stores the normal direction of the surface.
Image source on Medium
Exactely like UV coordinate colors, each color represents a direction.
Now how can I create a flowmap in Unity from my current scene? There are some good assets in Asset store like FluXY by Virtual Method which provides a really good flow simulation or FlowmapGenerator by Simon Barsky. but I wanted to know the logic behind it. So I’ve tried to make my own flowmap generator.
After reading many article about the topic, and checking many source codes I have implemented a CPU version of the Navier-Stokes equation in Unity. It will create a 2d simulation of the fluid and will generate a flowmap texture for you. You can define the size of the simulation, the number of iterations and the speed of the simulation.
Check the repository for more information: Open Flowmap