Virtual Pipes: A Simple and Efficient Method for Simulating Water Over Terrain

This article introduces a simple and efficient method for simulating water flow over terrain in games – the virtual pipes method. Based on shallow water equations and using a staggered grid, this method treats water flow as columns connected by imaginary pipes. Water flow is accelerated based on water level differences, and outflow scaling prevents negative water amounts. The author details the three steps: flow acceleration, outflow scaling, and water column updating, providing code examples. This method is easy to understand, computationally efficient, and suitable for games requiring terrain modification and water simulation, such as city builders. While it has limitations such as lacking inertia and velocity diffusion, it's practical for most game scenarios.