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

Wanted: Ocean shader

Discussion in 'Works In Progress - Archive' started by bigkahuna, Jan 8, 2009.

  1. MadMac

    MadMac

    Joined:
    Dec 30, 2008
    Posts:
    61
    :eek:
    WOW fantastic Work !!!
    many thanxxx for the share !!!
     
  2. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    twinfox, that is freaking awesome. thanks so much! I'm getting > 100fps fullscreen on a new macbook pro.
     
  3. mike123

    mike123

    Joined:
    Feb 8, 2009
    Posts:
    4
    Hello TwinFox is it possible to get the hole script for your ocean , i only have acess to a mac 4 days every month
    i am wating for the xp/vista release of unity tools
    then i will begin to write a shader for you cool ocean demo
    i will first try fxtools from nvidia

    mabye something can be optimize to run in a shader
    i now the FFT can be done in a 2 pass shader to create the butterfly.

    hope you can help out
    Mike
    michaelhansen555@msn.com




     
  4. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,687
    mike:

     
  5. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Agreed, this looks great; is coming together nicely!

    :)
     
  6. TwinFox

    TwinFox

    Joined:
    Jan 9, 2009
    Posts:
    66
    Everybody, thank you for your compliments. To be fair, I have only implemented a previously published algorithm.

    Mike123, thank you so much for volunteering for the shader work! I have been trying to make one myself, but just can't get my head wrapped around the whole shader business. I will PM you tomorrow about the details.
     
  7. dmorton

    dmorton

    Joined:
    Jan 14, 2009
    Posts:
    119
    These guys seem to have a good technique for modeling waves: http://www-evasion.imag.fr/Publications/2002/HNC02/wavesSCA.pdf

    Supports vertex based LOD so that you can model the waves right out to the horizon. Also supports filtering out low-amplitude and high-frequency waves as the LOD kicks in.

    Ive been working on getting this running on the iPhone, which is something of a stretch. Would be great if I had access to the VFP for this.

    Its possible to implement this without any trigonometric operations in the inner loop. Cost is about 10-12 FLOPS per vertex, and is highly parralelizable.
     
  8. ChrisBennet

    ChrisBennet

    Joined:
    Feb 15, 2009
    Posts:
    9
    Gorgeous!
    -Chris
     
  9. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Very nice work. Webplayer fps is capped at 50 - that's why you're seeing the big difference between that and the standalone.
     
  10. Image3d

    Image3d

    Joined:
    Jun 20, 2008
    Posts:
    155
    TwinFox

    Just an idea. Instead of using the real time FFT calculation, we could use a FFT previous calculated table.

    This would free the system for other tasks and the solution could be used in the Iphone.

    This would allow us to use previous deform ocean data to do Surf waves.

    For the Iphone there is no need for a special ocean shaders, as a textures and reflections would do the trick.
     
  11. Dragonos

    Dragonos

    Joined:
    Nov 10, 2007
    Posts:
    42
    Has anyone seen an body of water done with metaballs? It looks pretty nice but I fear to render a ocean instead of a glass of water would be a cpu killer.
    BTW Like your ocean alot. My games generally use a cartoony style though kind of like in Nintendo's Game Zelda Wind Waker. It would be nice to have a cartoon foam shader. (BTW can unity do metaballs? It would be really nice!!!)
     
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    no, no integrated metaballs.
    You might thought be able to write your own metaballs (or voxel balls, as the majority of meta ball algorithms are patented)
     
  13. VICTOM

    VICTOM

    Joined:
    Aug 28, 2005
    Posts:
    233
    There is meta-ball code on the wiki - last time I checked.
     
  14. dmorton

    dmorton

    Joined:
    Jan 14, 2009
    Posts:
    119
  15. dmorton

    dmorton

    Joined:
    Jan 14, 2009
    Posts:
    119
  16. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    The mesh animation is top notch. Now if it had a nicer shader with foamy crests, it would be awesome. (Of course that wouldn't be possible on the iPhone though.)
     
  17. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    @dmorton

    Wow (world of waves) ..!
    The waves are great.
    How do you do that?
    Is it a shader or an animation?
     
  18. dmorton

    dmorton

    Joined:
    Jan 14, 2009
    Posts:
    119
    Those last two videos are showing a 2-pass shader and a 2000 vertex ocean. The earlier videos show a 1000 vertex ocean, and this produces an acceptable quality result.


    Without bump mapping, it can be a 1-pass shader. You will notice that the bump mapping is only really visible up close - this is a result of the smallish scale of the bump map. I don't think it would be a huge loss to turn it off and use a more detailed texture map.
     
  19. dmorton

    dmorton

    Joined:
    Jan 14, 2009
    Posts:
    119
    Foamy Crests? Not possible on the iPhone?

    Them's fighting words!

    I had the foam working on an earlier build, but had turned it off while getting the lighting working properly. Whitecaps and foamy crests and breaking waves are coming up (it may be a third shader pass though - not sure, might be able to squeeze it into the second pass). Also coming are breaking waves, and boat induced spray.
     
  20. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    :eek: -This- I gotta see! :D
     
  21. dmorton

    dmorton

    Joined:
    Jan 14, 2009
    Posts:
    119
    Might have to draw a line somewhere an actually build my game instead of an ocean model :)

    I think once I get foam in I will have to put the ocean model aside and get the fishing happening.
     
  22. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    This is fantastic.

    Are we allowed to include this in our projects? I just wanted to confirm some kind of terms of use regarding this, assuming that thats why you posted the source. Its outstanding..

    thanks

    AaronC
     
  23. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    Same question as Targos - and same comment : this in one of the most amazing projects for Unity. It would deserve to belong to the Standard Assets in a future version, IMO.

    Subsidiary questions :

    1) there's a "buoyancy" script in the project. Is it already useable - and if yes, how ? I tried to attach it to an object with a rigidbody, but it keeps falling through the ocean plane... so I clearly have missed something.

    2) has anyone found a fix or workaround for the initialization problem ?

    Again, congratulations ! :D

    [EDIT] forget question 1, I just need stronger coffee : there is also a prefab named "Boyant Object" in the project... just assigning an ocean plane to the script's slot makes the object float on it. And this without having to deal with colliders for the water... this is really thrilling.
     
  24. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    Yes it floats, silly me ! :D

    I've just made a small "old style" scene that uses the package provided by Twinfox, a very simple submarine model from the Google SketchUp site, and a piece of music from a classic movie...

    Unity's powerful tools, plus this great ocean package, allowed me to create exactly the kind of scene that I had in mind.

    Webplayer : www.tiviboo.com/oceanretro

    [EDIT] lighter version, for GMA950 and the like :

    www.tiviboo.com/oceanretro2

    Also, a color version...

    www.tiviboo.com/oceanretrocolor
    www.tiviboo.com/oceanretrocolor2
     

    Attached Files:

  25. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    @Twinfox please can you confirm the terms of use on this? Thanks

    AaronC
     
  26. Randy-Edmonds

    Randy-Edmonds

    Joined:
    Oct 10, 2005
    Posts:
    1,122
    Awesome. but it does run slow on my macbook (GMA950), maybe 2fps.
     
  27. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    Yes, definitely. It runs very smoothly on an iMac 2.4, but kills a Mini 1.6. This is because it uses lots of image effects and 64 ocean tiles,... which are probably not needed for such a scene. Also, quality is set to fantastic and the webplayer to 1280 x 720...

    Will make lighter versions :)

    And seconding Targos : can we use this package for anything else than demos ?

    [EDIT] see my previous post for updated builds and an "early color cinema" version...
     

    Attached Files:

  28. ToreTank

    ToreTank

    Joined:
    Jun 23, 2008
    Posts:
    165
    TwinFox - great work indeed! I've been playing around with your example, and I'm not sure if you guys have already sorted it out, but the issue with the "failing intialization" seems to have its origin in the gaussian random function where the first value can be chosen as 0.0, in which case the Mathf.Log will happily return a NaN and *poof* there goes your values. Not sure if my "fix" is correct, but it seems to work (haven't noticed any failures lately).

    Code (csharp):
    1.  
    2.  
    3. function GaussianRnd () {
    4.     var x1 = Random.value;
    5.     var x2 = Random.value;
    6.  
    7.         if (x1 == 0.0)
    8.                x1 = 0.01;
    9.  
    10.     return Mathf.Sqrt (-2.0 * Mathf.Log (x1)) * Mathf.Cos (2.0 * Mathf.PI * x2);
    11. }
    12.  
    13.  
     
  29. OXYGEN

    OXYGEN

    Guest

    Joined:
    Mar 16, 2008
    Posts:
    1,101
    Hi Guys is there a version of this demo floating around that works with unity Iphone?
     
  30. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    Looks like you found it, congrats ToreTank ! :D

    I tested the submarine scene several times : not a single init problem anymore. It seems rock solid. Just updated the builds with your modified script, so that everyone can test online and confirm :

    www.tiviboo.com/oceanretro
    www.tiviboo.com/oceanretro2
    www.tiviboo.com/oceanretrocolor
    www.tiviboo.com/oceanretrocolor2
     
  31. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    I've ditched this as Twinfox didnt bother responding to our usage questions. A bit of clarification there wouldnt have hurt would it mate? Or common courtesy.
     
  32. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    Well... in the meantime, let's make some cool demos ! :)
     
  33. ToreTank

    ToreTank

    Joined:
    Jun 23, 2008
    Posts:
    165
    I've been working a bit with the FFT-based water and I've added a real-time refraction/reflection shader to go with it. If anyone's interested, I'll clean up the code and post it (It's now all C#, as I have rewritten it while following this: http://www.gamasutra.com/view/feature/3036/deep_water_animation_and_rendering.php to try to understand what's going on - I have obviously forgotten all about this Fourier-math thing except its name), but it's not really presentable at all currently. The shader should work fine with the javascript version though, obviously, so if anyone wants to port the relevant parts (the rendering of the refraction/reflection maps that is) poke me in a PM and I'll pass it over.
     

    Attached Files:

  34. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,687
    I guess we are all interested! - and also Twinfox asked for a shader :D

    Oh and guys i think twinfox made it already clear that this is free to use because it is based on the tessendorf paper.

    From my PMs with him i can only see that he wants the community to optimze it:

     
  35. mike123

    mike123

    Joined:
    Feb 8, 2009
    Posts:
    4

    Here are some ealy test of the shader
    reflection
    refraction
    Foam
    Deepwatercolor
    sun reflection light
    and the FFT2 Fuction in the MathLib by Ben is now generate a texturemap and from that we can genrate a normalmap so there is no more need to update vertex,normal,
    so on only 1 height map in floatpoint texturemap and
    1 normal map , 1 foam map, the detail map is just the normal map scale by 10 are passet to the shader and boom bang Ocean is comming to you soon
    Mike
    Here are a video link .... enjoy
    http://video.msn.com/video.aspx?vid=97943e36-4d15-4f11-bb77-abb019400bf2
     

    Attached Files:

  36. Charles Hinshaw

    Charles Hinshaw

    Joined:
    Feb 6, 2008
    Posts:
    1,070
    Easiest way is to add it as an attachment.
     
  37. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    That's looking very nice Mike. I especially like the sun reflection light. Would love to take a peak at how you did this.
     
  38. ToreTank

    ToreTank

    Joined:
    Jun 23, 2008
    Posts:
    165
    Damn it mike, that looks too awesome! Nice work!

    I ported the shader back to the original javascript, so if anyone still wants it - even after having been teased by mike's stuff - let me know. I would upload it if I could, but I'm currently on a very unstable/slow connection and I cannot seem to get the forum attachment upload to work, so I think the solution is the trusty old e-mail.
     

    Attached Files:

  39. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    Guys, this is amazing work ! PM sent, ToreTank.
     
  40. azeitler

    azeitler

    Joined:
    May 14, 2008
    Posts:
    162
    okay guys, this is just awesome :)
    i did not follow this discussion in detail - bottom line: how can we others get this thing and its sources?
     
  41. mike123

    mike123

    Joined:
    Feb 8, 2009
    Posts:
    4
     
  42. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    :eek: Wow, Mike, that's awesome! That is -exactly- the type of ocean shader I was talking about when I started this thread. Can't wait to take it for a spin! :)
     
  43. mike123

    mike123

    Joined:
    Feb 8, 2009
    Posts:
    4
    tanks alot bigkahuna

    well all the credits must go to TwinFox
    and all the othere people that has made a demo
    the problem i have only acess to a mac one week a month so it has been a bit of a problem start writing a shader but Vic20 has help me out by stripping the files out and send to me. so tanks Vic20 and TwinFox..

    i am working on underwater now and beach shore waves,
    Periodic FFT , Caustic pattens
    the Periodic FFT is so when you have the right settings you can save the butterfly Complex map out to a texture and when you load it back in the water will stay the same way all the time
    i have a hollyday for now from work , one week and 3 days i think the shader will be finish and i will hand it out to you all with a sample...

    Best regrads
    Michael Hansen

    HQ Ocean Download 90 megabytes
    http://rapidshare.com/files/217659944/NewOcean.wmv
    MD5: 515576B0D822FB2C3F901309B8FA9632
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    boys,
    you are great!
    I would like to see this on the wiki: it is awesome.

    keep on going, lars
     
  45. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Wow - there's really some amazing progress on this! I'd second that this would be awesome to have on the Wiki!
     
  46. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    471
    :oops: :oops:
     
  47. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    471
    Awesome absolute.... i was also looking this Weekend and must say WOW absolute the best Ocean Shader i have see so far for Unity.
    Can't wait....
    Hopefully there is also little progress on the iPhone Ocean Shader....
    thank you !!!
    kerstin
     
  48. TwinFox

    TwinFox

    Joined:
    Jan 9, 2009
    Posts:
    66
    :eek: Wow, what great progress you guys have been making, there is some mad talent here!

    @ToreTank: Great work on finding and fixing the bug! It drove me mad when I was still developing the script. Also, nice to see you have made good progress on the reflection/refraction part. Mind sharing your approach? Is it based on cubemaps or mirrored meshes?

    @mike123: I already sent you a PM, but again, this is incredible work! I'm so glad that Unity finally expanded to Windows, so we could take advantage of your expertese ;).

    @dmorton: Wow, I never thought it was possible on the iPhone... Makes me wonder why I bothered with FFT at all when the Gerstner waves look so convincing. Simply excellent work!

    @AaronC: Anyone can freely use the script, and edit it as they see fit (think of MIT license). Also, the Exocortex DSP that provides the FFT operations uses the BSD license, so no problem here either. I'm sorry to hear you abandoned the script because of licensing questions, but to be fair a PM would have reached me much faster.

    @photon: Honestly, I don't know who currently has the latest and greatest version, and if they are willing to share the code. The latest version I worked on can be downloaded here (v3), but I'm happy to say it is outdated and won't produce the same quality you see on the latest shots. Would someone perhaps be willing to contribute an updated script to the wiki?
     
  49. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    ToreTank is on holiday, but he allowed me to post his package, which contains an example scene. Trying to attach it gives me a forum error, so you can grab it here :

    www.tiviboo.com/unity/oceanpackage.zip
     
  50. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    Hi all

    This is absolutely fantastic . Great team work.
    it would be nice to see the water(plane) before hitting the play button.
    some kind of a plane preview. i don't know if this is possible.

    thanks again

    Norby