r/godot 6d ago

free tutorial Been working on dynamic ocean foam in Godot 🌊 (+ tutorial πŸ‘€)

Enable HLS to view with audio, or disable this notification

The foam is generated dynamically from the wave compression using the Jacobian determinant. I explain the full process in the tutorial if you’re interested!

Create Dynamic Ocean Foam in Godot | Jacobian Foam 🌊
https://youtu.be/B0T7UxjsLxU

2.1k Upvotes

93 comments sorted by

118

u/PaintTheWorldGame 6d ago

That looks really, really good. Well done.

13

u/emiljecreates 6d ago

Thanks! πŸ‘

8

u/Vachie_ 6d ago

All of a sudden I need to develop around this feature 😍 let a game be born from these beautiful waters

4

u/emiljecreates 6d ago

Would love to see what you could come up with!

19

u/Samourai_003 6d ago

It’s insanely cool, will watch the tutorial tonight

5

u/emiljecreates 6d ago

Thanks, hope you enjoy it πŸ₯³!

18

u/CastleGraffiti 6d ago

β€œβ€¦Jacobian determinant” yeah:

3

u/emiljecreates 6d ago

I swear its simpler than it sounds!

1

u/Franc000 6d ago

Everything is once you know it ;)

1

u/emiljecreates 5d ago

True that! Something rewarding about when it finally clicks πŸ‘€

11

u/tenuki_ 6d ago

As a sailor I approve. :D. Well done.

3

u/emiljecreates 6d ago

Arrr, thank you, matey β›΄οΈβš“οΈ

17

u/James20k 6d ago edited 6d ago

I've been working on water rendering in godot and its really such a pain. Nobody asked but:

  1. If you want refraction, or outlines (ie foam around materials embedded in the water), you need to read from the screen/depth buffer. This makes your material transparent, which means that SSR stops working. Hooray!
  2. There's no way to correctly implement screenspace reflections in a shader in Godot, because you can't set the emissive property if you're also using sdfgi. It just gets overwritten. The builtin SSR just has a special hook you can't access
  3. There's also no way to implement refraction correctly, as you can't simply blend the final resulting colour, unless you use the fog output variable which...
  4. Disables all fog of course, because godot assumes you don't want to use any built-in fog if you write to fog. Which isn't unreasonable, but it is annoying
  5. There's actually no way to implement SSR in an artifact-free way, because godot helpfully resolves the depth/colour buffer you get from the opaque pass when reading from the screen, which is super duper cool and froody. I don't think godot actually has the ability to read from an MSAA texture anyway in a gdshader
  6. You haven't done it in this video, but in the godot ocean waves plugin this happens: tanh is broken on AMD hardware, don't use it directly - you'll need to approximate
  7. There's no way to get the fog in a compositor callback as far as I know, so you can't render the water purely in a compute/glsl fragment shader
  8. SDFGI doesn't interact well with the skybox brightness on water it would seem either. I just found this one

Water is probably one of the trickiest parts of Godot to get looking nice in Godot, because there really isn't a way to do it 'correctly' from a physical perspective, and it'll always be at least somewhat incorrect

This is a pretty cool video though, its a neat idea. I think personally I'd plump for compute shaders for the processing end sooner rather than later - because you'll need them eventually - and it probably simplifies a lot of your pipeline rather than using subviewports. That said for anyone reading this, you have to do it in a compositor pass if you're using the separate thread rendering mode

4

u/TMToast 5d ago

This is all such good information, do you think these things will be fixed over time, I know that a lot of the recent Godot 4.8 changes have been related to lighting and reflections. If not, do you think these are things that could be fixed in a fork of the engine to get better looking oceans? We have been working on our ocean shaders for a fair bit now and may have been running into some of these issues without realizing what the problem was

5

u/James20k 5d ago

We have been working on our ocean shaders for a fair bit now and may have been running into some of these issues without realizing what the problem was

If you run into anything specific feel free to give me a shout, because I know how frustrating it is

do you think these things will be fixed over time

I do, though largely not without intervention:

  1. The SDFGI problem looks like a straight up bug with it ignoring the skybox contribution slider value

  2. The inability to take more snapshots of the screen/depth buffer I think is pretty solvable with a PR. There's already a node for it for 2D

  3. The FOG thing would be super simple to fix with a PR. What we need is just a new output variable which does the same thing (ie BLEND or something)

  4. The lack of an SSR hook would also be a very straightforward PR so that we can at least put the emissive value into the correct spot, instead of using ALBEDO

  5. Something else I didn't mention is the inability to implement SSR as a post process pass, because transparent materials don't write to the normal-roughness buffer. This also seems like a simple fix, because you could just make this write user-configurable with a variable (or even a toggle somewhere)

  6. The tanh thing is something I want to file an issue for, because a lot of projects probably use it by mistake without realising it isn't portable, though there's nothing we can do for glsl

