Jump to content

Of water and waves


wraitii
 Share

Recommended Posts

Agreed. I think the massive water plane we have at the moment is too inflexible (pun intended) and you can't really do much with it. Maybe eventually we can replace that with multiple small water planes that each has its own elevation, materials, etc and can be placed in Atlas as objects.

Perhaps a helpful metaphor is 'the water table'. Basically, the water table can be thought of as a terrain that is conceptually orthogonal to land terrain, with its own heightmap, tiles with materials, textures and blendings etc. That should also make it easier to do rivers and waterfalls: a waterfall, for instance, is just a drop in the water table, so this is where the engine should throw in special animations, particles, sounds etc.

Edited by zoot
Link to comment
Share on other sites

About the foam, Michael (Mythos_Ruler) created a/or perhaps several textures a couple of years ago that he placed manually. Hmm, looking at them in Atlas (just search for wave in the object tab) I guess they are more like waves, but still, something to check out at least, perhaps it can be useful in one way or another :)

Link to comment
Share on other sites

So I decided to give it a try using Blender's Ocean Sim to create an "animated" ocean texture.

What we should bear in mind is that Realistic Ocean is not seamless at all. If we can't implement a way to make things dinamically generated, or with an actuall animated water-plane (what would be pain, specially for all maps that we have, and maps that would be created by modders) it'll look quite unrealistic(tilled).

Blender's Ocean Sim, gives a realistic way to get seamless waves at least in the X factor(lol). The Y one is not seamless because of the wave dumping, what would look weird, specially on map edges. I tried to fix it by reversing time, what made it look quite awkward, but now looks seamless.

I'm gonna up two videos soon, one with the reversed time way and the other one completely time-foward.

It's a 250 frames animation only using baked displacement texture (Bump maps generated by the OceanSimulator - I can mess up with the setting to create different kinds of atmosphere) on a 4 vertices plane. The main probleman is that the displacement map uses negative values, what, for some reason, blender can't compute. So you'll see the plane. Enough of chit-chat. I shall upload the video.

Link to comment
Share on other sites

In general it looks good. It seams that the waves are reflected at the edges. If you can't change that it might be a good idea to only capture the middle of the calculated area so the reflection cannot be seen. I'd love to play around with this ;)

Link to comment
Share on other sites

This looks good, but fairly small, which could make it look not too good.

For "dynamic" water, the usual cheap system is using two textures and multiplying their normals. For those who have it, start Anno 1404: on low quality settings for the water, if you speed time up, you'll clearly notice it.

The fact that negative values of the displacement map are not computed is bad, that'd look very weird in-game, I think.

Link to comment
Share on other sites

Okay, I got the foam to move to properly simulate wave coming and going on the shores depending on the shore direction. It's still not perfect, but it's better.

Is it in your repo? If my computer can handle it, maybe I can find a way to videofy it.

Link to comment
Share on other sites

Not yet, I had another git problem. Here's a screenshot in the meantime.

(this shows my waviness improvements, Myconid's shadow on the water, Myconid's smoothing of the water texture and the foam)

Of course, it looks much better animated…

post-9128-0-81457500-1342091666_thumb.jp

But I'd rather wait to have added a few more stuffs before uploading (namely, a "distance to shore" parameter for some stuffs.)

Edited by wraitii
Link to comment
Share on other sites

But I'd rather wait to have added a few more stuffs before uploading (namely, a "distance to shore" parameter for some stuffs.)

Wouldn't it be better to use a water depth parameter in those cases? I mean, physically, the water doesn't "know" the distance to the shore...

Link to comment
Share on other sites

It would, but it gives weird results on maps like Oasis, and generally shallow maps. Technically, realistic result would be achieved by calculating "difference in water depth", which I might try.

@Myconid: actually, I ended up using the x-z vectors of the terrain normal, so I get the "direction" of shore. With a bit of blurring, the effect is very nice.

Edited by wraitii
Link to comment
Share on other sites

This looks good, but fairly small, which could make it look not too good.

For "dynamic" water, the usual cheap system is using two textures and multiplying their normals. For those who have it, start Anno 1404: on low quality settings for the water, if you speed time up, you'll clearly notice it.

The fact that negative values of the displacement map are not computed is bad, that'd look very weird in-game, I think.

The negative values are computed whitin the texture, Blender is the one with problems with it. ;)

I can see if I can get you some textures, so you might try it, if you like. The only issue is that they are in .exr and by 100x100 pixels.

://

Link to comment
Share on other sites

It would, but it gives weird results on maps like Oasis, and generally shallow maps. Technically, realistic result would be achieved by calculating "difference in water depth", which I might try.

@Myconid: actually, I ended up using the x-z vectors of the terrain normal, so I get the "direction" of shore. With a bit of blurring, the effect is very nice.

I don't know any relevant fluid dynamics, but I'd imagine what you'd really want is the gradient vector field based off the height map. https://en.wikipedia.org/wiki/Gradient

Edited by Sonarpulse
Link to comment
Share on other sites

Well, what I tried yesterday was "difference between 1 and the Y value of the normal". That gave me an indication of how slopes the ground was, which seemed to work fairly nicely.

I'll try to add some basic wave effect today, and if I succeed or fail, will clean things up and commit.

The last improvement would then be to use the z buffer to have a more realistic water depth.

Edited by wraitii
Link to comment
Share on other sites

Okay, I've committed the foam. No proper waves for now, I'm not sold on how to do it... Should it be on the shader, using the distance to the coast as a reference? A decal?

I'll probably try to add some sea foam on high waviness later.

It only works on GLSL for now (the code is messy and I do a fair amount of calculations, so I haven't yet bothered porting).

Needs recompiling (tell me if something goes wrong, I've had some serious troubles with git at some point and some files may be missing/corrupted).

The effect is scaled with waviness and slope, it's not perfectly realistic but I think the result is quite all-right already.

If someone wants to give a look at the code, I've modified slightly WaterManager.cpp/h and TerrainRenderer.cpp (more).

There's a "WaterTest" demo that showcases it on small island. Check out the Mediterranean Coves scenario, too.

Edited by wraitii
Link to comment
Share on other sites

I'll give it a spin :)

Okay, I've committed the foam. No proper waves for now, I'm not sold on how to do it... Should it be on the shader, using the distance to the coast as a reference? A decal?

The problem I see with using distance to the coast as a reference is that, unless you also take the angle of the coast into account, you might get waves that look a bit off. For instance, against a steep cliff you will want waves that surge 'violently' just before they hit the cliff face, not the cozy type of waves that roll slowly onto a beach.

I only have a very general idea about how shaders work, but could you perhaps use a combination of the water depth at a given point and the gradient of the terrain immediately below it?

EMqxN.png

On great depths, we obviously don't want breakers on the surface. On low depths we do. On steep gradients we want more 'violent' or intense breakers. On gentler gradients, not so much.

Link to comment
Share on other sites

Just realized I did a ton of unuseful stuffs with my texture, I hadn't noticed that PatchRData was about setting up this sort of stuff... I'll update, and keep my texture for other info I might find useful.

@Zoot: I'll probably do something along those lines.

Edit: ah, nah, I'll have to do with the texture for the normals but won't need the heightmap.

Edited by wraitii
Link to comment
Share on other sites

I just did a fair share of optimizations... Zooming as far back as legally allowed, it takes about 7ms on my computer, and the water refraction/reflection take about 5, I think it's okay given the effects.

We might want to consider updating the refraction/reflection maps one at a time for a cheap optimization, too.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...