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

    joukev

    Joined:
    Apr 22, 2013
    Posts:
    10
    Okay after some tinkering I could run the example from head@hunter with a mobile FPS controller and added some 3D sound and mobile skybox. Runs alright -

    My big #1 question is: how to change to dark(blackish) color of the water?
    Have looked at the script and shaders but could not nothing seemed to have effect.
     
    Last edited: May 23, 2013
  2. HeadHunter2009

    HeadHunter2009

    Joined:
    Jul 3, 2012
    Posts:
    50
    Hi guys, finilly i have some free time, and i made project package for you. Tested on Unity 3.5.7
    Package should work on any platform, and maybe in unity free (if reflection disabled)

    What i changed:
    1. Shader now have 2 lods, it will automatically set lod1 (should be faster on mobile) if reflection disabled
    2. Added cool looking editor script for ocean inspector
    3. Added wind controller, it will random smooth change wave scale during gameplay
    4. Added simple mist simulation around player
    5. Ocean now should work faster on mobile devices
    6. Added realistic sinking future to Boyancy.cs, just trigger sink in inspector during gameplay to see it in action
    7. Boyancy.cs now work with box colliders (they work much faster on mobiles)
    8. Added boat wake, it will automatically produse foam at player position
    9. Improved ocean tiles movement alghorithm

    Download (for chrome right click > save link as):
    View attachment $OceanMobileOptimized.zip
     
    Last edited: May 26, 2013
  3. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    What Unity version is this for? Would it work with desktop systems also? Gonna give it a go...

    EDIT: Tried it on Unity 3.5.7 and worked like a champ. Got some "unused variable" warnings but otherwise compiled and played just fine. The boat wake implementation is nice and I liked your mods to the buoyancy script. Overall, a truly outstanding mobile ocean shader. Thanks very much for sharing.
     
    Last edited: May 26, 2013
  4. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    @Head@Hunter
    Thanks a lot for the update. :cool:

    BTW, the ZIP file can be download from Opera but the link not working with Chrome, IE and Firefox. Anyone else have some trouble with this? :(
    I'm on Windows 7.
     
  5. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    It worked a minute ago using Chrome, but now that I've tried it again it isn't now.
     
  6. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Thanks head@hunter, I'll give it a go tomorrow. I couldn't download it either on chrome or IE :(
     
  7. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    btw, anyone got a chance to compare this version with unity water? last time i checked unity water was way faster than our mobile implementation.
     
  8. HeadHunter2009

    HeadHunter2009

    Joined:
    Jul 3, 2012
    Posts:
    50
    To download in chrome try: right click>save as

    Yes there some warnings, i just dont have time to fix it, but they dont effect performance. And yes it work olso on desktop.

    What is UnityWater? Does it do mesh deformation or something?
     
    Last edited: May 26, 2013
  9. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I think creat327 is talking about one of the Unity standard assets, specifically the first couple of ocean water assets that came with 3.x.
     
  10. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    it's on unity 4.x too
    just go into "assets" menu, then "import package" then select "water basic" or "water pro".
    You have about 4 different versions of water included with Unity. The one on Pro, was named Water4, and it was way faster than the mobile version of ocean shader when I tested it a few months ago.
     
  11. joukev

    joukev

    Joined:
    Apr 22, 2013
    Posts:
    10
    The new version runs good, not yet tested on iOS dev but will do that asap. Will do some testing with the wake etc. Thanks again!
    EDIT: works fine on iOS (iPad 2: 24 FPS, whereas the "older" version did better at 30FPS but didn't have the particle systems etc.)

    PS color can still not be changed, no matter what type I select or adapt colors in the editor (running unity3d v4 on OSX).
     
    Last edited: May 26, 2013
  12. HeadHunter2009

    HeadHunter2009

    Joined:
    Jul 3, 2012
    Posts:
    50
    But standart unity water dont have anithing similar with ocean, it should be a lot faster becouse it just static plane rendered with symple shader.
     
  13. spraycanmansam

    spraycanmansam

    Joined:
    Nov 22, 2012
    Posts:
    254
    Yep. Pretty... but useless for anything functional.
     
  14. HeadHunter2009

    HeadHunter2009

    Joined:
    Jul 3, 2012
    Posts:
    50
    Why useless? We working on online game called DarkWaters, it based on this ocean. Also this game for mobiles.


     
  15. spraycanmansam

    spraycanmansam

    Joined:
    Nov 22, 2012
    Posts:
    254
    I was talking about Unity's Water 4 ;)



    :)
     
  16. joukev

    joukev

    Joined:
    Apr 22, 2013
    Posts:
    10
    Head hunter,
    sorry for harassing you again but what about the color? clearly You could change it in your (mobile) game...
     
  17. HeadHunter2009

    HeadHunter2009

    Joined:
    Jul 3, 2012
    Posts:
    50
    Ok, i will explain how it works, for lod2 shader (when reflection enabled in ocean inspector) you can use water type selector, and set colors in expandable parameter for each water type. If you disable reflection you need to set water colors in Ocean material, in the lower part of material shader settings in inspector you will see 2 colors, you can set this colors to anithing you want. Have fun ;)
     
  18. joukev

    joukev

    Joined:
    Apr 22, 2013
    Posts:
    10
    Yeay thanks it worked - by changing the lower part of the material shader settings (SurfaceColor LOD1 and WaterColor LOD1). I have the indy version, so switching on/off reflecton did not do anything (very curious whether it is worth it ;-))
    Added some localized sounds, performance is now back at 30 FPS on iphone 4S

    Thanks again!
     
    Last edited: May 27, 2013
  19. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    773
    I've just tried the posted link to Head@Hunter's latest build (OceanMobileOptimized.zip), and all I get is a 1x1 image called "clear.gif". I've tried both opening and saving it, using several different browsers, and get the same thing with all of them. A few others have indicated they've had problems as well. If someone who has it could post a working link that can be used from IE or Firefox, it would be greatly appreciated. Thanks.
     
  20. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is my attachment of the same zip file. To down load this I simply clicked the link in Safari.
    View attachment $OceanMobileOptimized.zip
     
  21. bigkahuna

    bigkahuna

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

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    hi head
    I was able to finally test it on a device. It seems to run at the same speed than the version I uploaded. I hit 60 fps on both version on a sgs2. Were you able to run some benchmark?

    I'm hoping to get back my old nexus one phone, which ran it slow slow, so maybe that one is better for testing.

    also about your version, in mine you could change the water roughtness (scale, and so on), on yours when I change the scale, it goes back to some default value as soon as I hit play. I believe you have the values hardcoded somewhere. Also the bumpiness is missing (the little grainy on top of the water), was that completely removed?
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I always thought that there would be some solution using two cameras and adjusting their viewport live...

    Looking at your image, where this would fall down would be the curve on the lens of the moving water.

     
  24. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I don't recall how it was done, but one of the first versions of the community ocean project had it. When I tried to convert it to 3.5.x it was pretty badly broken, but I'll have to give it another go.
     
  25. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
  26. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Ok, so here are my tests:

    All versions run at 60 fps on samsung galaxy 2 and higher phones. So I guess unless you are very cpu bound, it doesn't matter which one you use.
    Now, I went back to my old nexus one phone. It's actually an awesome phone if you consider how old it is. I use it for benchmarking with old phones.

    Results
    - My version from: http://forum.unity3d.com/threads/16540-Wanted-Ocean-shader?p=1119643&viewfull=1#post1119643
    7 to 8 fps, with all fancy stuff set on, and 9 fps with fancy stuff off.

    - Head@hunter version
    5 fps by default, if you remove reflection it goes to 8-9 fps. Since on the shader removing reflection has zero impact on my version, i'm guessing the boost is on the lod improvement.

    - Water4 from unity4 pro package.
    12 fps

    so don't ask me why, but default water4 is faster.

    obviously you have to pick your choice, water4 has some short-comings.

    About the 2 mobile ocean versions, well, I'll have to dig into head's changes, i'm not sure what was improved on performance right now since it runs about 20% slower on my tests with nexus one. Maybe the slow down is on foam or some other script and the shader is truly faster, but I disabled mist and boyancy and all the stuff and got the same results. For all others, if you have a sgs2, i guess it doesn't matter which one you pick since i see no difference, this is more just an exercise on how to make it faster/cooler.
     
  27. HeadHunter2009

    HeadHunter2009

    Joined:
    Jul 3, 2012
    Posts:
    50
    You mean this lighting caustick effect on top of the water? Its wery simple to make, its just some bunch of textures what get assigned to material and animated from script ;)

    Scale get changed from wind script, so more wind then bigger waves.

    Improvement was in function OnWillRenderObject function, when i changed how this work i get around +10 fps on my Tegra3 tablet.
    Bampiness not missed, you can play with different bump textures to get best result.
     
  28. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    No, I'm talking about what it would look like when the camera is only half under and half above the water, such as in the photo I first linked to and the bottom right of the two images attached to ToreTank's post here: http://forum.unity3d.com/threads/16540-Wanted-Ocean-shader/page3?p=148822&viewfull=1#post148822
     
  29. joukev

    joukev

    Joined:
    Apr 22, 2013
    Posts:
    10
    For now I am sticking to head@hunters work (runs 30 FPS on my iPhone 4S), and this afternoon it worked eerily well in the Oculus Rift.
    Holy guacamole!!!!!!! I had to initate the pro trial so now I have the surface reflection working. Also included some ocean sounds and 3d effects. Still have to learn the intricaties of importing geometry for my ship and some keyboard control (suggestions welcome).
    Will try to make a short impression end of this week....
     
    Last edited: May 28, 2013
  30. HeadHunter2009

    HeadHunter2009

    Joined:
    Jul 3, 2012
    Posts:
    50
    Oh, i disabled this, becouse its extremly expencive on mobile devices.

    Just add box collider to your ship model(prefab), then add rigidbody component, and attach Boyancy.cs. Then you can move your ship like this:
    Here how you can control inputMoveDirection:
    Hope this help someone ;)
     
    Last edited: May 29, 2013
  31. skeptika

    skeptika

    Joined:
    Dec 31, 2011
    Posts:
    108
    Just wanted to say thanks to everyone still working on this project, it really is awesome.

    I've put my Kart game on the backburner while I work on other things, but as an example of how this community project is used, I was making a Kart game with a water-based component, think of it as Mario Kart with a dash of Wave Racer. Obviously there's not much to this 'lil demo, just my hover kart, a tiny bit of track and the ocean, but hop in, jump off the track and go cruising around the ocean (ASDW to move) and try to jump waves, it's freaking fun IMO to the point I thought of ditching Kart and just going Wave Racer style :) All this under 45 draw calls is amazing. Thanks to those working on this, keep it coming!

    https://dl.dropboxusercontent.com/u/30841964/Kart/Demo.html
     
  32. spraycanmansam

    spraycanmansam

    Joined:
    Nov 22, 2012
    Posts:
    254
    Yeah, Toretank's half-in/half-out implementation is pretttty expensive.. I can see it crippling mobile devices. But it works :)

    It's not perfect, but it works.
    It uses an extra orthographic camera to get the height of the water and uses those values for the transitions between above and below.
    Technically you can position the camera at run time so you can see half-in/half-out but it's not perfect... I think this is down to the depth rendertexture lookup. They have implemented a 'fade' effect between the two to blend.

    The underwater effects are a post effect.. and a bit expensive. But like I said, it works. I'd love to work on a better system, lots of things to do at the moment tho :p

    bigkahuna, let me know if I can help you get it working for you to try out.
     
    Last edited: May 29, 2013
  33. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    773
    I had the same problem as before when I tried your link using Firefox, but it at least works now in IE (under Windows), so thanks for re-posting. :D
     
  34. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    @spraycanmansam - private message sent.
     
  35. Cocoss

    Cocoss

    Joined:
    Jun 4, 2013
    Posts:
    2
    Hi everybody.

    First i want to congratulate all people who has participate to this project. But i need some help because it's hard to make it work. I downloaded and imported the package in unity and at the beginning not any scripts were correctly attached to its object. I tried to reassemble all this "puzzle" and i finally succes to make the cube floating, but the render with reflexion is very dirty with Green water and zoomed sand texture on it. I'm a beginner so is there someone who can help me ?

    I have also another probleme with physics. I want to make a pirates game where you can walk with FPS view (like Elders scroll) and get in ships. If you want to drive it you just nead to point on it and then the character will be attached to the ship and the camera view will go into Third Person View. My problem is that if go on a boat and point to the soil the boat is affected by the physics of the player and the player is ejected. So i tried to increase the mass of the boat but if i do that, the boat sinks.

    I hope that my english is as good as you can understand.

    Thanks in advance and keep doing good job like that !
     
  36. joukev

    joukev

    Joined:
    Apr 22, 2013
    Posts:
    10
    Just a update but no pics yet: yesterday the olympic sailing crew was here and the oceanshader + rift made a huge impression. Kudos to all of you.
    Only thing I changed to head@hunters scene was duplicating the box to add some more elements, with 3D sound sources attached and adding a simple sailing boat (found on google sketchup/3d warehouse) and imported the .dae file. For the rest I also built the scene as a iOS app and showed in on a ipad... Makes grown men puke when the "storm" setting is on.
    Kudos to you all!
     
  37. Julian-S

    Julian-S

    Joined:
    May 31, 2013
    Posts:
    73
    First off, thank you to head@hunter and all those who have contributed to these wonderful scripts and shaders.


    I'm working on a multiplayer game, and trying to use head@hunter's shader and script. Do you guys have any suggestions on how to get it working for multiple players?

    I was thinking somehow having a separate ocean follow each player or something, but if I try to use networkView.isMine == true with a player, it always seems to end up false for some reason.


    I guess another idea would be to not have it follow any player and only render tiles of ocean that a player is on. Going to try to make it so that it doesn't follow a player.

    Any help would be greatly appreciated!
     
    Last edited: Jun 7, 2013
  38. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    Hi !

    How can I change the specular color ?

    $726119seaspec.jpg
     
  39. navalaction

    navalaction

    Joined:
    Jun 18, 2013
    Posts:
    12
    We have not used headhunter shaders. For our own proprietary Unity shader we had to write a server. Server transmits the necessary ocean info to players client, in a cheaper version you can appoint one of the clients to transmit ocean info to all other clients.

    here is how our water looks in Unity

    http://www.navalaction.com/
     
    Last edited: Jun 23, 2013
  40. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,122
    The Game and Ocean look fantastic.
    Any chance your team would consider releasing the server side code and ocean generator as an asset on the store.
    A standalone version would sell great as a Ocean kit for budding naval sims creators.
     
  41. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    NavalAction: This looks fantastic! Good work.

    I'm sure the asset store would love to sell your ocean at any price. Very nice. I'm sure the water itself would be a winning package by itself, and the multiplayer water even more so!
     
  42. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    It is awesome to see this project still going, but this is seriously still being developed by passing zips of Unity packages?

    @Head@Hunter:
    As it would appear you have the latest version of this package, could you perhaps set up a github repository for this project to live in? Should make contributions, issues and y'know changes easier to track :)
     
  43. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    I talked to Martin Upitis. He is responsible for a lot awesome shaders for Blender's game engine.

    He's working on a water shader, which looks darn good. I asked him if there would be any chance to write such a shader fur Unity. He told me that he's really eager to take a look into Unity and maybe writing shaders for it.

    Here is his most recent work. He is still working on volumetric lighting and geometry tessellation.

     
    Last edited: Jun 24, 2013
  44. Kridian

    Kridian

    Joined:
    Jan 24, 2012
    Posts:
    55
    ^^ Wow! So glad Martin is working on his water shader again. I think it's one of the best ones out there at the moment.

    Keeping my eye on this one.*
     
  45. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    573
    is this available for download or its a upcoming release in the unity store?
     
  46. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    458
    That type of water can be achieved with unity.

    just import the water (pro only package) if you have unity pro

    otherwise grab the water from the island demo.

    if you don't know how, i can help you on how to
     
  47. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    458
    Achived with unity i think

    $CryEngine-3-Water-Surface-Screenshot.jpg
     
  48. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    Yes that is some awesome stuff. The features are really noteworthy

    - reflection with accurate fresnel refectance model
    - refraction with chromatic aberration
    - projected caustics on geometry from the water surface based on normals
    - seamless transition to underwater (no fake fog added)
    - accurate water volume with light scattering
    - view and light ray color extinction based on water color and sunlight
    - simple coastline detection based on terrain`s height-map

    Hopefully he ports that to Unity in the near future. It's about the time that Unity get's some modern water shaders.
     
  49. spraycanmansam

    spraycanmansam

    Joined:
    Nov 22, 2012
    Posts:
    254
    Pretty sure you'll find that's Cryengine :p


    I have ported his previous shaders to Unity in the past as a bit of personal research, including the underwater stuff. It works great, the source I ported was very much setup for the one scenario though. The underwater fog is particularly unwieldy for separate objects in the water, but it can be made to work with some commitment.



    I found Martins work and Crysis very inspiring (as you can probably tell from looking at the Crysis picture and our screenshot in this post :p) and while I couldn't use it for our needs in the end, I incorporated similar approaches and elements into our own ocean shader, with our own flair of course ;)


     
    Last edited: Jun 24, 2013
  50. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,687
    I'm also still working on the water and environment for my iOS sub sim. In development for 4 years now, I think it's already the 5th new ocean for this project. :-? - runs degraded in quality on iPad1 (to avoid the damned dependent texture lookups) this is the quality setting on iPhone4S iPod touch 5 (50-60 fps). The ocean runs completely in the shader, CubeMaps are calculated on the fly. I still hope I will be able to add real time reflections if I upgrade to a unity pro subscription. (I've also experimented with comparable high poly precalculated geometry loops before which worked fine but the load on the poor 3GS CPU and memory consumption was a bit too high for my taste.)

    Well, not looking as good as the last screenshots but it's on mobile. :)

    $WOTA-wolves-of-the-atlantic.png

    $periscope.png