Idea:
I was hanging around in Twitter (X) that I saw this beautiful water shader in Blender by @OfNodesAndNoodles I instantly wanted to make it in Unity.
Challenge 1:
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.
Breaking down the problem:
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.
What is a flowmap?
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.
You can learn more about the flowmap from these sources: source 1, source 2, source 3
I need a flowmap:
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.
Open Flowmap
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.
How to use it?
Check the repository for more information: Open Flowmap