gdquest-demos / godot-shaders

A large library of free and open-source shaders for the Godot game engine. Here, you'll get 2D and 3D shaders with playable demos.
Other
3.16k stars 191 forks source link

The foam in the 3d water shader is shown incorrectly #18

Open wojtekpil opened 4 years ago

wojtekpil commented 4 years ago

I'm submitting a...

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.

Razoric480 commented 4 years ago

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.

NathanLovato commented 4 years ago

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.

wojtekpil commented 4 years ago

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

Razoric480 commented 4 years ago

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.

NathanLovato commented 4 years ago

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.

wojtekpil commented 4 years ago

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.

Razoric480 commented 4 years ago

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 commented 4 years ago

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