Water Flow Shader
Using Flow Maps to create directional fluid movement in Unity Shadergraph.
Flow Map Texture
Flow Map Logic
A flow map utilizes the Red and Green channels to control panning direction:
- Red Channel: Speed/Direction in X axis.
- Green Channel: Speed/Direction in Y axis.
Applications
This method allows for precise control over water flow around assets. For example, painting a flow map around a rock in a stream ensures the water flows naturally around it rather than panning through it. This adds a significant layer of realism compared to standard panning textures.
Shader Features
Depth Effects
The shader samples the scene depth buffer and compares it against the water surface depth to calculate how shallow or deep any given fragment is. This value drives several visual properties:
- Colour Gradient: Shallow areas shift to a lighter, more transparent tint while deeper water appears darker and more opaque.
- Opacity: The water fades to fully transparent at very shallow intersections, avoiding a hard clip against the shoreline.
Edge & Foam Detection
Where the water intersects geometry — shorelines, rocks, or submerged objects — the depth difference is used to drive a foam mask. A threshold is applied to the depth value so that only pixels within a narrow band of the intersection receive the foam effect.
- Foam Band: Controllable width determines how far from the edge foam appears.
- Animated Noise: A scrolling noise texture breaks up the foam boundary so it never looks static or perfectly uniform.