zoot Posted July 13, 2012 Report Share Posted July 13, 2012 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? Quote Link to comment Share on other sites More sharing options...
wraitii Posted July 13, 2012 Author Report Share Posted July 13, 2012 (edited) 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:(the superfancywater adding foam, shadows on water, normal interpolation, which incidentally is what myconid and I added to the basic fancywater.) Edited July 13, 2012 by wraitii Quote Link to comment Share on other sites More sharing options...
Spahbod Posted July 13, 2012 Report Share Posted July 13, 2012 Nice job Quote Link to comment Share on other sites More sharing options...
Shield Bearer Posted July 13, 2012 Report Share Posted July 13, 2012 The wait is killing me! Keep up the good work guys EDIT: One thing I noticed is that the foam seems to be at a uniform distance from the shore in all places. This looks a bit unrealistic :/ Quote Link to comment Share on other sites More sharing options...
wraitii Posted July 13, 2012 Author Report Share Posted July 13, 2012 (edited) How would you fix that, Shield bearer? Or rather, what result would you expect?I'm working on using the depthbuffer for (more) realistic water murkiness. Edited July 13, 2012 by wraitii Quote Link to comment Share on other sites More sharing options...
Shield Bearer Posted July 13, 2012 Report Share Posted July 13, 2012 Lol, I'm not a programmer, but I think the distance would be a bit more random Quote Link to comment Share on other sites More sharing options...
zoot Posted July 13, 2012 Report Share Posted July 13, 2012 (edited) I'm quite sure what Shield Bearer is reporting is an artifact of the shader not taking into account water depth and terrain slope. That's my best guess, anyway Edited July 13, 2012 by zoot Quote Link to comment Share on other sites More sharing options...
wraitii Posted July 13, 2012 Author Report Share Posted July 13, 2012 Well, I tried to do it, but I guess my island is either too smooth (highly possible) or my parameters are wrong.I'm still messing around with the depth buffer… Had a fun problem with fishes that made everything wrong. Darn fishes. Quote Link to comment Share on other sites More sharing options...
zoot Posted July 13, 2012 Report Share Posted July 13, 2012 I guess the surf is distributed somewhat 'randomly' along the shore with spaces of plain water in between. Quote Link to comment Share on other sites More sharing options...
myconid Posted July 13, 2012 Report Share Posted July 13, 2012 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. Quote Link to comment Share on other sites More sharing options...
wraitii Posted July 13, 2012 Author Report Share Posted July 13, 2012 (edited) 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 July 13, 2012 by wraitii Quote Link to comment Share on other sites More sharing options...
zoot Posted July 13, 2012 Report Share Posted July 13, 2012 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. Quote Link to comment Share on other sites More sharing options...
myconid Posted July 13, 2012 Report Share Posted July 13, 2012 (edited) 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 July 13, 2012 by myconid Quote Link to comment Share on other sites More sharing options...
wraitii Posted July 13, 2012 Author Report Share Posted July 13, 2012 (edited) Always? By loading, you mean load a map? I get a few segfaults now and then which I'll have to track, but not always.@zoot: I need to know if x is [PI/2;-PI/2 ] or [-PI/2;PI/2], pretty much. Edited July 13, 2012 by wraitii Quote Link to comment Share on other sites More sharing options...
myconid Posted July 13, 2012 Report Share Posted July 13, 2012 I thought it was when loading at first, though it looks like it always segfaults when it's trying to display water. Quote Link to comment Share on other sites More sharing options...
wraitii Posted July 13, 2012 Author Report Share Posted July 13, 2012 (edited) 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).(no foam, waviness is too low). Edited July 13, 2012 by wraitii Quote Link to comment Share on other sites More sharing options...
Wijitmaker Posted July 13, 2012 Report Share Posted July 13, 2012 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. Quote Link to comment Share on other sites More sharing options...
zoot Posted July 13, 2012 Report Share Posted July 13, 2012 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! Quote Link to comment Share on other sites More sharing options...
zoot Posted July 13, 2012 Report Share Posted July 13, 2012 (edited) 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.rarIt 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 July 13, 2012 by zoot Quote Link to comment Share on other sites More sharing options...
myconid Posted July 13, 2012 Report Share Posted July 13, 2012 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. Quote Link to comment Share on other sites More sharing options...
wraitii Posted July 13, 2012 Author Report Share Posted July 13, 2012 1. On the optimized version? I've moved things around, so I may have missed a few stuffs, but I thought the second (optimized) version was right.2. hadn't thought of that, and it seemed to work for me, but I'll change, thanks. Quote Link to comment Share on other sites More sharing options...
myconid Posted July 13, 2012 Report Share Posted July 13, 2012 I have the latest version of your waterShader branch, which doesn't use the depth texture, so I guess... no? Quote Link to comment Share on other sites More sharing options...
wraitii Posted July 13, 2012 Author Report Share Posted July 13, 2012 That's the last I uploaded, so that's a yes. Well, thanks then Quote Link to comment Share on other sites More sharing options...
zoot Posted July 13, 2012 Report Share Posted July 13, 2012 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. Quote Link to comment Share on other sites More sharing options...
zoot Posted July 13, 2012 Report Share Posted July 13, 2012 It lives here: http://www.wildfireg...s/WaterTest.rar (there is even a wave sprite texture I created years ago in there).That thing is password protected. Can you copy it somewhere? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.