Course contentsShow
← Unity Game Development
Lesson 630 of 8289. Rendering and VisualsFree lesson

Simulating Flow Maps for Liquid Surfaces

Integrate flow map textures into your shaders to direct the movement of surface details like flowing water or creeping lava.

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:

  1. Sample Flow Map: Retrieve the RG values from your flow map texture.
  2. Remap: Use a Remap node to convert the 0 to 1 range into -1 to 1.
  3. Multiply by Time: Multiply the flow vector by a Time node and a Flow Strength property to control the speed and intensity.
  4. Offset UVs: Add this result to your base UV coordinates.
  5. Sample & Blend: Sample your main detail texture using these modified UVs. To make it smooth, use a "Phase" offset for two samples (e.g., Time and Time + 0.5) and blend them using a Lerp node 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.