I've posted the same question at GameDev Stack Exchange, but unfortunately I am not getting any response. So I am going to post ( and reword) it here. Hopefully I can get an answer!

I have a terrain ( in the form of mesh/element), and I want to indicate how the water flows in the terrain, subjected to gravity force and the terrain condition ( of course).

A crude way of doing this is to take every single mesh element, then draw the water flow direction from the highest point to the lowest, but I think this will result in a lot of ugly arrows that although can roughly point towards the correct directions, but really don't look nice when view as a whole.

Is there an algorithm, or even better, an existing code implementation ( in the form of well-documented APIs with Windows DLLs, or open source soure code), that allows me to generate the water "flow map" in an elegant, intuitive, look-nice way?


This is a well-studied problem in geomorphological and hydrological modeling, as well as the fields of geomorphometry and terrain analysis.

For visualization, flow accumulation is usually calculated. If every element of your terrain is taken as contributing a value of 1 to the flow, then flow accumulation is the sum of all the flow that passes through a given element. A depiction of this for a landscape might look like this:

Flow accumulation

There are several different flow routing methods. The one you describe is known as D8. A few additional ones are depicted below.

Different flow routing methods

Algorithms for performing the above, along with citations to appropriate references, are available in my library, RichDEM.

  • $\begingroup$ Looks impressive, but what does the legend actually stand for? $\endgroup$ – Graviton May 18 '18 at 3:39
  • $\begingroup$ In this case, number of upstream cells or portion thereof. $\endgroup$ – Richard May 18 '18 at 3:42
  • $\begingroup$ So it would appear that the RED area is the lower ground and BLUE is the upper ground, based on the legend ( shouldn't it be the other way round to conform to the normal topography legend usage)? $\endgroup$ – Graviton May 18 '18 at 4:36
  • $\begingroup$ That's correct. Red has a higher flow accumulation (more upstream cells) so its value is higher. $\endgroup$ – Richard May 18 '18 at 4:50
  • $\begingroup$ Interesting! Gotta check it out! $\endgroup$ – Graviton May 18 '18 at 6:46

There is one program, called IBER, that fits into your request: http://www.iberaula.es/space/53/modules

You can download it for free here: http://www.iberaula.es/space/54/downloads

  • $\begingroup$ Any specific module that I can use? Also, there seems to be no source code, nor a DLL that I can call? $\endgroup$ – Graviton May 16 '18 at 6:39
  • $\begingroup$ I have never used this code before... Only I kew about its existence. You can also programm the Shallow Waters equations by your own... $\endgroup$ – HBR May 16 '18 at 7:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.