godot-shaders icon indicating copy to clipboard operation
godot-shaders copied to clipboard

The foam in the 3d water shader is shown incorrectly

Open wojtekpil opened this issue 4 years ago • 8 comments

I'm submitting a...

  • [x] Bug report.
  • [ ] Feature request.

Bug report

What is the current behavior? Depth isn't calculated correctly for object near water. I marked the problem on the attached image: Screenshot from 2020-08-10 22-22-11

What is the expected behavior? There shouldn't be any foam around objects, that aren't in the water.

Tell us the steps to reproduce the bug, and if possible share a minimal demo of the problem.

Just add any MeshInstance to a 3d water demo scene and look at water with camera behind this node.

wojtekpil avatar Aug 10 '20 20:08 wojtekpil

I've issued a fix to the shader, clamping the refracted depth by the 'real' unrefracted depth. If you have anti-aliasing, there can still be a little bit of shimmering or brighter edge, but it should be minimized.

Can re-open if it's too much and explore more fixes, but it's a difficult problem to tackle.

Razoric480 avatar Aug 17 '20 17:08 Razoric480

Thanks for the fix @Razoric480.

@wojtekpil if the shader works, would you mind sharing a screenshot of your game? It's looking real cool, I'd share it on twitter. If you have a website you'd like me to share too I can post it with the screenshot.

NathanLovato avatar Aug 17 '20 20:08 NathanLovato

Hi, @Razoric480, sadly it didn't fix my problem. As for my game, @NathanLovato this is only a simple test scene. Currently I moved to this new one: Screenshot from 2020-08-17 23-26-04 This screenshot shows that, there is still problem: Screenshot from 2020-08-18 22-39-04 I don't have a website but If you are interested I sometimes post my progress on yt: https://www.youtube.com/watch?v=11uUeRN_uyM

wojtekpil avatar Aug 18 '20 21:08 wojtekpil

I'm not too sure how to fix it, unfortunately. If there's some aliasing issues between the depth buffer and the main view, the outline will be visible. But the foam itself should no longer be visible, or at least there shouldn't be much of it at all.

It also looks more like shadows from the trees and bushes rather than foam, but without seeing it in action or being able to play around with the camera angle it's hard to tell.

Razoric480 avatar Aug 18 '20 21:08 Razoric480

Would you have a scene to share with us? Even something simple, without sharing all your assets. That would help us fix the issue. In case you'd prefer not to publish it publicly, you can send it to me via email at nathan [at] gdquest.com and we will only use it to address the bug.

NathanLovato avatar Aug 18 '20 23:08 NathanLovato

Sorry for the late reply. I was tinkering myself with some of the water settings and I think that i found the issue. Here is the simplest demo scene that i could make to reproduce it: https://drive.google.com/file/d/1OAzvjuaWjfH7WlPcnBv0XK1x4ti-FtHd/view?usp=sharing (again, I just modified original file). As you can see there is strange ghosting behind rocks, even though they're floating above water. The problems seems to be "Refraction strength" that distorts UV. If I lower the value of this parameter the problems is almost gone. So probably it's a little bit different issue now.

wojtekpil avatar Aug 21 '20 20:08 wojtekpil

Okay, I see now. I've fixed the depth issue, but the UVs that sample the scene color are still distorted for the refraction. I'll see if I can fix it up.

Razoric480 avatar Aug 21 '20 20:08 Razoric480

Hrm, actually it can't really be fixed without drawing in two passes. The issue being that there's no way to get the screen texture without objects in front of the water. So the objects that are in front of the water end up in the way when it comes time to sampling the screen texture.

Reseting the UVs if the sampled depth lives above the water plane just creates unnatural refraction-less holes.

Would have to draw the scene below the water, save it as a texture somewhere, then draw the scene for the water and objects above it. But then you'd lose the effect of intersecting with the water, short of drawing objects partway submerged partially with a planar shader. image

Razoric480 avatar Aug 21 '20 21:08 Razoric480