Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

My Surfing Simulation Project

Discussion in 'Works In Progress - Archive' started by 3DRaddict, Jan 16, 2017.

  1. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    For many years I've always had a surfing game at the back of my mind, but hardware and software limitations have never allowed me to bring it out to the forefront. So my decision has been made... after all, I'm not getting any younger, and do so want to end up with a completed game. The last few years (since 2010) with various 3d engines (3DRad(deprecated), Oddity(deprecated), Esenthel and even raw DirectX) have given me the opportunity to try out various techniques, so I now have a pretty good grasp on what works and what does not.

    A history of my development attempts can be obtained by perusing the following links:

    http://www.3draddict.com/surfing-simulation.html
    http://www.esenthel.com/forum/showthread.php?tid=7949
    http://www.esenthel.com/forum/showthread.php?tid=8756

    After playing around and experimenting with Unity for the last couple of months, I've decided that this is going to be the final home for this project.

    Here's a quick and dirty video showing the beginnings of my beach scene and various surfing wave types (small shorebreak waves in the forground, a pointbreak wave to the right, and a large outer reefbreak wave in the background)



    The game itself will focus on you (the surfer) and your lone battle with nature (the waves). There will be no competitive surfing against fellow surfers, as I'm completely against today's large scale commercialisation of surfing. I will, however, throw in the odd mean dude who "drops in" on your wave, and also that shapely surfer chick who produces some eye-catching contortions on a surfboard.

    Sharks, jellyfish, driftwood and rocks will hinder your progress in making that perfect wave score. Paddling out to the "backline" and avoiding advancing "foamies" pushing your surfboard backwards will also be a challenge.
    Dolphins and whales will add some entertainment while you're waiting at the "backline". Weather conditions will also play their part.

    Surfing action will take place at various spots (real and fictitious) around the South African coastline, each spot sporting a different type of wave: reef-breaking monsters, shallow-breaking pipelines, fast-breaking point waves, lazy slow-breaking beach waves. You will start as a "gremmie" (learner surfer) and, as your points score increases (by means of learning new manouvres and increased "time-spent-on-waves") so you will advance to higher levels with more difficult waves.

    Well, that's my plan and I estimate a good two/three years in the making.

    The simulation game will be called "Surfari ZA", and I'll keep this thread updated as I progress.
     
    devotid, Flurgle and RavenOfCode like this.
  2. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    Made some design changes to my water shader to allow more depth, detail and realism. Much better, in my opinion.



    Now to experiment with foam particle explosions on the breaking waves.....
     
  3. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    Whew, getting particles to do exactly what I wanted was quite an exercise! Thank goodness for Google and the vast field of experienced Unity user-contributors!
    I now have my foam/spray explosion in the area where the wave crashes onto the ocean surface.
    I took my camera out to sea for a closer look:



    The wave looks nice from far, but actually it is far from nice....a lot more work is required on the closeup wave and its interface with the ocean surface.

     
    Ony, Flurgle, mgear and 1 other person like this.
  4. Deleted User

    Deleted User

    Guest

    I have been thinking about this as well, looks good , great start.

    p-
     
  5. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    Still experimenting with the look of water,wave and foam particles.
    At present my waves are seperate entities from the surrounding ocean and this has been challenging to integrate them
    seamlessly. I'm having problems with using alpha transparency on overlapping objects (i.e. waves,background ocean,skybox and foam particles). My current remedy is to have all objects rendered using 'Opaque' shader material and simulate transparency using texture map blending.



    I am now looking at making my wave a submesh of the main ocean mesh. As a Unity mesh is limited to a maximum of
    65500 vertices, this is proving rather tricky to get the fairly high resolution required for the wave.
     
  6. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    Great, I like it.
    For the 65500 limitations, why you don't split your mesh in 4 mesh or more ?
     
  7. Fera_KM

    Fera_KM

    Joined:
    Nov 7, 2013
    Posts:
    307
    Hi,

    I just want to wish you good luck!
    I think you have chosen the most difficult thing to make a game around.

    Not that I'm trying to put you down, I'm super happy to see game projects that does something, anything, thinking outside of the box.
     
  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    hey, i remember seeing your posts in 3drad forum.. : )

    have you checked geometry / compute shaders, tesselation ?

    btw. for inspiration saw this splash effect last week, quite amazing:
     
    DevMember and 00Fant like this.
  9. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    Thank you,folks, for the advice and helpful comments.

    I've taken note, and decided to forget visual details for now and concentrate on the basics of producing
    a wave that is a part of the actual surrounding sea, and not separate from it. In this manner, I am able to
    easily share the sea properties with those of the wave, thus providing a more seamless integration. As mentioned previously, a limiting factor is mesh vertex resolution. In this regard, I have built a very basic 'wave pool' in
    which I can experiment with various scenarios. At the moment I'm using a 250 x 250 vertex procedural mesh grid.
    The vertices are 1 Unity meter apart in the X axis and 2 meters apart in the Z direction which gives an overall
    surfing zone of 250m x 500m. Via some mesh manipulation trickiness I've managed to squeeze vertices together in
    the area occupied by the travelling wave. This does more or less provide the resolution required for my wave.
    I must bear in mind, however, that this 250m x 500m patch is to be a tile within a much larger surfing area.
    Once I'm more aquainted with Unity, I'm sure that compute shaders, geometric shaders and tesselation are going to play their part in future episodes.

    mgear:
    (Thanks for the links, mgear ....yeah, and I also remember you from those good ol' 3DRad days, along with sadly departed 'jestermon' and 'RedOktober')

    Here's a vid of my developmental 'wave pool' thus far....with warts and all....still early days!



    My requirements are for the breaking wave to move forward smoothly with the surrounding sea surface gliding over
    the wave as it moves. To visualise this happening, I've textured the sea surface with a text-marked texture.
    The wave must be able to handle a left-breaking, right-breaking and middle-breaking portions. It must also be of
    varying size in length, width and height.

    kemonono:
    I'm definately going to need it....:)
    I get the feeling of going around in circles with this project... trouble is I'm not sure whether the circles are getting
    closer together or further apart!:(
     
  10. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    In the words of Willie Nelson, I'm "On the Road Again"...:)
    I've found the solution to my problem in the form of adaptive tessellation. Fortunately, last year I devoted a great
    deal of time getting to grips with raw DirectX11 coding with the aim of applying it to my Surfing Simulation project.
    I got pretty far with it, but eventually realized that I was wasting much of my time 're-inventing the wheel'. Why go to all that effort when there were perfectly good 3D engines around which covered all the nitty gritty? Hence Unity3D...

    Anyway, in this particular instance, it has stood me in good stead... I had a tessellation shader on hand which I have
    fairly easily been able to port to Unity. My wave is now an integral part of the surrounding ocean and no longer chugs
    jerkily along 1 meter a frame. With tessellation, I have been able to increase the resolution ten fold, and not just for
    wave, but for the whole patch of ocean. The wave now glides along like a swan.And being adaptive, the tessellation, being adaptive, can vary according to camera distance.

    All the requirements mentioned in my previous post have been met, as the accompanying video demonstrates. Ok, the wave is not actually a wave yet, but a rectangular block representing the wave... it is still part and parcel of the main ocean patch.



    My next job is to add Gerstner wave action and Perlin Noise to the presently flat sea mesh. I think, also, that a Compute Shader is going to play some role.
     
  11. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    After a rather tedious struggle I've managed to add some realtime perlin noise to the 'water' surface.
    The perlin noise and its normals are generated in script, then transferred to the surface mesh via compute shaders.
    The perlin noise is a height value which is used to displace the mesh vertices Y values.My first attempt was to do it all via script, but this reduced the framerate drastically from 80fps to 30fps. This forced me to start reading up and trying to understand the scant documentation on Unity Compute Shaders. I eventually found an excellent tutorial ( http://cheneyshen.com/tag/computeshader/ ), which got me going in the right direction. After applying compute shaders there was only a small drop in framerate from 80fps to 70fps.



    The video just shows the added perlin noise, with the render textures displayed as GUI images at the top of the screen.
    I have not yet made use of the normals in the pixel shader. This will come later, when I concentrate on the 'eye candy'
    stuff.

    The perlin noise represents the secondary up/down ripple motion always present on the sea surface.
    There is also another motion in the form of overall wave swell. This will be my next task...to add it either using the
    'Gerstner' or 'Sum of Sines' algorithm.
     
  12. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    Merged in some Gerstner wave action to provide a base swell.
    Greatly over-exaggerated in this video clip, but the nice thing is that, because the wave is comprised of 4 superimposed Gerstner waves, there are available a large number of useful parameters for tweaking the wave to any size, form and direction.



    That rectangular monstrosity is still present, and my next job is to convert it to a decent surfing wave.;)
     
  13. Fera_KM

    Fera_KM

    Joined:
    Nov 7, 2013
    Posts:
    307
    You are actually doing a 3 part project!
    1. Breaking wave
    2. Ocean
    3. A game

    I just wanted to say, I find it a bit fascinating to read, I've been working with ocean for a few years now,
    not from a mathematical point of view (not a programmer), but artistically.
    I personally found it easiest to break ocean fractals into 2 layers each with 3 parts, "Large wave", "Small wave" and "micro wave", and a second layer containing the areas where the wave direction changes (creating those localized "still water" areas, or breakup pattern). I also find it personally easier to tweak it with a lambert-esc gray material.

    Have you had any thoughts on waves catching up to each others and adding on (like a rouge wave)?
     
    Last edited: Feb 28, 2017
    zeb33 and theANMATOR2b like this.
  14. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    I have now replaced that rectangular block with a recognizable breaking test wave. The wave is completely non-surfable, or, as in surfer lingo "a closeout"... meaning that it breaks over the whole face of the wave, not gradually left or right.



    There is a little visual artifacting, probably due some discrepancies in the normals, which I'll have to look into later. However, my main goal of having a breaking wave as part of the surrounding ocean has been accomplished.

    At present the wave does not sense any water depth as it advances forward. The shape,size and break point of the waves are dependent on what is underneath the water surface, or the water shallowness. I must now, therefore, concentrate in obtaining a live depth map, or maybe I'll use the static heightmap from which I derived the terrain. Whatever is easier... :)

    @Kemonono
    That's for sure!
    (1) and (2) have to be accomplished first, before I even start (3). In fact, there is also another major stage... the actual surfboard physics involved in riding the wave... now that's real hairy stuff ! (Hence my guesstimate of 1 to 2 years for development)

    Yes I have...but rogue waves are usually encountered in the open sea, and my focus is mainly more inshore where the breaking surfing waves are to be found.
     
  15. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    Just replaced my scripted Perlin Noise, with a superfast GPU based Perlin Noise found in the free 'Turbulence Library' resource from Asset Store.
    A 100% FPS improvement resulted (from 45fps to 90fps) :)
     
  16. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    Used my terrain heightmap to provide some depth sensing for the inshore waves. This enabled me to add dynamic foam generation and transparency effects at the shoreline.The foam generation is very flexible and can be tweaked for intensity, fading out, distance from shore, and is dependent on the shape and depth of the ocean floor. The waves also flatten out as they approach the beach.
    Seeing as I now have more 'frame power',I've widened the surfing zone to 500m. So the whole zone is now a 255x255 vertex mesh, with a distance of 2m between vertices. The tesselation provides the detail in this regard.



    I'm still using my 'test text texture' as the water texture, and will now start working on making the water surface more 'waterlike' by adding some scrolling normal maps and a little environment reflection. BTW, I've flattened my main surfing wave for now, whilst I work on these effects.
     
    Last edited: Mar 12, 2017
  17. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    A little of this, a little of that, and plenty tweaking!
    There are a large number of variables involved, so it is difficult to find just the right combination to get the desired look.
    Anyway, better too many than too few.
    A definate improvement on the previous... I've now added scrolling normal maps and skybox reflection.
    I'll have to investigate what those random flashes are.

     
    RavenOfCode likes this.
  18. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    This looks really cool, definitely gonna follow this! :)
     
  19. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    that flicker looks bit similar to what these guys (@JeanSimonet) had on their game dev stream "while ago", they had some dx11 gpu/tesselated mesh there too i think.. cant remember what was the cause though.
     
  20. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    I've fixed the 'random flicker' problem. It actually had nothing to do with the tessellation, but was caused by some clashing values in the code that flattens the waves as they approach the shoreline. I'm very happy about that....I can now continue. :)
     
    alexanderameye likes this.
  21. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    To gain some perspective on wave scale as I progress, I've placed Ethan on the beach...


    and Ethan at sea...


    A gentle calm sea... I can't have him drowning at this early stage! ;)
     
  22. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    I'm now quite a happy chappy ! :)
    I've accomplished something that I thought would be a major hurdle...I now have a buoyant surfboard!
    This is a milestone for me, as the surfboard mechanics are going to play a huge part in this project.
    I not only want the surfboard to ride the waves, but it must also react with the broken waves as they advance towards the beach. That is, the board must get pushed back as its rider tries to paddle out to the 'backline' through the 'foamies'. Or, if he loses his board in a 'wipeout', the board must behave according to the forces acting upon it.
    (In present times, the board is anchored to the surfer by means of a 'leash'... but back in my surfing days we had no such thing, and it meant a long swim to shore to retrieve your board.... darn it! I've just given away my age! :mad:)

    Anyway, here's a short clip of my buoyant surfboard bouncing in the swell.



    Still a bit unstable...but that's to be expected...it has no rider to drive it!
     
    RavenOfCode likes this.
  23. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    Using a 'GrabPass' I was able to add a little transparency/refraction ... makes all the difference... water passing over the surfboard no longer hides it.

    Here's a view from the deep end of the wave pool, zooming on to the freely floating surfboard.

     
    RavenOfCode likes this.
  24. Zac-Yeates

    Zac-Yeates

    Joined:
    Jan 23, 2015
    Posts:
    20
    You may want to make the video public. Apart from that, the waves look very nice so far. Are they hand placed or do they dynamically generate based on the topography of the ocean. i.e. if an incoming wave hits a sharp coral reel will it automatically "know" that it needs to rise up and possibly form a barrel?
     
  25. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    Yes, that is my eventual plan... based on the underlying terrain, the wave will change its shape and break accordingly.
     
  26. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    Now that I've sorted out the surrounding water properties and surfboard buoyancy, my focus is once again on perfecting my test surfing wave.
    I've brought back my 'test text texture' for the water and my previously hidden test wave. Because the water is semi-transparent, so too was the test wave, with the result that I was unable to see it nicely, as it merged too well with its surrounding sea base. To solve that problem I 'lerped' a little white into the wave so as to distinguish it from its surrounds.(Maybe a little too much white, but at least I can see it whilst experimenting)

    The video clip is a view from the beach showing the wave forming and advancing. I also took the liberty, using various key presses, of changing the wave's height and position whilst it was travelling forward.

     
    RavenOfCode likes this.
  27. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    A better looking wave set, with random positioning and random wave height (within limits!)

     
  28. dutchlol446

    dutchlol446

    Joined:
    Jan 16, 2015
    Posts:
    12
    i love it already keep going
     
  29. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    1+ for this project. I would love to give it a go some time!
     
  30. 3DRaddict

    3DRaddict

    Joined:
    Jul 25, 2016
    Posts:
    26
    My surfboard now has a driver whom I'm calling TestDummy.

    Getting TestDummy to perform some paddling animation served as my introduction to keyframing in Mecanim...and, boy, was that some introduction! Along the way, I discovered the following:
    1) There are no ready-made surfing animation clips that I could find via googling, so I will have to make them all myself. (Hint: If any of you come across any, then please let me know :) )
    2) There really is very little 'how-to's on making custom CHARACTER animations using the Animation Editor keyframing.
    3) I discovered (after some frustrating experimenting) that Unity does not allow keyframing of 'humanoid' characters... they have to be imported as 'generic' in order for keyframing to work.

    Until I've had more practice with animating in Unity, I'm just going to stick with what I've learned so far. I'm more a technical guy rather than an artist, so this is going to be a little difficult for me. I have noticed that Unity has a small section on Inverse Kinematics, so I'll definately be looking in that direction.

    If all else fails, I might have to wipe the cobwebs of my old copy of 'fragMotion' and use it for making my animations.



    I've tried to simulate real-life paddling by using the [LArrow] key to provide a paddling forward force on the left side of the surfboad and the [RArrow] key for an equivalent force on the right side of the surfboard. Thus, by alternating tapping of these keys, one drives the board forward. By single taps of the [LArrow] the board will turn left, and vice-versa for the [RArrow]. (Imagine your index and middle fingers as TestDummy's left and right arms :p)

    I think I'll next refresh myself on the Unity Particle system so as to add some visual dynamics to the water and waves.
     
    alexanderameye likes this.
  31. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Would be cool if this works in VR. You could easily paddle with the Touch/Vive controllers.
     
  32. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
  33. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    There is a good reason there are no good support for animating humaniods in Unity: No one wants to do it, cause there are so much better tools around. : )
     
    theANMATOR2b likes this.
  34. zeb33

    zeb33

    Joined:
    Nov 17, 2014
    Posts:
    95
    @3DRaddict , have just started on this path, hope you didn't abandon it..
     
  35. StarChick971

    StarChick971

    Joined:
    Nov 28, 2015
    Posts:
    112
    Found this topic, @3DRaddict it reminds me the new alpha game Search for Surf