Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Realistic Breaking Wave

Discussion in 'Scripting' started by StarChick971, Jun 24, 2019.

  1. StarChick971

    StarChick971

    Joined:
    Nov 28, 2015
    Posts:
    36
    Hello,

    I am currently about starting a new project on surf with a realistic approch (more simulation oriented than arcade). Here are some inspirations I have:
    • World Surf Series - PS4 (2018)
    • True Surf - mobile (2018)
    • YouRiding The Journey - mobile (2016)
    • Kelly Slater Pro Surfer - PS2 (2002)
    BUT, I am facing a big issue with how to render a real looking wave from its growth until it breaks into foam.

    I find out several way to render the ocean but very few to have some breaking wave look:
    Concerning shader, I have already seen some interesting free ones like:
    None of them allow to do what I need.

    Still, I found out an very interesting asset which might do exactly what I want: Mega-Fiers
    https://assetstore.unity.com/packages/tools/modeling/mega-fiers-644


    ... but I would have to pay 134€ only to use a single feature i can't afford! I only need that Bezier Attractor from the package. Now I am looking for a way to achieve this mesh deformation by scripting but it seems to be very complex at the end, then I will have to add some physics to this mesh...

    I would really appreciate some help if anyone has a way to create that realistic breaking wave. I hope this thread can also help other developers/designers to add some realism to their ocean/shore/beach scenes.
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,736
    Well, the easiest way to create such wave is to model it.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    7,361
    Using 3D software, animating and importing to Unity, may be the convenient way of sufficient and simple results.
    If expecting much, be ready to spend time, or money.
     
  4. TPEUnity

    TPEUnity

    Joined:
    Jan 17, 2018
    Posts:
    25
    Simplest way that comes to my mind is using Blenders (or any other 3d modeling software with similar feature) wave modifier and using shape keys to fake it.
     
  5. StarChick971

    StarChick971

    Joined:
    Nov 28, 2015
    Posts:
    36
    Well, after month of testing stuff, modelling in Blender/3DSMax without good results, I finally I just got Mega-Fiers for half the price thanks to BlackFriday. Let's see what is possible then...
     
  6. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,030
    When you're only doing one wave at a time (as in surf games), then the physics of breaking waves isn't complex (I was recently reseaching waves for a project, and although I didn't need/want breaking waves, I found a few free research papers on the web that went into details of breaking-waves). It's a bit of work - you need to mathematically model the waves, and then add breaking-behavior, and finally you need to update your mesh each frame to use the values from your mathematical model - but each step is quite small.

    There's a couple of different mathematical models, with different levels of accuracy, but they all looked reasonably simple to implement. The hardest part for me was mathematically modelling basic waves (there's a LOT of tutorials for how to do this for games, using Gerstner waves to make meshes), which Unity has built-in (some of the included shaders have functions you can use that automatically make gerstner waves) ... but to add the breaking behavior, you might need to re-implement gerstner yourself.

    If you haven't written much code for dynamically changing meshes at runtime before, and/or haven't done much work with turning math functions into in-game movements, then this could take you many weeks to implement, but it's mostly about going slowly and testing as you go.
     
  7. StarChick971

    StarChick971

    Joined:
    Nov 28, 2015
    Posts:
    36
    I think we saw the same documents from the web, I gathered a dozen of them with different approaches (most of them are extracted from theses about breaking wave modeling), the best I found is the one from Siggraph 2007 with the Surf's Up movie. I tested some mathematical approaches by changing the mesh on Update(), but it is very performance costly and I would like to run severals wave at a time like what you can see at Snapper Rocks Autralia or Puerta Chicama in Peru as shown below (maybe with less waves):

    I know the Gerstner wave model and successfully re-done it with Shader but this is the the "growing" wave moment, collapsing (or breaking) moment is the tough part to represent within Unity (Blender doesn't allow very flexible parametric wave except if you create several copies with slight changes).
    In addition to that there is the Physics part which is even more costly in performance...

    I will try to get the vertices from a gerstner ocean then apply the Attractor modifier from Mega-Fiers if it works...
     
  8. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,030
    If I remeber correctly, there was one that used a nice simplification using rotating circles as an approximation of where the breaking wave should go, but I don't quite remember it (I wasn't paying attention). I just checked some of my bookmarks - Uncharted had some talks on their waves, and they had breaking waves IIRC. I also looked at the Boussinesq approximation, which looked like it had potential for a high-fidelity simulation (probably more what you're looking for?)
     
  9. StarChick971

    StarChick971

    Joined:
    Nov 28, 2015
    Posts:
    36
    I found an very interesting video extracted from Siggraph for Surf's Up making of about the wave generation:
     
    a436t4ataf and Antypodish like this.
  10. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,030
    Cool. My vague memory is something like that, but more precise.

    Something like ... the main wave surface exactly runs on the edge of one circle, but the point where it collapses follows a smaller circle that rolls around the inside edge of the main circle. It was apparently based on actual physics of how gravity pulls the breaking wave edge down - it looked too simple to be true, but seemed to match.

    Sorry I can't find the paper any more :(, I've been through my browser history and saved links, and just isn't anywhere. Arrgh.
     
  11. The_Storm_Rider

    The_Storm_Rider

    Joined:
    Jan 28, 2020
    Posts:
    4
    Hi @StarChick971 ,

    I am also making a game with breaking wave in Unity and I have coded a way to model them quite realistically with good calculation speed. My game will be different as it is a boat game in 2D for mobile, still the code is made for 3D, so if you have difficulties I can share things. (but I won't disclose the whole code for free as I spent months on them).
     
  12. StarChick971

    StarChick971

    Joined:
    Nov 28, 2015
    Posts:
    36
    I would be really interested in such solution.

    May you share a screenshot about how it looks like?
     
  13. dhtpdud528

    dhtpdud528

    Joined:
    Apr 8, 2018
    Posts:
    12
    I am also making a surfing game. I'm very curious about your code. If you put it on Assetstore, I'll pay as much as I want to buy it.
     
  14. dhtpdud528

    dhtpdud528

    Joined:
    Apr 8, 2018
    Posts:
    12
    Last edited: May 7, 2020
  15. StarChick971

    StarChick971

    Joined:
    Nov 28, 2015
    Posts:
    36
    I know the game, I forgot to mention it in the first post.
    The game looks visually great but according to the reviews the surfing feel is not realistic enough. Yet, gameplay here is not our topic, let's focus on Virtual Surfing waves: they look perfect with a good shader making the ocean beautiful. However, it seems to be the same perfect barreling wave for all spots, maybe by just making it breaking in different sections.

    The main idea of the topic is to reproduce all wave styles starting from the perfect tube wave:

    Plunging - making perfect tubing waves


    Spilling
    - gentle slope floor resulting in mushy waves


    Surging - long period on steep beach


    Collapsing - between surging and plunging

    (source: https://www.surfertoday.com/surfing/the-four-types-of-breaking-waves)

    In addition to that, there are different configurations: beach break, reef breaks, point breaks, rivermouth break.
    It would be great to be able to have cross-waves so the height is the sum of two intersecting waves (double-up waves) or even reforms when the same wave breaks again.
     
    Last edited: May 8, 2020
  16. Image3d

    Image3d

    Joined:
    Jun 20, 2008
    Posts:
    110
    Hi, Megafiers is the way to go...

    Just remember that Surf games are real time simulations and you must balance between speed and wave resolution...
     
  17. StarChick971

    StarChick971

    Joined:
    Nov 28, 2015
    Posts:
    36
    Even if the waves generated using MegaFiers look nice, it is not realistic enough and there are some issues when the waves collapse: I randomly get weird positions for some vertices resulting in backface rendering and such, that is not good.
    Most Surf games are using baked waves, I don't think they are pure real time simulation in the same game, they break exactly the same way and most of the time in the plunging type.
     
  18. StarChick971

    StarChick971

    Joined:
    Nov 28, 2015
    Posts:
    36
    I saw that alpha game a long time ago but I didn't post it here, someone managed to create realistic wave within Unity: https://shorebreakblog.wordpress.com/ (you can try yourself on the website download page)
    So it is feasible, we just need to know how! Here are some screenshots from his game:

    From the barrel :cool::


    Surfing!


    Beautiful shot:


    In the tube:


    Looks great right? ;)
     
    Joe-Censored likes this.
  19. StarChick971

    StarChick971

    Joined:
    Nov 28, 2015
    Posts:
    36
    Ok, now I am thinking about using Bezier splines to give wave a nice breaking shape, here is my first attempt :) :






    It is ok that the mesh is not perfect (especially the wave shoulder) but I got some progress with a breaking wave.
     
    zeb33 and Joe-Censored like this.
unityunity