Is there any way to have a river flow without flow maps?

Good day everyone,

I’m currently making a city building game in Unity and I’m using the default Water example that comes with it. I have a terrain that is 2048 x 2048. For my terrain generation what I do is generate hills using a very basic perlin noise function, then spawn a random river path based on the map seed (so that each seed always produce the same map)

I have a big water plane that sits 2 units below my terrain, and after I have my river path I just lower the terrain following that to expose the water and give a “river” like feel. The problem is right now my water is awful and I think having a stream would greatly increase the appearance of it. I saw some shaders that are using a flowmap but you have to generate the map somehow and it seems the only way is to use some third party tools.

Since the player generates the terrain randomly when a new game begins I must find a way to do this proceduraly. You can see the actual generation in action here: http://dl.dropboxusercontent.com/u/234357896/UnityBuilds.html

Is there any way to have a river that is not straight flow or stream correctly without flow maps or could anyone point me in the right direction to proceduraly generate them?

Thank you very much for your time.

Actually if you check my “Aubergines water shaders” package, you will see there is a builtin editor to paint flow maps. You can use the same function to generate flowmap at runtime too but that requires some coding skills from your part.

EDIT: Or if you prefer a slightly cheaper option, you can check my “Aubergines Editor Tools” package which includes the same flowmap editor but without the water shaders.

If you already generated a river path it shouldn’t be to difficult to add generation of a flow map.
Make sure your water plane is the same size as your terrain. Then with SetPixel paint your flow map texture: U/V = X/Z-Coordinate * 1/TerrainSize
You have to transform the flow direction into colors by yourself (just take a look into your water flow shader and apply the calculations vice versa)…

You can also calculate flow maps at the vertex level if textures are out of the question.

Thank you for the replies everyone, Aubergine, if your package comes with a way I can generate the flowmaps at run time it’s definitly worth the 40$!

BIG BUG thanks you too, I don’t really know what Coordinates should be in your line of code? That’s the way I was planning on going as well, translating each terrain coord into a pixel on the flowmap. It’s probably the way I’ll end up testing for now.

hippcoder: could you elaborate on that method?

Thanks!

Instead of making a giant water plane, have you considered generating the water mesh/s in the shape of the path of the river? If you also generate the uv’s correctly, simply scrolling the texture would make it appear to flow.

Using jRocket’s method i’ve also implemented vertex colors to adjust the refraction of the water on that location :wink: for the finishing touch.

I thought about that method as well, are there any tutorials for “complex” mesh generation like that? The only procedural meshes I do are rectangles , 4 verts, to lay down roads and crop fields. I’d like to know how to properly generate meshes and more specifically their UVs.

Thanks in advance!

It’s going to depend on how you make your river path, but basically you would generate two vertices, each x units away perpendicular to your path, and keep doing that along your path a number of times depending on how dense in resolution you want it to be. The UV’s would be easy to do. One side of the path a 0, the other at 1(in UV space).

I guess that hard part would be getting the direction of the path at any given point along it’s length, or even defining where exactly the river path is if you’re using perlin noise. That I have no idea how to do.