Running water, early video

Finally got the flowsim stuff in order, and it supports obstacles. Now I can start working on adding the foam.



Took a picture of a flowmap but it’s before I fixed a copy/paste error (points are missing on the right side). Also it’s a 64x64 image scaled up to 512, so its pretty bad quality.



http://www.jamtlandoutdoors.se/images/dist/flowmap_2.png

Made a video. It’s the last one before release.



http://www.youtube.com/watch?v=D9Mv5VYqID8

9 Likes

Again, really nice. I want to drink from that river :slight_smile:



Will, breaking the surface enable water filter, so it looks like im under water? That would be a nice feature. The flow is very good looking now :slight_smile:

Soooo cool. You should experiment with some different river textures (I mean stone textures, rubble etc.) for the submerged parts, I think that would help emphasize the contrast between the dry/green soil and the river.

@staugaard

Haha I also want to drink. It’s so clear and fresh-looking. That’s why I didn’t put the depth back in (it’s just commented out in the shader tho, still there).



I think a filter could be added. The filter itself I suppose can be similar to the sea water filter. To check if it should be enabled I could for example save a heightmap. Got very much information in the generation class now, flow, volume flow, heights etc. Basically everything that can be used to do anything with the water.

1 Like

You are awesome.



Am I allowed to built my own water system on your awesome work so I can use it in my blocky world once I implement water? It looks so great that I would like to start doing it right now^^ :wink:

@enum

Sure you can do what you want. It’s same licence as jME (like all my stuff is). I think it might be hard tho, because I haven’t written any description of how it works (like a full design document). There’s some info in this thread but that’s pretty much it. And the comments in the code. Also the code will change much during alpha, and until the full graph system has been implemented.



I’m also doing sort of a C layout in many places, because I want to put as much of it as possible into gpu kernels later.

Someday I’ll be able to design and do things fast as people like you @androlo. You barely did a forest lib, then a sky system, and now you’re working with running water. And all that fast, I’m barely able to keep up with my huge schedule for 1 project :stuck_out_tongue:

Thank you androlo :slight_smile:



I guess most of what you are doing there will be new to me so I expect it to be difficult but also instructive.

Code changes are not that problem because I have so much other stuff that has a higher priority right now :frowning:

@shirkit

Well the libs are not yet finished. I think probably next year they can all be considered fully functional libs. Also I did water sky and plants because I need it for apps. When water is working I got what I need, and then it will be a lot slower progress.

This is an extremely ugly screen, but it shows that foam is working now. Notice how the foam is only happening where the water is flowing down from the edge.



There’s a massive fps drop, because I am doing the foam as a separate routine while testing, but the foam is just a black and white texture so im gonna bake it into the normal map alpha channel and just process it in the same routine as the normals. Woun’t even need extra texture fetches. Very efficient.



Anyways, the “turbulence” value is currently based on the mesh normals. The value of normal.y is used in the formula. If that value is 1, the water mesh is horizontal. If it’s 0, the mesh is vertical (like a waterfall for example). The more vertical the water is, the more prominent the foam will be. Not sure how to treat edges yet but I will probably do a more elaborate calculation later (based on edge detection etc.), and write the turbulence value as a mesh attribute.



http://www.jamtlandoutdoors.se/images/dist/foam_water.png



Gonna re-scale and re-orient and tweak etc. Just showing that it works.

4 Likes

I think a well placed particle emitter would make it look more realistic :slight_smile:

A bit better looking screen showing the foam.



http://www.jamtlandoutdoors.se/images/dist/water_foam_2.png

2 Likes

Oooo, that looks good.

I now fixed the stretching of refraction map near screen edges (as described in the last vid), and flickering near river edges because of 0 value flow vectors (also in last vid). Those were the important things that was left to do. Just doing some polishing now.



The river height is a real issue with complex terrains. I deal with it by averaging height values now, but it will require a more intelligent approach later. I think the best way is to do some flattening/smoothing of the affected terrain before applying the actual river-brush.

I think I’m gonna add terrain smoothing/leveling right away. I’m also gonna add some weights and stuff to the smoothing. Been experimenting with a few different types of terrains and found some new problems. One problem is the general shape of the river mesh. It becomes sort of convex-looking if the terrain is shaped that way, which does not look good. I think it should rather make a few steps in that case. That looks a lot better, and it could be fixed for example by incorporating a step function in the terrain smoothing process.



Gonna add the terrain smoothing now. When that’s done I’ll put the code up and call it alpha.

2 Likes

This will be put up tomorrow I think.



Mixed foam into the normal map now, and adapted shader code. I also added the terrain leveling and smoothing. It reads all terrain heights in the affected area then writes the lowest value, so that it never causes land to rise above the current terrain heights.



It is working well now. All the weird stuff seems to be gone. Just gonna run some more tests, to be sure.

2 Likes

I’m uploading the code, but only the lib at this point. EDIT: Actually I was doing that but writing this post took all the time so I’ll finish tomorrow.



I will wait with a demo until after I fixed the river mesh tho. I have figured out how to deal with heights now, and want to add that before doing a demo and release vid.



I decided to use a monotonically decreasing step function as the “core shape” of a river (height-wise). The rivers are 3d shapes but they are directional and use the same height on each side, so the heights are always just 1d arrays, ordered from the starting point to the finish.



http://www.jamtlandoutdoors.se/images/dist/Heights_top.png



http://www.jamtlandoutdoors.se/images/dist/Heights_side.png



This shape is generated by using a simple edge detection algorithm to divide the height array up into segments. Every curve starts out with one segment. This segment is defined by the the first and last element of the array.



http://www.jamtlandoutdoors.se/images/dist/Core_curve.png



In the image, there are two curves, red and blue. The purple part is where they overlap. The red curve is generated from the two end-points (1,4) and another point provided by the edge detection algorithm (3).



The edge detection in the case of the red curve is less responsive to height differences then in the case of the blue curve, generating a new segment only where height differences are very large. In the case of the blue curve it detects another jump. (at 2).



The segments are turned into a step function by reading all heights between each set of consecutive “joints” (like from 1 to 2, from 2 to 3 etc.), and then writing the lowest value to every point. The first point in each pair is always the closed one, except in the last segment where both are closed.



This ensures that water is always lower then the terrain, which in turn ensures that the terrain is never raised during the blending of original and edited terrain (creating weird looking walls around the river).



The algorithm only detects height differences if they are negative btw, so if the river curve in the image was traced from right to left, it would only have one segment, and it’d be the same height as the lowest point on the curve (water should of course not be running upwards).



Finally…



With this method the important points are found, a simple curve is made, and then all the other stuff is based on that. There will be some processing of the heights after. One example would be smoothing out the edge at the top of each waterfall to make it more rounded. Another would be to allow for water to run at an angle, but by interpolating between segments, not just “letting it happen” by having the water follow the terrain. Terrains are way too complex to get predictable results using that approach.



There are many other examples.

4 Likes

This is looking so cool! Definitely the best looking water in JME so far :slight_smile: Is it going to flow faster based on steepness as well as foaming? I suppose a waterfall should move a lot faster in than the part of the river before and after… the extra speed is then caught when the water crashes and it goes slow again. Also, I wonder if its possible to blend the edges where it meets the terrain?

Waterfalls go faster but are thinner than the river they are falling from/to - they accelerate and that “stretches” the water out.



@androlo. I’m not sure what you are trying to achieve with the levelling as by its nature no river will ever run sideways along a slope. The only case where that would happen is if it’s been artificially made to do that (i.e. a canal), in which case walls next to the river on the downward side are actually quite likely. (Usually it’s earth embankments).