In this lesson, you will learn how to use flow maps to dynamically distort texture coordinates, allowing surface details to follow non-linear paths like swirling eddies or river bends.
Understanding Flow Maps
A flow map is essentially a specialized texture where the Red and Green channels store vector data representing the direction of movement at every pixel. In Unity, we treat these as (u, v) offsets. Since texture colors range from 0 to 1, we typically remap the data to a range of -1 to 1 to represent movement in all four directions.
The Logic of Flowing
To implement this, you sample the flow map and use it to offset your main surface texture (like a water normal map or foam texture). If you simply added the flow value to your UVs, the texture would slide away. Instead, we use a time-based interpolation to create a seamless loop. By sampling your texture twice—at two different points in time—and blending them based on the flow vector, you prevent the "popping" effect that occurs when a texture resets its loop.
Here is the conceptual flow for your Shader Graph:
- Sample Flow Map: Retrieve the
RGvalues from your flow map texture. - Remap: Use a
Remapnode to convert the 0 to 1 range into -1 to 1. - Multiply by Time: Multiply the flow vector by a
Timenode and aFlow Strengthproperty to control the speed and intensity. - Offset UVs: Add this result to your base
UVcoordinates. - Sample & Blend: Sample your main detail texture using these modified UVs. To make it smooth, use a "Phase" offset for two samples (e.g.,
TimeandTime + 0.5) and blend them using aLerpnode controlled by a triangle wave, ensuring the transition happens exactly when the samples reset.
This technique is superior to simple scrolling because it allows your liquid surface to curve, twist, and follow the specific topology of your meshes, whether it is water rushing around a rock or lava creeping down a crater.
Key Takeaway: By encoding directional vectors into a texture's color channels, you can procedurally warp UV coordinates to simulate complex, non-linear fluid motion that feels alive and reactive to your surface geometry.