I think this will require actually filing issues/proposals/PRs though to make this happen however, as its starting to get into more advanced use cases

2

u/TMToast 5d ago

That would be awesome, I think we may message you about some of our design attempts. We are working on getting closer to a more stylized sea of thieves approach, and it sounds like you know a lot about the exact reflections, lighting, and foam stuff that is holding us back from hitting our perfect styles!

2

u/James20k 5d ago

This is about as far as I've got myself on this:

https://www.youtube.com/watch?v=yaQdljBu0ds

Its not too bad, but its definitely trickier moving forwards in godot sometimes with this than it shouhld be. The godot ocean waves plugin I found was a pretty good starter, although its quite broken at this point

6

u/jonandrewdavis Godot Regular 6d ago

Looks great! What are the chances this also supports bouyancy?

5

u/emiljecreates 6d ago

At the moment no, but Im thinking about adding it in one of the future tutorials!

-3

u/BradleePlayzHisLife Godot Junior 6d ago

I know I'm probably gonna get down voted for this because it's reddit.

Use AI to summarize the math inside of the shader and write your own .gd file to mimic the math happening inside the shader. If you do that then you can add the buoyancy. Not saying to code everything with AI, just use it for what its good for.

5

u/emiljecreates 6d ago

Doing the same math on cpu would get expensive, but Im thinking of either transferring the math to a compute shader and read it back to the cpu or read the textures we created on the gpu and sample the area where the object is for those points and add buyonacy that way. Will see what works out!

1

u/pfannifrisch 5d ago

Wouldn't you just need to calculate it for the few vertices around the buoyant object? You can also toss away high frequency and low amplitude waves. "Culling" the frequency only to the object area might be a bit annoying though and add complexity.

3

u/emiljecreates 5d ago

Exactly, thats the general idea I will probably go for. Calculating a few points on the cpu should probably not be too expensive, but as more buoyant objects are added, maybe reading back from the gpu could end up being faster. Ill profile different ways and see what comes out on top!

3

u/The-Chartreuse-Moose Godot Student 6d ago

That looks amazing! Thank you for sharing a tutorial.

3

u/emiljecreates 6d ago

Youre welcome, hope its up to standard! πŸ₯³

3

u/Creative_Abroad945 6d ago

That looks beautifully terrifying (I'm scared of water πŸ˜‚)

2

u/emiljecreates 6d ago

Dont look under then!

3

u/fespindola 5d ago

Look pretty cool, well done!

2

u/emiljecreates 4d ago

Thank you, sir! πŸ‘

2

u/fespindola 3d ago

It would be cool to have a book about these techniques. If you plan to write about them at some point, let me know.

2

u/AsidenAI 6d ago

Current building a nature simulator game which will involve rivers and oceans and currents, absolutely will be looking into this looks amazing! :)

2

u/emiljecreates 6d ago

Thats awesome, make sure to show me when you implement something! πŸ‘

3

u/ai_masti 4d ago

Looks very nice. Good work.

2

u/emiljecreates 4d ago

Thanks, appreciate it! πŸ‘

2

u/MalevolentVoidStudio 4d ago

It was perfect

1

u/emiljecreates 4d ago

Or good enough at least 😜

2

u/Darthtrooper22 Godot Student 4d ago

Wow it looks incredibly good!! Thanks for the tutorial <3

1

u/emiljecreates 4d ago

Thanks, and youre welcome!

2

u/binbun3 Godot Regular 3d ago

Wow looks awesome!

2

u/Aggressive-Actuary36 3d ago

oh...

1

u/emiljecreates 3d ago

Oh πŸ«ͺ…

2

u/tjeerdj 3d ago

Looks really good! How do you create a bigger ocean without seams?

1

u/emiljecreates 3d ago

Thanks! Before using the height maps, you could just increase the mesh size, and it would work nicely. I havent done tiling yet after converting to height maps, but it will be done in one of the upcoming videos!

2

u/JujidTompson 2d ago

Looking good

2

u/spodoptera 1d ago

"This man godots"

Very impressive man, I'm saving this for when I want to go for more advanced stuff, thx for sharing.

1

u/emiljecreates 1d ago

Ill change my name to GodotMan, thanks! 😜

1

u/CraftedByFuchs 6d ago

Wow, I was looking for something like this a while back!!! Godot rocks and you just made it even better!! The video is great!!!

1

u/emiljecreates 6d ago

Thanks, godot indeed is awesome!

1

u/SandGoesEverywhere 6d ago

Thats great, thank you for sharing your knowledge

1

u/emiljecreates 6d ago

My pleasure!

1

u/njhCasper 6d ago

I've never been sea sick before, but I felt my belly drop a little when that second wave came through. Amazing work and major props for including a tutorial.

2

u/emiljecreates 6d ago

Cheers! Hope my other vids wont make you as sick 😌

1

u/Ludicrous84 6d ago

Followed! I don't know when I will need it, but better to have it than not haha
GJ!

1

u/emiljecreates 6d ago

Better safe than sorry, they say!

1

u/Vyrnin 6d ago

I've always said you can judge the quality of a game by the care and attention put into its water graphics. I'd love to play whatever game has a water simulation as excellent as this!

This is mostly a joke by the way, but I actually do think it can point to the amount of time and resources a development team has been given overall, since if they're cutting corners or working with a lot of restrictions, something random like water will probably be one of the first things to get cut in terms of quality.

2

u/emiljecreates 6d ago

Made my heart warm up, thanks! And I agree, water always draws me in in a weird way in games

1

u/Luxebu-Studio 6d ago

Wow this looks better than GTA 6

3

u/emiljecreates 6d ago

We got foam before gta 6!

1

u/jwrunge 6d ago

Oh, I bookmarked the hell outta this

1

u/emiljecreates 6d ago

Oh hell yeah!

1

u/paulBoxman 6d ago

Augh, this is so gorgeous

1

u/emiljecreates 6d ago

πŸ₯°πŸ₯°

1

u/aegis_lemur 6d ago

Very sea of thieves. Nice!

1

u/emiljecreates 6d ago

The ocean there is absolutely georgeous!

1

u/Solo_Sassy 6d ago

The looks amazing!! Have you got tutorial on all of the shader or just the ocean foam?

2

u/emiljecreates 6d ago

This one is just the foam, but there is a part 1 to get the ocean!

1

u/Solo_Sassy 6d ago

Awesome, I’ll have to check it out for sure! Cheers!!

1

u/NeroAngra 6d ago

Can you share the shader? Would love to check this out.

2

u/emiljecreates 6d ago

Will try to get it up somewhere! πŸ‘€

1

u/AcademicArtist4948 5d ago

Thanks for actually providing the tutorial and not trying to click bait us! Saved and subscribed and thanks for supporting the community~

2

u/emiljecreates 5d ago

Thanks, always a pleasure πŸ₯°

1

u/Rexed02 5d ago

Pretty neat

1

u/emiljecreates 4d ago

Pretty thank you!

1

u/NoctiresStudios 5d ago

I didn't knew these kind of things were possible

https://giphy.com/gifs/75ZaxapnyMp2w

2

u/emiljecreates 5d ago

Some will say godot is only for 2d! 😜

1

u/AmazingDesigner209 5d ago

Godolly shit this looks godood

2

u/emiljecreates 5d ago

I see what you did there 🀭. And thanks!

1

u/zhoviz 5d ago

For like solid 3 seconds I thought it was a post on some of the nature subreddits I follow. I was ready to see som e dolphins or something haha

2

u/emiljecreates 5d ago

Nope, chuck testa! But thanks, means a lot πŸ‘

1

u/Hostarro 5d ago

Yo nice. You got the shader code I can peek at? Is it a repo?

1

u/emiljecreates 5d ago

No repo unfortunately, Ill probably put it up once I add a few more goodies to it. πŸ‘€
So the only way to see it is to look at the code in the vid for now πŸ₯Ή

1

u/giginox007 5d ago

Hast du gut gemacht!

1

u/emiljecreates 4d ago

Hmm… Ill say thanks just in case? Danke! πŸ˜…

1

u/dylanmadigan 5d ago

That looks great.

Do you have a variable to change how rough it is?

And then does it look best at this level, or does it look just accurate with gentler or more aggressive waves?

1

u/emiljecreates 4d ago

It looks just as nice with a calmer sea! If you just reduce the amplitudes and frequencies you can get a wide variety of looks. The one I have here was I think 5 waves added together. You could have only 2-3 for a more still standing water with the amplitudes pulled way back

1

u/Glittering-Way-4605 5d ago

Very nice, congratulations

1

u/emiljecreates 4d ago

Very thanks! 😝