FFT-based ocean-wave rendering, implemented in Godot

(github.com)

790 points | by RafelMri 2 days ago ago

97 comments

  • kamranjon a day ago ago

    The other two Godot repos by this person are very interesting as well. I love the level of detail they add to explaining their repos. This one is particularly interesting: https://github.com/2Retr0/GodotGaussianSplatting

    Wonder if they are a student, they seem to cite other work frequently and have a strong grasp on recently published materials.

    • codetrotter a day ago ago

      > Wonder if they are a student

      Seems like they might be.

      One of their repos has this title and description:

      > ENGR96A-coursework

      > Relevant coursework for ENGR 96A Introduction to Engineering Design F23

      And F23, judging by the dates of the commits in that repo means Fall 2023.

      Of course, it could be that this and other UCLA courses referenced in the repos are open for everyone. So maybe you don’t have to be enrolled as a traditional student at UCLA to take them.

  • jesperwe 2 days ago ago

    20 years ago I could spend months tweaking ocean surface in renders and not get even close to that. Amazing how good this is!!

    Although the demo clip feels a bit exaggerated (saying this having over 50k Nm open water ocean sailing in my logbook). Waves that sharp and high would need the wind blowing a lot stronger. But I am sure that is just a parameter adjustment away!

    Since it is in Godot I assume the rendering is real time? Does it need a monster GPU?

    • aithrowawaycomm a day ago ago

      This is not a criticism, just an observation: it looks like what I imagine an ocean of hot corn syrup would look like (after dyeing it blue). The viscosity seems right; possibly the surface tension is not what ocean water would have (a colloid of salty H2O and biomaterial, which is common in real-world experience but quite ugly for computational fluid dynamics).

      Also note that the ocean spray here is a post-hoc effect, but for a real ocean the spray dulls the sharpness of the waves in a way that will be (vaguely) apparent visually.

      Of course there's almost no "physics" in this elegant, simple, and highly effective model, so I want to emphasize that suggesting directions to poke around and try things should not be construed as an armchair criticism.

      • hackable_sand a day ago ago

        This is literally a criticism.

        • aithrowawaycomm a day ago ago

          A) It would be a criticism if I thought these effects could be plausibly rendered with a similar FFT algorithm, but that seems unlikely to me. I think these results are "highly effective" given the toolset, which is not attempting to emulate the actual physics.

          B) This project is not an all-out attempt to make lifelike water, it is described as an experiment. I am making an observation about the result of the experiment, not criticizing the project for failing to meet standards it wasn't holding itself to.

          • westurner a day ago ago

            Neat that FFT yields great waves.

            But ultimately, does that model model vortexes or other fluid dynamics?

            Can this model a fluid vortex between 2-liter bottles with a 3d-printable plastic connector?

            Curl, nonlinearity, Bernoulli, Navier-Stokes, and Gross-Pitaevskii are known tools for CFD computational fluid dynamics with Compressible and Incompressible fluids.

            "Ocean waves grow way beyond known limits" (2024-09) https://news.ycombinator.com/item?id=41631177#41631975

            "Gigantic Wave in Pacific Ocean Was the Most Extreme 'Rogue Wave' on Record" (2024-09) https://news.ycombinator.com/item?id=41548417#41550654

            • aithrowawaycomm 21 hours ago ago

              Keep in mind that this project is aimed at video game developers, not oceanographers :) The point is to get something cheap and plausible, not to solve Navier-Stokes with finite element methods.

        • CognitiveLens a day ago ago

          This not a criticism, but the comment you are replying to is a critique, not a criticism.

    • lloeki a day ago ago

      > 20 years ago I could spend months tweaking ocean surface in renders and not get even close to that.

      There are tons of videos now about that making the whole thing (somewhat) more approachable, but there are still a lot of pitfalls!

      One of my favourites on the subject: https://m.youtube.com/watch?v=yPfagLeUa7k

      This one is nice too: https://m.youtube.com/watch?v=kGEqaX4Y4bQ

    • sails a day ago ago

      Agree, based on the clips, it looks a bit random.

      I think it is looks to be very good, and probably the best I’ve seen having given it a cursory search recently to see what was possible.

      In terms of what I’d like to see, open ocean waves generally have more rhythm, I’d be very interested to see a simulation of 15 knots of wind blowing over 1km for a few hours and see if that matches what I observe, which would be relatively organised wave trains (sets) that build and disperse.

    • pjmlp a day ago ago

      Back when I graduated, doing particle engines, with marching cubes and stuff like that, was a graduation thesis project.

      Nowadays it is a check box on a game engine, one of many.

      People don't imagine how good they have it with modern engines.

      Not to take any value out of this work, this is a great achievement and kudos to the author, only making the point how good we have nowadays.

      • kevindamm a day ago ago

        Back when I graduated I was still holding my breath for the patent expiration on marching cubes, GPUs were still being made for PCI and even ISA slots, you could find some game engines but you would have a better time writing one specialized for the type of game or graphics you were targeting.

        Things really have improved a lot.

        • pjmlp a day ago ago

          I guess we might have a similar age, first computer Timex 2068. :)

          • kevindamm a day ago ago

            sounds like it, my first computer was an Atari 800 XL that shared the family TV as its monitor (and fortunately there was an RF switch to toggle between it and the antenna so we worked out a kind of timesharing system)

            • pjmlp a day ago ago

              Sounds familiar. :)

    • ryanjshaw a day ago ago

      There's 2 demo clips, the second one shows quite a number of parameters you can adjust.

      • pixelatedindex a day ago ago

        I think the point is that these parameters you adjust are being rendered near real-time, whereas back in their days you’ll have to enter these values, and add custom tweaking because the hardware just wasn’t powerful enough to do the things we can do now at many times the speed. Not to mention the vast improvement in mileage for your time.

        • dylan604 a day ago ago

          yeah, the "in real time" is what kills me. the old joke of blue bar races, rendering, buffering, and any of the other things us gray beards had to put up with is just unimaginable to the whippersnappers of today.

    • matsemann a day ago ago

      > I could spend months tweaking ocean

      I have a game project. But I always get nerd sniped by cool game stuff, and want to implement them myself. My progress so far could probably have been achieved in a 48h gamejam if I just used/bought existing assets. Instead I have also spent weekends playing with water shaders and getting them to look how I want.

      But my game is a puzzle game. I don't need water, except that I now have a cool splash screen..

      • efdee a day ago ago

        You might be taking "splash screen" a bit too literal.

    • CyberDildonics a day ago ago

      20 years ago I could spend months tweaking ocean surface in renders and not get even close to that.

      I'm not sure what you mean here, because this is made directly from research that was done 20 years ago and it looks the same, it's just being done in real time.

  • fcatalan a day ago ago

    Things like this brought me into computers, but along the way I fell for the easy and boring life of glueing libraries, endpoints and corporate bullshit that leads to burnout. Perhaps some day...

    • lukko a day ago ago

      I think make the move gradually - find the stuff you were excited in originally, that you would love to learn more about and eventually do. Spend maybe a few hours a week diving into it - then gradually increase and move away from your current job.

      Go for it - we're all rooting for you!

    • EasyMark 21 hours ago ago

      I see a lot of my friends making more money than me doing stuff like that but I followed my interests and went into robotics first chance I got and do not regret it. There is nothing like the feeling you get seeing your code really interact with the world, at least speaking for myself.

    • kevindamm a day ago ago

      Someday could be today...

      • Trasmatta a day ago ago

        My problem is I'm so burnt out from the aforementioned stuff I don't have the motivation or energy for the cool stuff anymore. I feel like I need a year long sabbatical first, but reality says otherwise.

        • EasyMark 21 hours ago ago

          If you can afford it (time/family/financially) I would say to do it. Even if it’s only 6 months. You can learn a LOT in 6-12 months if you’re disciplined and focused. Don’t forget to build up a network in any new endeavor you take, it will save you time, give you inspiration, and help get a job later on, and maybe you can help them along the way as well.

        • zackmorris a day ago ago

          Same here, this has been the central crisis of my working adult life for 25 years. Unfortunately it never gets better. And I've taken 6 months to 1 year off for severe burnout with physical symptoms like adrenal fatigue twice now.

          My feeling is that this problem is intractable alone. We need groups working towards liberation, and societal change to support healthy work/life balance.

          What that looks like in practice is that wealthy people, especially those who won the internet lottery, should start giving something back. At the most basic level, that's paying one's taxes. Beyond that, they should start setting aside ego-based goals and start accepting requests outside of their attention so that the most pressing problems facing humanity can finally get solved.

          Give a billionaire $1 billion and a year later they'll turn it into $2 billion. Give one of us $1 billion and a year later a form of cancer will be cured. That's why they have the money and we don't, and why it takes so long for things to get better, if they ever do.

        • otteromkram a day ago ago

          Sounds like you just need more coffee :-D

          • Trasmatta a day ago ago

            More coffee, maybe a pizza party. That'll fix me right up.

      • maaaaattttt a day ago ago

        There are only two good moments to plant a tree: 20 years ago and today.

        • Aeolun a day ago ago

          Isn’t it like: the best time to plant a tree is 20 years ago. The next best time is today.

          • epaga a day ago ago

            Though I never understood why 19 years ago wouldn’t be the second best…

            • airstrike a day ago ago

              Because you didn't think of it then.

              You thought of it 20 years ago and didn't do it, and you're considering it again now.

              Instead of telling yourself it is too late to do it now, just go for it, so that in 20 years more you will be happy you planted this tree.

              • lukan a day ago ago

                Also some people like their children and grandchildren to enjoy some fruit trees.

                (Even if they are just "family" in the broader sense and not their own)

            • plasticchris a day ago ago

              Because the statement is meant to motivate the reader.

            • rbetts a day ago ago

              That would make today the worst day to plant a tree?

              • phn a day ago ago

                The worst so far, and the best when compared to all of your remaining days.

          • maaaaattttt a day ago ago

            Yes that’s it, thank you. I’ll admit I was too lazy to look the exact one up.

        • robinsonrc 5 hours ago ago

          15 years ago was probably pretty ok too

      • purple-leafy 16 hours ago ago

        Make that day today! I’ve realised this same problem too, sure there’s some beauty in an ultra tight gluing of logic … but there’s a vast unexplored sea of programming beauty waiting to be discovered. I realised this over the weekend, so I’m diving into graphics programming.

        I’m rooting for you!

  • viraptor 2 days ago ago

    Different approaches, but if someone's interested in waves/ocean simulation, Acerola published some awesome (as always) videos on this topic. https://youtu.be/PH9q0HNBjT4 and https://youtu.be/yPfagLeUa7k (edit: just realised one is linked in the references, just under the real name rather than nick)

  • btbuildem a day ago ago

    It's interesting how hard this problem is. We've been trying for decades, and we're still in the uncanny valley with it.

    If you freeze-frame this, the peaking waves look like snow-capped mountains. It feels unrealistic because for water to have features this sharp, it would have to be quite windy -- and the wind would never be blowing straight up. Here, the sharp features would need to be directional.

    The simulation has the swell nature of the waves down pretty well though. There isn't as much horizontal movement, as more up-and-down, which is what you'd expect to see in open water.

    • zamalek a day ago ago

      > uncanny valley

      I've been playing Nightingale and, oh boy, is the ocean water something special there. To be clear, they don't tackle spray and such by keeping the waves calm, which has allowed them to focus on other things. Whatever it is they are doing to simulate light transmission is working. The light shining through the waves at sunrise or sunset looks great and really sells the effect for me.

      It could maybe be accused of being a bit painterly, but it doesn't look wrong.

      • btbuildem 7 hours ago ago

        I checked out some gampleay videos -- they do a good job with the swell too, and I really like the way ambient light interacts with the water (daytime you can see in, nighttime you can not) -- but again, the water texture quality is a bit uncanny. It looks like they're just scrolling a bumpmap over a wavy surface, with the final effect of too much horizontal motion for the little surface ripples/wavelets. It makes it look like there's a current, more like a moving river than a ocean/lake body of water.

        It's a stunning-looking game oveall, wow. I had no idea :)

  • tomcam 2 days ago ago

    I spent years living on the beach. When you live on the beach, you watch the ocean for hours at a time because it’s mesmerizing and feels sensational. I wouldn’t guess for a second this was a render.

    • saxelsen a day ago ago

      Have you actually looked at waves and how they move, though? If you've spent years living on the beach you'd be able to spot in a heartbeat that the formation of foam and movement of the wave is not natural.

      • tomcam 20 hours ago ago

        Other observers said the same thing so apparently I didn’t look as carefully as I thought I did!

        > If you’ve spent years living on the beach, blah blah blah

        I wish I gave a flying fuck about your not very subtle accusation. Feel free to believe what you want. I’m retired and I still don’t have as much free time as you do. You are not very good at mind reading, but I’m glad you’re giving the old college dropout try.

        • cenamus 11 hours ago ago

          20k hacker news karma says quite a lot more free time than a couple hundred though

          • tomcam 11 hours ago ago

            Yet somehow I held down multiple jobs simultaneously, care for a severely handicapped child, support an extended family, and keep up my technical skills even in retirement while other people are staring at TikTok in line at Starbucks. Maybe it says something about time management. Stay classy

  • tsurba 2 days ago ago

    Shadertoy also has nice ones https://www.shadertoy.com/view/Ms2SD1

  • Eddy_Viscosity2 a day ago ago

    This is great, but this approach will break down a bit for REALLY big waves as they become non-linear. Water waves are not sinusoidal, but are close enough for small and medium wave heights that these methods work really well. The big big waves are not only much farther from sinusoidal but the waves start interacting with each in a non-linear way that can't be captured by the linear superposition approach used here.

    So for most sea states, this is fantastic. But if you want to do the 'perfect storm' wave or something like that, you need to use a different approach for realism.

  • convivialdingo a day ago ago

    Fourier was measuring tidal waves when he came up with wave frequency transforms - so in a way this is almost a full circle.

    Very impressed!

  • bnegreve a day ago ago

    It is very impressive, and better than anything I've seen before but think something is bit off with the swell. If I had to explain I would say that high frequency waves don't travel on top of low frequency waves the way they do in the video.

  • julosflb a day ago ago

    Very neat! I'm hydrodynamics by background and I wondered a long time ago why this kind of approach was not used as I always found ocean waves to look awful in movies. Once you describe ocean sea state in frequency domain, it is quite easy to give to floating objects like ships realistic motions using what we called RAO in this field (linear operator). You can also model sea disturbance (diffracted and radiated waves) caused by an object in a similar fashion.

  • eps 2 days ago ago

    Don't have any substantial comments, but I must say that the result is really impressive. Just wow.

  • lambdaone a day ago ago

    This is astoundingly good work; even though, as other commenters have said, it could still be improved on, the fact that it achieves such a level of realism with such a simple and elegant framework is truly impressive.

  • lukko a day ago ago

    Oh my - this is great!

    Does it mention what the density of the mesh is, or is it a flat plane with no displacement?

    Also, I wonder if there's a way to optimise the foam particles in some way. It does seem very wasteful to generate them across the whole plane, when most are culled. I wonder if the particle emission / creation could be linked to foam density?

  • goode 17 hours ago ago

    I was a bit confused what use an FFT had here since I was only familiar with the Fourier transform in the _forward_ direction (compute the component frequencies of a signal given samples). But this uses the _inverse_ Fourier transform, which effectively lets you take samples of a signal given its component frequencies. Here, those component frequencies are generated by mathematical functions developed (by other researchers) to model ocean waves, which are explained in https://github.com/2Retr0/GodotOceanWaves#ocean-wave-spectra.

  • kelseyfrog a day ago ago

    Any other resources on empirically derived rendering/animation methods?

    A lot of hobbyist gamedevs can think of tutorials where we "slap noise" on various things. While a good temporary use, there's an pedagogical gap between beginner and advanced methods.

    Another that comes to mind is vegetation animation. Like ocean waves, we often see animators throw a few octaves of sin/cos on plants to simulate wind, but because it doesn't spectrally match what we see in the real world, it looks off.

  • kroolik 2 days ago ago

    That's some National Geographic clip. Now, show us the demo!

  • HL33tibCe7 a day ago ago

    This is beautiful, I'd love to have this as a lockscreen or even a screen panel on a wall somewhere

  • bee_rider a day ago ago

    It looks really good.

    Out of curiosity, I’m sure everybody has heard of the FFT. They are quite general and used all over the place, and I imagine they’d be the first thing somebody would reach for if they had to describe waves.

    But I’d never heard of Gerstner waves. This leads me to believe that Gerstner waves are a more specialized thing. Since lots of work has already gone into rendering water, I tend to assume the method with a name I’ve never heard of was only reached for after very clever people rejected Fourier transforms for some reason.

    But, the results look better than most of what I see elsewhere. Has something changed to enable the more conventional solution?

  • cheschire a day ago ago

    While I appreciate ever more realistic water bodies, the part that game makers really struggle with is where the water encounters an obstacle.

    I did not see any mention of this in the description. Conceivably though, this is not a huge conceptual leap right? A game maker would simply need to add logic to impact the frequencies near objects, no?

    • magicalhippo a day ago ago

      The referenced paper "Simulating Ocean Water" talks about this in section 5. Indeed the FFT approach makes this difficult, where a different approach[1] for waves reflecting off obstacles.

      That approach uses convolution, however you can perform convolution using FFTs[2], so perhaps there's some nice way to combine the two approaches.

      edit: I just skimmed the papers, and it seems[1] does indeed mention combining the FFT approach with the convolution approach in the section on Ambient Waves.

      [1]: https://people.computing.clemson.edu/~jtessen/reports/papers...

      [2]: https://phys.uri.edu/nigh/NumRec/bookfpdf/f13-1.pdf

    • thom a day ago ago

      To an extent you can get away with just sampling the output of the water shader to work out the water's effective height at any given point. Big changes in height, or buoyancy for non-static objects, indicate bigger angles hitting the waves and you can fake some splashes with particles while the wave itself just gets occluded. Apply forces at just three or four points and you can make a boat rock pretty believably on top of this kind of water.

  • tonetegeatinst a day ago ago

    What level of math is this?

    I struggled in calculus over the summer but passed and am currently taking discrete math but recognized basically none of the math equations in the github project readme.

    • szvsw a day ago ago

      It general falls into the category of signal processing - you will want to start with reviewing the Fourier transform, which requires a bit of calculus and a little bit of linear algebra. It helps to know Euler’s formula and how it gets used. There are lots of great visualizations online. The main thing that will really help with this though is developing a decent understanding of the concepts of the frequency domain and time domain as starting points. Good luck.

  • nox101 a day ago ago

    Reminds me of Sea of Thieves

    https://youtu.be/aGogFt4bhTM?t=12

  • shireboy a day ago ago

    Nice, but may need to adjust the limits: https://news.ycombinator.com/item?id=41631177

  • chhs 2 days ago ago

    Looks incredible!

  • Archelaos 2 days ago ago

    The demo looks unrealistic. The waves never break. Increasinlgy steeper slops with pointy peaks travel from left to right until they just sink down towards the left.

    • AlunAlun 2 days ago ago

      This is explicitly a simulation of ocean waves, and ocean waves do not break.

      • Archelaos a day ago ago

        Okay. That makes sense. What about the steep elevation? Shouldn't it be smoother at the top?

        • UniverseHacker a day ago ago

          As someone who has done offshore sailing… the waves also look unnaturally steep/tall/pointy to me. It’s very cool, but needs some tweaking still.

  • rkagerer 2 days ago ago

    The sample video is really impressive, it's worth a peek.

  • purple-leafy 16 hours ago ago

    This is a really fascinating graphical piece!

  • aetherspawn a day ago ago

    I think the downside of this approach is you can’t ie split the waves with a ship.

    • coldcode a day ago ago

      Yeah I wondered how that could be done, otherwise this would only be good for backgrounds.

  • Mattish 2 days ago ago

    2 of the linked references have full implementations of very similar things, with some shared references.

    Is there something here which godot is enabling which wasn't previously possible? It seems to be entirely GPU compute workload with particles which are available as part of all mature rendering engines

    • arminiusreturns a day ago ago

      Godot itself is open source, which I think has brought a strong community of people to it. My mega-big-ultra project I've been working on since 2013 would be nowhere near as close to where it is now (close to launching crowdfunding/alpha) if I hadn't transitioned to Godot! (I was fighting the UE4 system from the days when it was $20/mo, we linux people really got dealt dirty by Tim Sweeny, with lots of empty promises for linux support)

  • bobim a day ago ago

    I would like a Silent Hunter III remake with this.

  • arminiusreturns a day ago ago

    This is awesome to see! Much more progress than I have made on my gplv3 version for my system. (the original intention was to replicate Blackwake style ship combat)

    For what it's worth, the real difficulty in gameplay is getting physics objects to interact with the waves properly.

  • jkmegtu a day ago ago

    Free fire

  • pmarreck a day ago ago

    How do I get this masterpiece running locally to play with? I don't even know what Godot is (but I've used makefiles and such)

    • nkrisc a day ago ago

      1. Download Godot: https://godotengine.org/download/windows/ (this project uses an addon for GUI that requires C# so you’ll need the C# version of Godot 4.3)

      2. Clone the repository

      3. Open Godot and import the project by navigating to the directory containing the project.godot file.

      Then open the project and away you go.

    • eaglefield a day ago ago

      The github repository is a godot project. Godot is a game engine. The quickest way is to download godot. Clone the repository and open the folder as a project in godot.

    • jimmySixDOF a day ago ago

      If you have a Quest VR device Godot just released an editor with live scene updates I am bookmarking this to try see what it looks like in there.

    • krapp a day ago ago

      Godot is an open source game framework: https://godotengine.org/

      You would presumably need to download the Godot framework and open it in the framework.

  • wslh a day ago ago

    Great! I've shared this with every physicist I know who's not directly involved in animations.

    Quick question from my swimming class yesterday: We know that professional swimmers use a range of technologies, both old and new, in their training. Is there currently a model that fully simulates the physics of swimming across different styles? If not, this seems like a great project idea!

  • ReptileMan 2 days ago ago

    That looks wet. And honestly it is the best compliment I can give.

  • bschmidt1 a day ago ago

    Looks awesome. Is it from a fixed perspective only? If not should show the camera rotation in the video demos so it's clear how it could be used.

    Would be curious to see how it looks from different angles etc. as the light changes.