Flowing Rivers
-
- Google Summer of Code Student
- Posts: 1005
- Joined: Wed Jan 08, 2003 9:15 pm
- Location: Lyon, France
- x 49
- Contact:
Flowing Rivers
Hello!
For some time I was wondering how to render rivers flowing on a terrain.
Using a special mask texture to choose where to draw the river in the pixel shader was an obvious solution, but how to make them flow?
Some days ago I've found a post on a blog talking about the way flowing water is simulated in Left4Dead 2 and Portal 2, linking to a Valve document written for the Siggraph.
This paper is mainly about using a "flow map" to scroll the water normal map in a given direction. For me, the most intersting thing in this paper is how the normal maps are scrolled.As I don't really want to generate a flow map, I just used the terrain normal to retrieve the flow direction, because basically, the water always flows the direction of the slope.
Then, having a normal-mapped water flowing in the right direction, I just added some basic fresnel & specular reflexion to give it a nice look.
**!NEW VIDEO!**
Here, a video, my terrain geometry hasn't any true riverbed so sometimes it's quite strange in video, but globally it's working.
The necessary screenshot:
For some time I was wondering how to render rivers flowing on a terrain.
Using a special mask texture to choose where to draw the river in the pixel shader was an obvious solution, but how to make them flow?
Some days ago I've found a post on a blog talking about the way flowing water is simulated in Left4Dead 2 and Portal 2, linking to a Valve document written for the Siggraph.
This paper is mainly about using a "flow map" to scroll the water normal map in a given direction. For me, the most intersting thing in this paper is how the normal maps are scrolled.As I don't really want to generate a flow map, I just used the terrain normal to retrieve the flow direction, because basically, the water always flows the direction of the slope.
Then, having a normal-mapped water flowing in the right direction, I just added some basic fresnel & specular reflexion to give it a nice look.
**!NEW VIDEO!**
Here, a video, my terrain geometry hasn't any true riverbed so sometimes it's quite strange in video, but globally it's working.
The necessary screenshot:
Last edited by Crashy on Fri Sep 17, 2010 6:48 pm, edited 1 time in total.
- PolyVox
- OGRE Contributor
- Posts: 1316
- Joined: Tue Nov 21, 2006 11:28 am
- Location: Groningen, The Netherlands
- x 18
- Contact:
Re: Flowing Rivers
Very nice! I also read that paper a few weeks ago. And you've got some interesting results from it. But I notice it looks a bit strange the way the edges of the river flow towards the middle, as though the water is coming out of the ground. Can you modulate the effect based on the depth of the water, or use the normal of the water surface rather than the normal of the ground to define the flow direction?
-
- Google Summer of Code Student
- Posts: 1005
- Joined: Wed Jan 08, 2003 9:15 pm
- Location: Lyon, France
- x 49
- Contact:
Re: Flowing Rivers
Yep this is what I mentionned when I told it was sometimes strange This was a fast test with resources not really prepared for that.
The solution I see is to have a the terrain surface "flat" in the flow direction where the river mask is applied.
As a future work I plan to add manual terrain editing and river-mask painting directly in my game editor, so this shouldn't be an issue.
Mmhh yes it could be a good addition to the effect. I also plan to add some foam when the flow speed is high, it's a really simple effect to make.Can you modulate the effect based on the depth of the water
I'm afraid I may don't get it, but the water surface normal is the ground normal.use the normal of the water surface rather than the normal of the ground to define the flow direction
The solution I see is to have a the terrain surface "flat" in the flow direction where the river mask is applied.
As a future work I plan to add manual terrain editing and river-mask painting directly in my game editor, so this shouldn't be an issue.
- PolyVox
- OGRE Contributor
- Posts: 1316
- Joined: Tue Nov 21, 2006 11:28 am
- Location: Groningen, The Netherlands
- x 18
- Contact:
Re: Flowing Rivers
Sorry, I thought you were creating some new geometry for the water surface. But actually you made it clear in your post that you are drawing this directly onto the terrain - I just didn't read that carefully!Crashy wrote:I'm afraid I may don't get it, but the water surface normal is the ground normal.
-
- Gnome
- Posts: 389
- Joined: Mon Jul 26, 2010 10:53 pm
- x 22
Re: Flowing Rivers
That's cool looking. Although it looks a little bit odd with water on the edge flowing inward (what are the technical terms for these lol). Perhaps you could do an aggregation so the edge follows towards the average of the slope. And you can modulate the edge, so the edge flows a little bit parallel to the center of the flow. Just my 2 cent, not sure on the details.
- _tommo_
- Gnoll
- Posts: 677
- Joined: Tue Sep 19, 2006 6:09 pm
- x 5
- Contact:
Re: Flowing Rivers
That's a cool tech
But, i still think that having an artist-modelled polygon strip for the water surface is just better
Then you can just make the water flow in the direction of the UVs.
But, i still think that having an artist-modelled polygon strip for the water surface is just better
Then you can just make the water flow in the direction of the UVs.
-
- Google Summer of Code Student
- Posts: 1005
- Joined: Wed Jan 08, 2003 9:15 pm
- Location: Lyon, France
- x 49
- Contact:
Re: Flowing Rivers
Yup but from my experience, modelling a polygon strip that is following the terrain is not something easy. This is part of a rendering shader set designed for a kind of plane-shooter game, so the terrain is vast, and there would be a bunch of polygon-strip to model. That's why I decided to go to use a texture mask that the user is going to paint directly on the terrain in Realtime, so it's faster to make, WYSIWG and avoid the typical problems when using two polygon meshs so close one from another(polygons not really matching, Z-Fight, sort-order because river is transparent, etc).
You could also use WorldMachine to alter the terrain with a BRAND NAME erosion, and then use the flow map that is generated as a mask
( http://wiki.splashdamage.com/index.php/ ... egatexture )
This weekend I'll try to have a better designed terrain and upload a new video
You could also use WorldMachine to alter the terrain with a BRAND NAME erosion, and then use the flow map that is generated as a mask
( http://wiki.splashdamage.com/index.php/ ... egatexture )
This weekend I'll try to have a better designed terrain and upload a new video
-
- Google Summer of Code Student
- Posts: 1005
- Joined: Wed Jan 08, 2003 9:15 pm
- Location: Lyon, France
- x 49
- Contact:
Re: Flowing Rivers
Here is a new video with new resources, the bad behaviours are mostly removed, enough for flight-sim game
I'll post some code tomorrow as some people asked for it.
I'll post some code tomorrow as some people asked for it.
- spacegaier
- OGRE Team Member
- Posts: 4304
- Joined: Mon Feb 04, 2008 2:02 pm
- Location: Germany
- x 135
- Contact:
Re: Flowing Rivers
A lot better, but you can still see a pattern of the river (from the normal map or what ever it is called/used in this case).
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
-
- Gnome
- Posts: 389
- Joined: Mon Jul 26, 2010 10:53 pm
- x 22
Re: Flowing Rivers
that's cool. Yeah I think after you tweak this a little bit it would work perfectly. Maybe support multiple layers so you have effects such as splashes, I don't know. Some more tweaks...
-
- Google Summer of Code Student
- Posts: 1005
- Joined: Wed Jan 08, 2003 9:15 pm
- Location: Lyon, France
- x 49
- Contact:
Re: Flowing Rivers
Yeah I'm looking for a way to reduce the tiling, I'be got the same issue on my ocean shader, if someone has a neat link, it would be perfectspacegaier wrote:A lot better, but you can still see a pattern of the river (from the normal map or what ever it is called/used in this case).
Yup, as said before I'll add some foam when the flow speed is high, and a friend advised me to add some foam on the river shore too.Maybe support multiple layers so you have effects such as splashes, I don't know.
I'll keep you aware of the progress of the shader:)
- PolyVox
- OGRE Contributor
- Posts: 1316
- Joined: Tue Nov 21, 2006 11:28 am
- Location: Groningen, The Netherlands
- x 18
- Contact:
Re: Flowing Rivers
I can't watch the video on my current machine to see the problem, by if you are suffering from tiling of the water surface then maybe you could look at Perlin Noise to generate the water heightmap procedurally? There is a GPU implententation in GPU Gems 2 or 3 (and 1, but that's older). I've used it myself, and could even give you my Ogre 'conversion' in a few days time.Crashy wrote:Yeah I'm looking for a way to reduce the tiling, I'be got the same issue on my ocean shader, if someone has a neat link, it would be perfect
-
- Google Summer of Code Student
- Posts: 1005
- Joined: Wed Jan 08, 2003 9:15 pm
- Location: Lyon, France
- x 49
- Contact:
Re: Flowing Rivers
I reduced the tiling issue using a random noise texture to alter normal maps.
Here is a shader code snippet for the cool stuff:
Here is a shader code snippet for the cool stuff:
Code: Select all
//assume that the water flows down the slope ~=the more horizontal the normal is, the faster the water flows
float2 flowDir = -normal.xz;
//time01 is an uniform parameter = the ogre auto value time_0_1
float phase0 = time01;
float phase1 = (time01<=0.5)?time01+0.5: time01 - 0.5; //yeah this is crappy and non optimal :)
float3 normalT0 = tex2D(riverNoise0, ( Texcoord) + flowDir * phase0 )*2-1;
float3 normalT1 = tex2D(riverNoise1, ( Texcoord) + flowDir * phase1 )*2-1;
float HalfCycle = 0.5;
float flowLerp = ( abs( HalfCycle - time01 ) / HalfCycle );
float3 riverNormal = lerp( normalT0, normalT1, flowLerp );
riverNormal = normalize(riverNormal+noise); //add some noise to the normals
- spacegaier
- OGRE Team Member
- Posts: 4304
- Joined: Mon Feb 04, 2008 2:02 pm
- Location: Germany
- x 135
- Contact:
Re: Flowing Rivers
Really looking great however I still feels a bit like the river is just flat painted on the ground. Perhaps you should carve the river bed out a bit and make a little bit more distinctive border between the grass and the water. Then it would defintely approach "perfect" .
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
-
- Google Summer of Code Student
- Posts: 1005
- Joined: Wed Jan 08, 2003 9:15 pm
- Location: Lyon, France
- x 49
- Contact:
Re: Flowing Rivers
Yes it was planned from the beginning, I'll use some rock or gravel texture for the riverbed( and why not do some faked refraction using the river normal map) in the future.
I'm going to stop working on it for the moment, it was a "proof of concept" for an upcoming project. I have to finish the game engine first
I will update this topic as soon as I've got the effect finalised
I'm going to stop working on it for the moment, it was a "proof of concept" for an upcoming project. I have to finish the game engine first
I will update this topic as soon as I've got the effect finalised
-
- Gnoblar
- Posts: 17
- Joined: Tue Oct 12, 2010 7:08 pm
Re: Flowing Rivers
Have a look at my river:
http://goo.gl/gcXQ
- it doesn't show any tiling (even on very large surfaces like open sea)
- the waves are directional (in the video they change direction going around the ring)
- the waves can have local scaling (in the video, the inner waves are smaller)
- no visible pulsing
This was done in osg. shader code will soon be available
http://goo.gl/gcXQ
- it doesn't show any tiling (even on very large surfaces like open sea)
- the waves are directional (in the video they change direction going around the ring)
- the waves can have local scaling (in the video, the inner waves are smaller)
- no visible pulsing
This was done in osg. shader code will soon be available
- jacmoe
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
Re: Flowing Rivers
Inlining your video, Umpf:
Looks great!
License?
Looks great!
License?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
-
- Gnoblar
- Posts: 17
- Joined: Tue Oct 12, 2010 7:08 pm
Re: Flowing Rivers
Thanks for inlining the video. Except for the cool music, there is no license. you can do whatever you want with it.
-
- Google Summer of Code Student
- Posts: 1005
- Joined: Wed Jan 08, 2003 9:15 pm
- Location: Lyon, France
- x 49
- Contact:
- Xypher
- Gremlin
- Posts: 180
- Joined: Tue Jun 29, 2004 1:35 am
- Location: Richmond, IN; USA
- Contact:
Re: Flowing Rivers
Very nice, it looks great!
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW
http://www.hellbatgames.com
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW
http://www.hellbatgames.com
-
- Gnoblar
- Posts: 13
- Joined: Wed Nov 04, 2009 6:41 pm
Re: Flowing Rivers
Sadly, the "cool music" prevents me from watching the video, because UMG is blocking the video...umpf wrote:Except for the cool music, there is no license.
- jacmoe
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
Re: Flowing Rivers
No code requires no license. I just hope you actually do get back to us with code, Umpf. (Cool username).
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
- SunSailor
- Gnoll
- Posts: 699
- Joined: Sun Jan 02, 2005 5:45 pm
- Location: Velbert, Germany
- x 2
- Contact:
Re: Flowing Rivers
Pretty strange - playing the video shows me a message, that it contains material from a third party and isn't available in my region (germany). Are you using copyright protected music? Because the pictures can't be the problem. Would be nice, if you could recreate the video without such issues, as your work is much appreciated from my side . Would really like to see it.
- Kentamanos
- Minaton
- Posts: 980
- Joined: Sat Aug 07, 2004 12:08 am
- Location: Dallas, TX
Re: Flowing Rivers
Yeah it uses a Queens of the Stoneage song (a very appropriate song too btw...hehe). I guess deals with Germany haven't been negotiated etc.SunSailor wrote:Pretty strange - playing the video shows me a message, that it contains material from a third party and isn't available in my region (germany). Are you using copyright protected music? Because the pictures can't be the problem. Would be nice, if you could recreate the video without such issues, as your work is much appreciated from my side . Would really like to see it.
-
- Gnoblar
- Posts: 17
- Joined: Tue Oct 12, 2010 7:08 pm
Re: Flowing Rivers
hi,
glad you liked the video. Apparently the whole world can watch it but youtube is blocking it in Germany (and only Germany). Perhaps you can try something like 'hotspot shield' (or equivalent) to let youtube think you are not from Germany.
And I will make the source code available soon. I promise, but I want to make sure it is even better than it currently is (lots of hacking went on, and I need to normalize the code a bit to make it readable ). Also I will write some text to go with it, so people will understand what I did.
you will get it, but all the nice comments are appreciated.
glad you liked the video. Apparently the whole world can watch it but youtube is blocking it in Germany (and only Germany). Perhaps you can try something like 'hotspot shield' (or equivalent) to let youtube think you are not from Germany.
And I will make the source code available soon. I promise, but I want to make sure it is even better than it currently is (lots of hacking went on, and I need to normalize the code a bit to make it readable ). Also I will write some text to go with it, so people will understand what I did.
you will get it, but all the nice comments are appreciated.