Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Godot 4 #6

Open
bemain opened this issue Mar 10, 2024 · 6 comments
Open

Port to Godot 4 #6

bemain opened this issue Mar 10, 2024 · 6 comments

Comments

@bemain
Copy link

bemain commented Mar 10, 2024

Love this project, the implementation is so elegant! Thank you a lot!
For anyone else using a newer version of Godot, I've ported the code to Godot 4. Some things are still missing (the boat, etc.), but the base implementation is there. Enjoy!
https://github.com/BeMain/dynamic-water-godot4

@bemain
Copy link
Author

bemain commented Mar 11, 2024

I also made an attempt at converting the implementation to 2D. It works, but doesn't at all resemble the 3D version. Check it out here:
https://github.com/BeMain/dynamic-water-godot4/tree/2d

@itsnotmetwo
Copy link

@bemain When I run the Godot 4 ported version I get a noise which was not present in 3.5. It's an infinite jitter which never settles. However small the waves are, they expand to the edge. I've gone through the code and even ported a C# version, but I can't seem to be rid of it. I had a suspicion that it might be a format conversion happening which multiplies the ripples (srgba to linear), but adding counter conversion did not solve it, at least with my lacking skill.

A temporary work around I did was to dampen z_height in the simulation shader with 0.996, which funnily enough still didn't remove the jitter. So on top of that I added a epsilon if statement which sets the height to zero if to low. Slowing down the wave speed can also remove the infinite jitter.

Would be nice to figure out the cause of the difference between 3.5 and 4.3.
CBerry22 have a different approach, but suffer the same issue.

@bemain
Copy link
Author

bemain commented Dec 2, 2024

@itsnotmetwo Thanks for sharing. Yes, I remember encountering this issue and not finding a good solution either. I think I did something similar to what you propose in my application, but it's far from ideal. Let me know if you figure something out! Or open a PR ☺️

@bemain
Copy link
Author

bemain commented Dec 2, 2024

The fact that the issue disappears for lower wave speeds got me thinking.
First, maybe it's an issue that occurred when a is too high (I think that's what the variable was called, if my memory doesn't deceive me). So what if we decrease the resolution of the simulation, does that make any difference?

I've also remember having some other issues with wave speed. In my application I was simulating sound waves and not water waves, so I wanted to increase the wave speed as much as possible, but that meant I had to decrease the resolution quite a lot. One thought I had was to run the simulation at a higher framerate than the game (say 2 simulation frames per game frame). That way, maybe we could get the waves to move faster without being limited by having to decrease resolution. But I never implemented it.

@itsnotmetwo
Copy link

I think variable 'a' being to high is a different issue. That occur in the original 3.5 version as well; with resolution 512x512 the wave_speed upper limit is 0.082. There is a warning for it. So double the frame rate for physics means twice the wave speed. That's good idea for higher resolution, though expensive. Can it be done for the simulation class alone?
var delta = 1.0 / ProjectSettings.get_setting("physics/common/physics_fps") var a = c*delta*grid_points a *= a if a > 0.5: push_warning("a > 0.5; Unstable simulation.")

I think the infinite noise generation is a different issue though. There seem to be some multiplier between frames. I added a attenuation of 0.996, but noise still persist, meaning they are generated at a faster rate. Even when the collision source stops producing waves.
vec4 z = a * (texture(z_tex, UV + vec2(pix_size, 0.0f)) + texture(z_tex, UV - vec2(pix_size, 0.0f)) + texture(z_tex, UV + vec2(0.0f, pix_size)) + texture(z_tex, UV - vec2(0.0f, pix_size))) + (2.0f - 4.0f * a) * (texture(z_tex, UV)) - (texture(old_z_tex, UV)); z *= attenuation;

@bemain
Copy link
Author

bemain commented Dec 2, 2024

Moving the conversation to bemain/dynamic-water-godot4#1, since this is a problem with my port, not the original implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants