Search Unity

Wanted: Ocean shader

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

  1. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    That is interesting. I told you, your water shader looks great in the Stranded Deep thread :) Didn't know it's influenced by Martin's shader.

    But it's only developed for Stranded Deep right? And I'm not sure how good that works for beaches and not so deep water. As you said, it is customized for your needs, which is fine.
     
  2. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    Looks great for mobile.
     
  3. navalaction

    navalaction

    Joined:
    Jun 18, 2013
    Posts:
    12
    Suddenly lot's of water!)))
     
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    And don't forget: This is a community project thread, so, pay it forward and let people know what they can do to create their own water.

    Please DON'T STOP POSTING your water here, as it's great to see what you are doing, but if you can release any code, ideas, solutions, discussions, on what you did to make your shader work for your game or your platform, PLEASE DO!

    If you have links to things like the CryEngine or Blender GameEngine code and tips on how to port that over to Unity, Great!

    If you have a repository of your code you want to share, FANTASTIC!

    This is the Community Ocean Shader project "Wanted: Ocean Shader", after all!
     
  5. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    458
    oh drat, i didn't notice it was cryengine water. but thats one beautiful ocean shader you got there
     
  6. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I experimented with the Blender Game Engine years back, boy has it come a long way since then. One crit though (and this seems endemic to all the "underwater scenes" I've seen here and with other game engines), and that's the animated distortion everyone seems to be using. In real life (and anyone who is a diver will back me up on this) you don't see that sort of wavy distortion underwater. Only in an area where the water density is in flux (very rare, such as near an underwater volcano or where salt water is mixing with fresh). I would request that if someone adds a new ocean version that they include some method to turn off the non-realistic underwater effects.
     
  7. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    This shader just looks fantastic.
     
  8. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    That was my first feeling as well. If you are wearing a mask, there is no wavy distortion. There is some shift between the air and water at the glass, but it's consistent, and could be put in as a lens aberration for a perfect first person mode. Personally I'd avoid it. Without a mask, it's just a form of blurry. Again a simple post effect, if you need it.

    But otherwise, sweet!

    Is any of this available to play with?
     
  9. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    You can download the blender files, it's in the youtube description
     
  10. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    That is an interesting observation. I never thought about that. But now, since you mentioned it, I have to say you're absolutely right.

    On the other hand, you have a lot things in games that are a bit exaggerated for dramatic purposes. But yeah, it would be a good idea to have the possibility to disable such a effect.
     
  11. spraycanmansam

    spraycanmansam

    Joined:
    Nov 22, 2012
    Posts:
    254
    ^^^ This! I find this is one of the most difficult design aspects we're dealing with at the moment. Realism in some cases is just plain boring.. I find that striking a nice balance between realism and 'stylised' (or hollywood :p ) realism works well.

    For example, when developing the water shaders, looking at some real life footage of oceans, etc, some of it just looked boring, flat and dull ..and it can be in reality. Personally, I think you need to find the balance between making it visually stimulating and not over-cooking it.


    I guess you could compare it to TV, if there was no studio lighting or makeup, all our favorite TV shows would look pretty flat and dull, but that would be straight-up recorded realism.




    @VIC20, love the water shader, looks great for mobile!
     
    Last edited: Jun 26, 2013
  12. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is important, yes. Especially with the color loss, then sheer light loss - and the fact that most surfaces in a common diving area are covered with a thin layer of grey silt - underwater scenes ARE very boring. Most photos are taken under strong color compensating lights.

    I think you've done a great job with the underwater look in Stranded Deep. It's got great feeling.

    The the twisty distortion (which I noticed in GuildWars2 last night) is a bit OTT.

    -

    Being this


    vs this


    with something like this:
     
  13. Ben-Massey

    Ben-Massey

    Joined:
    Jun 13, 2011
    Posts:
    581
    It comes down to personal preference... its a bit like motion blur i suppose, some people prefer it whilst others hate it, it can always be a settings option i guess. I personally prefer it, gives it a much more fluidly feel and fakes the scuttle drifty-ness of the player.
     
  14. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    this ocean is really nice: D
    Another ocean HERE

    Do you think we can "merge" the two?
    The waves et foam of the ocean community, and reflection, underwater and caustics of Kostiantyn ocean ?
     
  15. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    Hi Nipoco

    Did Martin get back to you about the possibility to port his water shader to Unity ?

    Would be great to see this for the unity community. this would be awesome :)

    thanks

    Norby



     
  16. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    Hi Norby.

    There are no promises from his side. So I wouldn't hold my breath on this one. But at least he showed some real interest in Unity, after asking him about porting that shader to Unity.
     
  17. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    There is some additional information about underwater looks and surface reflections HERE.

    One of the problems with that solution and to a degree with Kostiantyn's is that they are global solutions. When the camera is under the water, the fog level for the entire scene is changed; or the post effects are changed; or caustics are applied to every surface... whether it's in the water or not.

    Some of the other solutions here, and some require extensive back reading, solve these in a more complex manner.

    As a matter of fact, I believe the current version of the shader knocking around is a "mobile ready" version which drops most of the underwater solutions from earlier iterations.
     
  18. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    Thanks Nipoco

    Norby
     
  19. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    yes good work ;)

    for reflection in the water, it is only possible on flat water and not a non-animated ocean?
     
  20. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    Yes Little Angel !! Good idea !

    A little test
    your code with a few modifications
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5.  
    6.  
    7. public class Underwater : MonoBehaviour {
    8.  
    9.     public float waterLevel;
    10.     public Camera camera;
    11.     public Transform waterPlane;    //  Testing
    12.     public Color underwaterColor;
    13.    
    14.    
    15.     private Texture2D underWaterTexture;
    16.     private bool isUnderwater;
    17.     private Color cameraNormalBackgroundColor;
    18.     private Color fogNormalColor;
    19.  
    20.  
    21.  
    22.     // Use this for initialization
    23.  
    24.     void Awake () {
    25.         // Test ?
    26.         underWaterTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
    27.         Color underwaterTextureColor = underwaterColor;
    28.         underwaterTextureColor.a =.4f;
    29.         underWaterTexture.SetPixel(1, 1, underwaterTextureColor);
    30.         underWaterTexture.Apply();
    31.        
    32.         fogNormalColor = RenderSettings.fogColor;
    33.         cameraNormalBackgroundColor = camera.backgroundColor;
    34.     }
    35.  
    36.  
    37.     void OnGUI(){
    38.         if (isUnderwater)
    39.             GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height), underWaterTexture);
    40.     }
    41.        
    42.     // Update is called once per frame
    43.  
    44.     void Update () {
    45.  
    46.         if ((transform.position.y < waterLevel) != isUnderwater) {
    47.             isUnderwater = transform.position.y < waterLevel;
    48.             if (isUnderwater) SetUnderwater ();
    49.             if (!isUnderwater) SetNormal ();
    50.         }
    51.  
    52.     }
    53.    
    54.  
    55.     void SetNormal () {
    56.  
    57.         RenderSettings.fogColor = fogNormalColor;
    58.         camera.backgroundColor = cameraNormalBackgroundColor;
    59.         RenderSettings.fogDensity = 0.01f;
    60.  
    61.         waterPlane.localScale = new Vector3 (waterPlane.localScale.x, 1.0f, waterPlane.localScale.z);
    62.     }
    63.  
    64.  
    65.  
    66.     void SetUnderwater () {
    67.  
    68.         RenderSettings.fogColor = underwaterColor;
    69.         camera.backgroundColor = underwaterColor;
    70.         RenderSettings.fogDensity = 0.1f;
    71.        
    72.         waterPlane.localScale = new Vector3 (waterPlane.localScale.x, -1.0f, waterPlane.localScale.z);
    73.     }
    74.  
    75. }
    76.  
     
  21. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
    Hi !
    Well, I improved the underwater effect LINK
    I have an idea to change the flare under water to simulate sunlight through the water. What do you think?
    Also, is that it is possible that the reflection is more transparent, to make place for the refraction. Since I activated the skybox reflections the refraction is not visible ...
     
    Last edited: Jul 6, 2013
  22. laurent-clave

    laurent-clave

    Joined:
    Jul 18, 2011
    Posts:
    280
  23. navalaction

    navalaction

    Joined:
    Jun 18, 2013
    Posts:
    12
  24. primus88

    primus88

    Joined:
    May 14, 2013
    Posts:
    611
    Dat water....
     
  25. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    That is a spectacular shot. Looks like you've nailed the sea spray, what about boat wakes, what do yours look like?
     
  26. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    oooh i would love to see a web player just
    to look at the water. very nice

    Norbert
     
  27. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Bumping this since it's awesome shot.
    Is this based from community ocean project or you made your own ocean?
     
  28. dilbertian

    dilbertian

    Joined:
    Aug 13, 2010
    Posts:
    74
    This project looks incredible!

    I just downloaded latest Asset Link and then created a new project and new scene, and then moved all prefabs over to current scene, added a directional light and hit play and the physics/movement seems to be working fine, but the ocean color is all black.

    FYI - I am using Unity 4.1.5f1 standard version.

    *** Edit ***
    I saw your DX11 post - I am using Mac OS X 10.7.5 - so could this be the problem?
     
    Last edited: Jul 22, 2013
  29. jaxy

    jaxy

    Joined:
    Jul 22, 2013
    Posts:
    3
  30. navalaction

    navalaction

    Joined:
    Jun 18, 2013
    Posts:
    12
    We wrote our own ocean. It's DX11 only currently, but for our audience its ok.
     
  31. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,688
    Looks also nice when "moving" (filmed with camera in first part of the movie and and recorded via airplay in 2nd half of the movie).

     
  32. ominousdev

    ominousdev

    Joined:
    Sep 10, 2012
    Posts:
    2
    That is massively impressive.
     
  33. sadicus

    sadicus

    Joined:
    Jan 28, 2012
    Posts:
    272
    There is some epic Ocean water going on.OceanPackageVersionDarkloy.unitypackage
    There was not a scene, how to assemble all the assets?
    when all prefabs are added to the scene, Unity 4.2 Crashes.
     
    Last edited: Aug 6, 2013
  34. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    Could you please share or even sell this solution?
     
  35. VoellGraves

    VoellGraves

    Joined:
    Jul 16, 2013
    Posts:
    6
    Or maybe just give some tips.
     
  36. HeavyMcD

    HeavyMcD

    Joined:
    Nov 4, 2012
    Posts:
    317
    This is stunning! Outstanding job guys...
     
  37. HeavyMcD

    HeavyMcD

    Joined:
    Nov 4, 2012
    Posts:
    317
    Nice demo! Cant wait to see more..
     
  38. Kemp-Sparky

    Kemp-Sparky

    Joined:
    Jul 7, 2013
    Posts:
    72
    Hello, could you include a demo scene with this package? I'm not sure how to set it all up. Thanks!
     
  39. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Same here, I'd really like to see how to setup a scene based on an actual example scene.
     
  40. Lilass

    Lilass

    Joined:
    Oct 10, 2013
    Posts:
    1
    Hi there.
    I'm new to Unity and really impressed about the work done here!
    Thank you for this water.

    So I have a question. Everything work fine here with Unity 4.2 but there is no mesh associated to the 'ocean' prefab. Is there a way to see a plane or something corresponding to ocean in scene view in order to place it correctly and adjust its size correctly ?

    Thank so much.
    Lilass
     
  41. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    Unfortunately, the ocean shader is only visible when the game is running. I usually drop a translucent plane into the scene at sea level, as a reference point when working on my terrain, and then turn it off before playing/building the game. It's a bit of a clunky workaround, but gets the job done. An alternative, if you're using a trigger collider to generate underwater effects, is to use a rendered cube for the collider, and turn rendering off before playing. Hope this helps.
     
  42. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
  43. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Sometime i always curious if somebody is really still working on this.... and somehow i think we need to complete remade this ocean community GO considering the current unity version and technology....
     
  44. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    Yes, I tried this out a while back, and the waves look pretty good. The only problem was that buoyancy was implemented as a shader, making it difficult to adapt to other objects. It could do the job though for some people (plus it's free).

    This project dates back to Unity 2, and hasn't been updated as much as it should to work with Unity 4. Right now, it's more of a headache than it's worth sometimes to get it to even load without errors, let alone play nice with other assets. I keep coming back here looking for new developments, but they seem to have dried up for the time being. Still, there's hope.

    In the mean time, I've turned to an app called Wave Creator http://forum.unity3d.com/threads/201677-Wave-Creator-Real-Waves-in-Unity!. It isn't free, but at 10 bucks, it isn't going to break anyone. It doesn't currently provide its own surface shader, but does give you a pretty nice wave displacement simulation. It also has a simple buoyancy script, and an underwater effect, both calculated from the changing surface height. The cool thing is, you can dress it up in any kind of water shader you like, to get lots of different looks. [//End Blatant Plug]

    I'm still looking for a really definitive solution that:
    a) looks good from both above AND below,
    b) includes physics/shaders for buoyancy, splashes, boat wakes, and shoreline foam,
    c) drops into a scene without a lot of fuss or conflicts,
    d) won't break the memory/processor/resources budget, and
    e) won't break the bank.

    Here's hoping the community ocean project rises from the ashes to become all this, or at least inspires some savvy developer to do something better.
     
  45. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  46. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Hi there,
    I'm looking back into the project and I'll set up a public git for the last version I've got. I have a question though, anyone knows an easy way to create shore lines for this? I've got it working nicely but the shores are horrible, maybe we can do the trick by using transparency in the material but still... not very nice.
    I'm talking about the mobile optimized version.
     
  47. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
  48. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    The original full version of the ocean shader has shoreline effects, but they're pretty weak and unconvincing. Looking at some of the other water products on the market, Water+ has pretty decent foam, but it depends on them baking a foam area around the terrain in the scene, and this wouldn't work well with an animated displaced water surface. There's a free standalone shoreline foam script available as well, but it suffers from the same limitations. Plus, you've got to export out your terrain, and create the shoreline zones in a 3D modelling app. Unity Pro's Water4 has pretty good shoreline foam, and doesn't need to be baked. I wonder how they do it? It probably depends on some Pro only features though. There are a few other water packages that try to tackle this on the fly, with mixed results. I'm still looking for this feature as well.
     
  49. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    If you want to create shore lines effect from the shader, the easiest way to doing that is using depthbias or depth difference, it's the same way how ProWater4 shore lines works.
     
  50. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    This could be the way to go, but not being an accomplished shader programmer, this isn't enough information for me to actually produce a working shoreline foam effect. For any of you who are, how about taking this concept and running with it? If it's that easy, why aren't there dozens of shaders, scripts, and plug-ins that do this on the asset store already? The sad fact is that there aren't that many solutions available for those of us that can't create our own effect from scratch. Most of them don't work that well, are too expensive, or have some other fatal flaw. I've played around with this stuff long enough to realize it's not really my area of expertise, which is why I look to developers, and community projects like this one, to save my sorry backside. I really hope someone who knows this stuff will take the bait, and show the rest of us how it's done.
     
    Last edited: Oct 24, 2013