Jump to content

Of water and waves


wraitii
 Share

Recommended Posts

The basic idea looks right, but it is quite slow on my (already slow) computer too. I went from 10 to 4 FPS when enabling fancy water on Mediterranean Coves.

Do we have any hope of having the actual water plane sweep up on the shore and then recede?

Link to comment
Share on other sites

It's not too surprising that it's slow: with Myconid's improvements, it's gone from 4 texture sampling to 9, and more calculations are added.

I've committed a new version, which features many small optimizations (won't make it twice faster, but could gain a few FPS). I also added an option in default.cfg to enable/disable advanced effect, so now you can choose between three LOD:

post-9128-0-17078700-1342191509_thumb.jppost-9128-0-73690000-1342191511_thumb.jppost-9128-0-50818900-1342191514_thumb.jp

(the superfancywater adding foam, shadows on water, normal interpolation, which incidentally is what myconid and I added to the basic fancywater.)

Edited by wraitii
Link to comment
Share on other sites

wraitii, that depth buffer thing has been bugging me a lot. I googled up gl_Fragcoord.z and it's indeed supposed to be the value that is written to the depth buffer.

In theory, if you linearise both the depth value from the texture and the depth value from gl_Fragcoord.z you should be able to subtract one from the other and get a meaningful measure of distance between the two. But, it's not that simple it would seem.

Link to comment
Share on other sites

I dunno how I got it to work, but I did the same z_n/z_b stuff to gl_fragCoord.z and the depth texture, and by substracting the two I have a usable value. I dunno if it represents the distance accurately (in game tiles) but it works (I've had to distort the coords along the water normals arbitrarily too, or models close under the surface did weird things).

The only problem is that it looks like gl_fragcoord.z is glitched on some ATI cards…

Edited by wraitii
Link to comment
Share on other sites

I guess the surf is distributed somewhat 'randomly' along the shore with spaces of plain water in between.

Another thing I took away from that (and other) videos is that the foam looks stronger as it is coming in (the 'swash') than it does going out (the 'backwash'). Don't know how that could be done in a shader.

Link to comment
Share on other sites

I dunno how I got it to work, but I did the same z_n/z_b stuff to gl_fragCoord.z and the depth texture, and by substracting the two I have a usable value. I dunno if it represents the distance accurately (in game tiles) but it works (I've had to distort the coords along the water normals arbitrarily too, or models close under the surface did weird things).

Yeah, that's what I was thinking. If you draw that value with gl_fragColor, the resulting colour directly in the centre of the screen should be constant as you zoom in and out with the mousewheel. That is, the depth should be unaffected by the distance from the camera.

The only problem is that it looks like gl_fragcoord.z is glitched on some ATI cards…

Yeah, I've read that somewhere, and as I have an ATI card that may be what I'm experiencing. Anyway, I think it should be possible to calculate it manually in the vertex shader. In fact, if you calculate it yourself it may be possible to avoid linearising it altogether (maybe).

Oh, btw. Looks like superfancywater=true causes a segfault when loading the game.

Edited by myconid
Link to comment
Share on other sites

Can you debug that? I'll see if it's the same cause as mines.

Anyway, I've finished modifying to take the depth buffer into account (using gl_fragcoord). Here's some candy:

The "normal" fancy shader shows the same transparency everywhere. The "super" fancy shows the water getting more tinted with "eye depth". You'll notice that you can make out the blob in the background, underwater: it looks clearer as it's nearer from the surface and eye. I'd need a proper luminance map to make it perfect.

On the tower shot, you'll notice refraction going stronger as the depth rises.

(Still have to fix the shores, though).

post-9128-0-66134700-1342201428_thumb.jppost-9128-0-44726100-1342201434_thumb.jppost-9128-0-56287400-1342201431_thumb.pn

(no foam, waviness is too low).

Edited by wraitii
Link to comment
Share on other sites

Looking really nice :)

I was wondering if you had considered another pre-shader method that might add a little bit to the atmosphere of where water meets shore. A really long time ago (2003), a WFG programmer created a demo of some waves that were similar to how AOM did their effects. It lives here: http://www.wildfireg...s/WaterTest.rar (there is even a wave sprite texture I created years ago in there).

AOM basically used a wave sprite that would move, expand and fade on an edge detected shoreline. You can see it in this video here:

It isn't perfect, but I always thought it looked nice. It might be a nice addition, especially for those that can't use fancy water.

Link to comment
Share on other sites

Anyway, I've finished modifying to take the depth buffer into account (using gl_fragcoord). Here's some candy:

The "normal" fancy shader shows the same transparency everywhere. The "super" fancy shows the water getting more tinted with "eye depth". You'll notice that you can make out the blob in the background, underwater: it looks clearer as it's nearer from the surface and eye. I'd need a proper luminance map to make it perfect.

On the tower shot, you'll notice refraction going stronger as the depth rises.

Sweet!

Link to comment
Share on other sites

I was wondering if you had considered another pre-shader method that might add a little bit to the atmosphere of where water meets shore. A really long time ago (2003), a WFG programmer created a demo of some waves that were similar to how AOM did their effects. It lives here: http://www.wildfireg...s/WaterTest.rar

It basically used a wave sprite that would move, expand and fade on an edge detected shoreline. You can see it in this video here:

That looks really good. Maybe the texture can improved to look a bit more realistic, but I suspect we can properly get better results with this than with a pure shader solution.

Edited by zoot
Link to comment
Share on other sites

1. You have a memory leak on the GPU, because you allocate a texture called "heightName" every frame, but you don't free it.

2. You create heightName as GLuint* and then give that undefined pointer to glGenTextures, which causes things to crash when the driver tries to write to it. Create it as GLuint and adapt the rest of your code.

Link to comment
Share on other sites

By the way:

The "super" fancy shows the water getting more tinted with "eye depth".

I believe you said that you based this on the 'murkiness' setting? Physically, that would not be quite correct as that blue tint is due to the color of water itself, not due to siltation or other murky stuff. (Or maybe I misunderstood and you aren't basing it on murkiness.) Also, did you consider / are you doing the 'color extinction' thing I suggested in the other thread? I suspect that would make for a warmer transition between the ocean and the shore.

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...