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. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I'm looking for a full ocean shader, similar to what is available in Quest 3D and DX Studio. I can provide additional information and examples of what has been done in other engines. This is a paid project. Please contact me privately by email so we can discuss the particulars.

    Thanks!
     
    AntonioModer likes this.
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    I'm not sure exactly what you're after but is the water shader set used in the island demo suitable? There are two IIRC, the main water shader then another for the "foamy" shore area. Sorry if I'm off the mark but I thought I'd mention that in case it helps. Good luck!
     
  3. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I'm not talking about a water shader, but rather an Ocean Shader, with ocean waves and foamy crests. I've modified the Sine Wave Modifier script to animate a mesh, but that only gets me about half way to where I'd like to be.

    Here's some examples:

    Virtual Sailor (look at the two screens at center/bottom right):
    http://www.hangsim.com/vs/screen.php

    Quest3D (check out the Ship Sim 2008 video):
    http://quest3d.com/index.php?id=209

    DX Studio:
    http://www.dxstudio.com/gallery.aspx

    And Ogre 3D (check out the nVidia ocean shader screens:
    http://windmek.ca/ogre_renderings

    And here's the nVidia Ocean shader that most of these are based on:
    http://developer.download.nvidia.com/shaderlibrary/webpages/shader_library.html#Ocean
     
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    I took a brief look at NVIDIA shader. It looks pretty much like our water shader (in fact, ours has better reflection), just with added sine wave perturbation in the vertex shader. Should be quite easy to add... but now it's sleep time here! :)
     
  5. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Well, actually what I'm after is more like the Virtual Sailor screen at the top. Both Quest 3D and DX Studio offer similar ocean shaders (sine waves from 2 directions, variable foam on wave crests, boat wakes on the ocean surface, etc.) I just didn't post screen shots of these since I'm using my Mac (and their demos only run on a PC).

    @Aras - Sleep? When did you guys at Unity Tech start sleeping? Geez, sounds like things are slacking off over there! ;) (I'm just teasing of course!)
     
  6. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,687
    You mean Tessendorf water? That's what i'm also looking for - internet is full of manuals but i feel like i never visited school when i look at the math.
     
  7. horsman

    horsman

    Joined:
    Jul 19, 2008
    Posts:
    156
    It can be a little much to do the tessendorf water, In fact many people spend a long time trying to get it looking right.

    You'd need both a shader or script that moved the vertices and a shader that did bump mapping for the more detailed bits. You'll also need a Fast Fourier Transform library and a good working knowledge of math. My guess is that any script you wrote from C# wouldn't be fast enough to do a good job on it ( Written in C with very lightweight code is often just able to make it look good enough).

    I think you are best sticking to a simpler approach or at least a shader only approach.
     
    bittumondal likes this.
  8. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434

    Attached Files:

  9. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434

    Attached Files:

  10. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    And here's my best efforts so far using a modified sine wave generator script, Pro water, and some tweaked textures. Not bad overall, but not nearly as nice as can be done in many other engines...
     

    Attached Files:

  11. TwinFox

    TwinFox

    Joined:
    Jan 9, 2009
    Posts:
    66
    I played around with the Tessendorfian ocean during the christmas holidays, and have the vertex displacement working:


    The shader is only a stock Reflective/Bumped Specular with not-so-perfect textures applied. I used the Exocortex DSP for the complex 2D-FTT, and it seems to be fast enough with a 32x32 grid.

    For those interested, a zipped webplayer is attached.

    You'll want to run the file a few times, as the waves are randomly generated and not always very interesting. Be warned though - it sometimes crashes the browser for reasons not clear to me. Also, there is some jitter in the ocean which is not present when played in the editor - entering full screen removes it a bit. Don't get seasick :D.
     

    Attached Files:

  12. KlaRo115

    KlaRo115

    Joined:
    Feb 24, 2006
    Posts:
    675
    How did you guys script this vertex displacement for the waves?
     
  13. KlaRo115

    KlaRo115

    Joined:
    Feb 24, 2006
    Posts:
    675
    Oh, and I'm also working on creating reallistic water, but mainly playing around with shaders... :)
     

    Attached Files:

  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,898
    great efforts so far – i would realy like to see more.
    what about moving this thread to the sahder lab / showcase? because here it might get a bit lost i guess.

    lars
     
  15. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    ... because my whole purpose for starting this thread was to (hopefully) recruit someone to create a true ocean shader (comparable to what is available in other engines). So far, I'm sorry to say, there haven't been any takers. :(

    Incidentally, although the posts here might be good compared to past efforts in Unity, they pale in comparison to what is possible with Quest3D and DX Studio out of the box with no additional coding.
     
  16. horsman

    horsman

    Joined:
    Jul 19, 2008
    Posts:
    156
    The interpreted script just isn't fast enough to get that quality of wave made without the engine supporting it, unfortunately. Perhaps with C++ plugins and pro some of it could be done.
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Scripting is JIT compiled rather than interpreted and generally gets at least 50% native C++ speed--up to 70% in some cases with built-in arrays, I gather, which is what you'd use for this--so I'm not so sure about that. TwinFox's attempt was pretty decent.

    --Eric
     
  18. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    So what you're saying is that this can't be done in Unity, at least not without some Herculean effort?
     
  19. horsman

    horsman

    Joined:
    Jul 19, 2008
    Posts:
    156
    I'm not sure if you know the area, but a 32 by 32 grid is not sufficient, and the algorithm's bottleneck is the Fast Fourier Transform. Even on a 4 core 2.8, doing an acceptable grid of 256 or 512 (which is about 64 times and 256 times more expensive than Twinfox's attempt, respectively) is a task with the Fast Fast Fourier Library, in assembly language. JIT code simply can't hack it, in this case constant factors are important, and the underlying implementation of basic functions.

    There are plenty of other options, like a number of baked wave animations or some other wave generation technique. There's potential for doing the FFT on the graphics card, and also other techniques for oceans.

    Best luck, of course! If someone got the tessendorf model working well, it would be very impressive.
     
  20. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
  21. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
  22. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,687
    That's really the best i ever saw - and the explanation does not sound that complicated.
     
  23. horsman

    horsman

    Joined:
    Jul 19, 2008
    Posts:
    156
    Wave Particles are very limited in some ways, however. They tend not to perform well on large bodies of water, and are instead used to model the interactions between objects and water. If you only need a small body of water, wave particles will do the trick.
     
  24. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Hmmm Wave Particles.

    /me drools...
     
  25. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    Hi TwinFox

    is your script available , this is looking pretty good.

    Norby
     
  26. TwinFox

    TwinFox

    Joined:
    Jan 9, 2009
    Posts:
    66
    Well, I'm still chasing the impossible and using a FFT based approach for ocean simulation.

    The water is constructed from identical planes that tile seamlessly, each tile being a 32x32 grid. A procedurally generated 32x32 pixel bump map is now used to represent the smaller waves. Much effort went into building the normal and tangent maps to get the shading correct, but it was worth it.

    There is still some initialization problems with the water, so I'm once again attaching a zipped web player in case it needs to be rerun. It does run noticeably better fullscreen.

    Norby:
    This script is still pretty much WIP, but I am willing to share it to those interested (including bigkahuna :)) PM me and I will send you a link. I don't want to put this in the Wiki yet, as it should IMO be reserved for finished code.
     

    Attached Files:

  27. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,687
    here is what i did with that script so far - webplayer following in some hours

     
  28. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    Thanks Twinfox

    Wow i must say that the pictures are looking great.
    thanks for willing to share with us.

    Vic20 are you using procedural foam map ?

    Norby
     
  29. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    Twinfox

    i just started the web player and i must say i am really impressed.
    this is the best ocean shader made within unity for now.
    also performance is better.
    keep on the good work.

    norby
     
  30. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Twinfox - The webplayer is pretty impressive, definitely the best done with Unity so far. PM sent...
     
  31. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    ummm I can't view it from the webplayer I get the skybox and thats it, I have an Imac Intel 2.4 procesor 3gb of ram and ATI,RadeonHD2600, don't get any error in console or any other thing out of the ordinary besides the file

    Edit: I can view it by clicking on the .unity3d file, you have an html error, firefox 3.0.5
     
  32. TwinFox

    TwinFox

    Joined:
    Jan 9, 2009
    Posts:
    66
    Norby, bigkahuna: Thanks for your kind words.

    bloodtiger10: This is known behavior. Sometimes the ocean initialization fails and you only see the skybox. I have no idea why this happens, as it seems to occur randomly. Just reload the page a few times and it should work.
     
  33. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Yeah, I ran into this once in the editor (thanks, by the way, for sharing this). Second time I tried it worked. Weird that it doesn't send up any errors. If I sort out the reason I'll be sure to let you know.

    Now that I've had a chance to actually look at this (albeit a brief look) this is very cool. Thanks for sharing!
     
  34. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    ok. :D thank you
     
  35. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,687
    i always get errors when the water does not show up in the editor - i'll post when i next time get one... may took a while - busy with some optimisation
     
  36. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Thats really nice, looks good on MBP

    Well done. Will be keen to see where you take this

    AC
     
  37. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,687
    got no errors today but the ocean was always on when i pressed play

    The little demo from the screenshot above (sometimes the tiles seems not to fit, that has nothing to do with the water it's something i just made wrong in my last script today.

    http://www.hessburg.com/unity/U-Boot0815_Test.zip
     
  38. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Looking good!

    Personally I'd recommend desaturating the textures by 50% as typically designers etc tend to over blow the saturation due to lcds being so high quality and vibrant. Washing out the saturation often makes things look more realistic-if thats what you're aiming for...

    //2c

    AaronC
     
  39. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,687
    i just received a message from someone with a mac book pro getting only 3fps with this demo. I get 55-70 on a 4 core. Anone else with such extremely bad fps?
     
  40. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    It appears that I'm getting less than 10 fps (could be about 3-5 fps) on my first gen Intel iMac Core Duo.
     
  41. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    2.16ghtz 1st gen MBP 256mb vram 2gigRam
    =10-15fps on highest quality and resolution

    HTH
    AC
     
  42. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    46 FPS 1920 x 1200 (Fantastic)
    2 x 2.8 GHz Quad-core intel Xeon

    Norby
     
  43. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    ... I should add that I ran it in windowed mode, 1024x768 resolution, Fantastic quality setting.
     
  44. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Wow - this is looking pretty good and useful. Framerate was also okay on my Mac Pro (4-core) but I'd have to see what it's like when there's more in the scene ;-)
     
  45. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
    I'm getting around 30fps average on a 2008 MacBook Pro.

    I noticed I could at times see what appeared to be seams and lod-type popping when looking off to the right of the boat.
     
  46. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,687
    that's just an unfinished primitive script that causes that, a kind of frustum culling to avoid useless copies of meshes which are out of view - unfortunately i forgot that while the tiles jump every 50 meters back to the boat that the boat still moves 50 meters before that happens :D so it can happen that you see some outdated unanimated tiles that come back into view.
     
  47. TwinFox

    TwinFox

    Joined:
    Jan 9, 2009
    Posts:
    66
    After some indexing acrobatics, I managed to optimize the ocean script up to the point where I get 50 fps in webplayer, and 150 fps in standalone on my 2.2 GHz MBP. It would be nice to know what kind of speeds other people get on their hardware.

    There is now a simple LOD implemented, which allows the ocean to extend all the way to the horizon. Each tile is drawn separately, so there is an increase in draw calls. This is, however, something which can be quite easily optimized.

    I'm afraid this is as far as my skills go. The ocean is still missing is a good shader (the one used is not really up to par), and object reflection/refraction (cubemap approach cannot be used because of the large topography). Realizing these would require fairly good knowledge on shader writing, which I unfortunately do not possess. Hopefully someone in the community would be willing to contribute.

    The zip file includes the webplayer, as well as an unitypackage containing the ocean script and all necessary resources. Note that the initialization bugs are still there, so restart the player if necessary.
     

    Attached Files:

  48. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    Wow Twinfox

    it's amazing what you have created,
    it's looking fantastic.you are my hero

    Norby
     
  49. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    @TwinFox - looks like you've got the mesh animation wired, but you're right, it needs a better shader. I am getting some minor error warnings when I create a new project with your package:
     

    Attached Files:

  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Even with that shader, it still looks pretty darn nice!

    --Eric