Search Unity

The Community Ocean Shader (Open Source) Unity 5

Discussion in 'Shaders' started by laurent-clave, Nov 30, 2015.

  1. ZeroGround

    ZeroGround

    Joined:
    Dec 21, 2016
    Posts:
    2
    Thank you very much, after a little knowledge refreshment in shader programming i was able to get exactly what i needed :)
     
    elias_t likes this.
  2. Elmah

    Elmah

    Joined:
    Apr 15, 2017
    Posts:
    1
    Is there a way to make ocean render at multiple positions (in multiplayer for example) ?
     
  3. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi.

    Each player should run its own simulation, and sync the time var that controls it.

    There is a major rewrite going on right now - which is 8 months late now - that will get rid of the tile system and will use a projected grid. That should make things easier for multiplayer.
     
    paulbuck86 and hopeful like this.
  4. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    I got an email notification from the user @JamesArndt about the foam covering the ocean.

    You should replace in the shader the shore line code with this one on unity 5.6 or newer:


    Code (CSharp):
    1.                 //SHORELINES
    2.                 #ifdef SHORE_ON
    3.                     float zdepth = LinearEyeDepth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.ref)).r);
    4.                     float intensityFactor = 1 - saturate((zdepth - i.ref.w) / _ShoreDistance);
    5.                     half3 foamGradient = _ShoreStrength - tex2D(_FoamGradient, float2(intensityFactor - i.bumpTexCoord.w, 0) + tangentNormal.xy);
    6.                     foam += foamGradient * intensityFactor * _foam;
    7.                 #endif
     
    JamesArndt and st-VALVe like this.
  5. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    106
    I'm trying to use this primarily for the underwater environment. When I use the demo scenes or add an Ocean object to my own scene, there is no underwater. Instead once I go below the water surface it is just the regular environment. I apologize if I am using the wrong terms here as I am pretty new to Unity. Is there something I need to do to enable underwater use?
     
  6. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi.

    Sorry, the lib does not support underwater effects yet.
     
    JamesArndt likes this.
  7. swredcam

    swredcam

    Joined:
    Apr 16, 2017
    Posts:
    106
    Ah so the references to "underwater" in this thread must refer to the rendering of objects that are underwater, as seen from above the water level?

    Thank you
     
  8. MikeBike

    MikeBike

    Joined:
    Apr 29, 2017
    Posts:
    28
    Hi
    looks great. How to add this ocean material/effects to a skinned mesh renderer?
    Thanks
     
  9. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi.

    Just use a material that is stored in Assets\Ocean\Resources\oceanMaterials.
     
  10. MikeBike

    MikeBike

    Joined:
    Apr 29, 2017
    Posts:
    28
    Thanks yes I've found that. But I want the ocean moves/waves also on my mesh. Could I access that with c#?
    I've attached the ocean script to my mesh but it crashes.
     
  11. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    It is not that easy to this.

    You should study the code and remove the parts that apply the ocean transformations to static meshes.
    Then get heights from the simulation data and apply them to your mesh.
     
  12. MikeBike

    MikeBike

    Joined:
    Apr 29, 2017
    Posts:
    28
    I can use that for a little commercial game? Way cool, thanks for your work.
    ok for a start I attach that but update doesn't get called?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class rot : MonoBehaviour {
    6.  
    7.   public float speed = 10.0f;
    8.   SkinnedMeshRenderer thisSkinnedMeshRenderer;
    9.  
    10.   void Start () {
    11.     thisSkinnedMeshRenderer = this.gameObject.GetComponent<SkinnedMeshRenderer>();
    12.   }
    13.   void Update () {
    14.   //thisSkinnedMeshRenderer.transform.Rotate(Vector3.up * Time.deltaTime * speed);
    15.   thisSkinnedMeshRenderer.transform.Rotate(Vector3.up, 90.0f);
    16.   Debug.Log("Hello", gameObject);
    17.   print("Text I want to write to Unity console");
    18.   }
    19. }
    later I could simply inherit from your ocean like:
    public class rot : Ocean {
    ? New to C# with only a little c++
    Thanks and regards
     
  13. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi.

    Yes of course you can use it. No strings attached.

    You have to completely skip the parts that have to do with the creation and update of the mesh tiles.

    Then you should use the getHeight (batched) functions to apply the vertex transformations to your mesh.

    It can be a little bit tricky, but I don't have the time to make an example now.
     
  14. MikeBike

    MikeBike

    Joined:
    Apr 29, 2017
    Posts:
    28
    Great. Should be fun to wrap my head around c#. :)
     
  15. appl044

    appl044

    Joined:
    May 13, 2014
    Posts:
    8
    I have tried this and it gives errors. It would be great if this product worked for 5.6 and newer.
     
  16. appl044

    appl044

    Joined:
    May 13, 2014
    Posts:
    8
    I tried this also and I am also seeing errors. And once I resolve them, no shore foam. Is there some way to work around this, by maybe disabling shadows?
     
  17. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi. What kind of errors?

    Because I have it working here for Unity 5.6.
     
  18. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,172
    @elias_t I was wondering where you might have posted documentation for what each part of the interface does? Right now some of the settings are opaque or vague on how they affect the ocean.
     
  19. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi. Sorry, there is no extra documentation right now. I hoped that the "?" buttons next to most fields in the inspector would be helpful enough.
     
  20. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,172
    @elias_t Do you know if it is possible to do something like this with your plugin?


    We were able to place the plane from your plugin on top of a cube, but we can't get the cube to clip itself to the animating waves on the sides.

    Would it be possible to extend the Ocean script to create meshes on the side that line up with heightmap meshes of the Ocean plane? SideMeshOcean.png
     
    Last edited: May 16, 2017
  21. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Well it could be possible if you create limited tiles and extrude there edges downward...
     
  22. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,172
    Do you know in what part of the Ocean.cs would be the best place to do that? I'd like to attempt the extruduing with a one tile Ocean as a test.
     
  23. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Find the function 'updateTiles' to see how the tiles are update in the non-NATIVE code section.
     
  24. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi all.


    Since I am struggling between small and larger contracts and my personal project that would use an improved version of the ocean lib never fired up I am thinking of splitting the project in 2 versions.

    1. The same free version as it is now that will get most of the improvements.

    2. A commercial version at a symbolic price of $10 - $20, that will include more effects, more attention and support.

    That way I can get some motivation that I lost between my contracts.

    What do you think?
     
    iddqd, IronDuke and red2blue like this.
  25. IronDuke

    IronDuke

    Joined:
    May 13, 2014
    Posts:
    132
    Long as there's a free version for peasants such as myself, I'm happy.:cool:

    A paid version is great too, since it means moar green paper for you, which means moar happy for you, which means a decreased likelihood that you'll abandon the project.:D

    --IronDuke
     
    elias_t likes this.
  26. The_Uber_Rasta

    The_Uber_Rasta

    Joined:
    Feb 25, 2014
    Posts:
    8
    Hi sorry to ask but would it be possible to make semi still murky or black water that works for lakes or pools similar to how suimono does it? I'm a poor South African developer $65 is asking a lot for water, this open source solution really looks amazing heck I'd say it looks better than a bunch of paid assets, I would definitely consider paying $10-20 for this asset if I could get it to look ok for a lake.
     
  27. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi. Look at this post on how to do this: https://forum.unity3d.com/threads/t...pen-source-unity-5.370818/page-2#post-2442038

    But I wouldn't run the ocean simulation just for lakes or pools. Just use the shader on a plane.
     
    The_Uber_Rasta and hopeful like this.
  28. Acme3dProd

    Acme3dProd

    Joined:
    Mar 13, 2016
    Posts:
    5
    I would like to thank you very much for this asset. It is amazing! It made my work with a game trailer really easy!
    Here is the trailer:
     
  29. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Very good looking! Nice work!
     
  30. br90218

    br90218

    Joined:
    May 25, 2016
    Posts:
    4
    Hi!
    So I think somewhere around page 2 there's a friend who was also working on a flight sim and had similar questions?
    This is where I am so far:
    upload_2017-5-23_22-43-43.png

    I know that there's a LOD system going on in there, but the transitions are just.... unsatisfactory.
    Is there any way I can make an infinite ocean that looks uniform? (One material, no LODs)

    Thanks!
     
  31. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi. I am working right now to replace the tile system with a projected grid. Should be up soon.
     
  32. st-VALVe

    st-VALVe

    Joined:
    Jan 8, 2014
    Posts:
    11
    How could I like this post twice?)
     
    The_Uber_Rasta and IronDuke like this.
  33. IronDuke

    IronDuke

    Joined:
    May 13, 2014
    Posts:
    132
    By having me do it for you.:cool:

    --IronDuke
     
    br90218 and st-VALVe like this.
  34. nazaroaversano

    nazaroaversano

    Joined:
    Mar 25, 2017
    Posts:
    2
    Hello,
    I have a question for you.... I need to create a realistic sailing for a very big ship and foam is not enaught ( i think need bow wave and stern wave and/or same foam all around the border of the ship) ... is possible to improve the interaction between the ship and the ocean?
     
    VictoryWorks likes this.
  35. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    205
    As far as I've understood shadows aren't working currently? @elias_t how's it going with that update on the shadows?

    By the way thanks for all the work you've put into this, the shader looks great as it is already.
     
    JamesArndt and The_Uber_Rasta like this.
  36. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi all.

    I am sorry for yet another delay. I do my best to get the next one ready, but still, other job obligations keep me distracted.
     
    eXonius and st-VALVe like this.
  37. smonz3

    smonz3

    Joined:
    Jan 9, 2017
    Posts:
    18
    really looking forward to the next version :) I changed the shader code for 5.6 but still can't seem to get shore line foam working correctly it always covers the whole ocean.. would be great to have a 5.6 release :)
     
  38. PapaCUh

    PapaCUh

    Joined:
    Jun 17, 2017
    Posts:
    6
    elias_t, 2 things:

    1- Thank you for all your work! Cheers!

    2- I'm using Unity 5.6.1f1 and all boats seems to be unmasked for the ocean. The "Masked/Mask" shader is set to the boat/ship and AlphaTest+71 RenderQueue 2521 but the ocean water enters the boat. How to prevent it?
    BoatMask.jpg BoatMask.jpg
     
  39. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    4,875
    I believe Unity made substantial changes to render texture in 5.6.1. Perhaps that's the source of the problem.
     
    PapaCUh likes this.
  40. PapaCUh

    PapaCUh

    Joined:
    Jun 17, 2017
    Posts:
    6
    I found something annoing:

    weird tiles.png

    This white blocky area keep following the boat and blinking around it. I turned off the boat trails and sea foam but nothing solved it.

    PC specs:
    Windows 8
    Intel i5 3210m 8gb RAM
    Intel HD 4000 graphics card

    On a Intel i5 4690 8gb RAM and a ATI Radeon R7 370 (Windown 7) it doesn't happen.
     
    JamesArndt likes this.
  41. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,598
    didn't know this thread was here. Found it on CETO's thread... Thanks Hopeful.
     
    docsavage and hopeful like this.
  42. ahardy

    ahardy

    Joined:
    Feb 11, 2015
    Posts:
    10
    Hi,
    For this problem, I use a shader mask that hides the sea inside the hull of the vessel. Most of the time, a simple cube is enough, but you can have a more precise geometry if you want better results.

    Here is the code of the mask I use :
    Shader "Custom/WaterMask" {

    SubShader {
    // Render the mask after regular geometry, but before masked geometry and
    // transparent things.

    Tags {"Queue" = "Geometry+10" }

    // Don't draw in the RGBA channels; just the depth buffer

    ColorMask 0
    ZWrite On

    // Do nothing specific in the pass:

    Pass {}
    }
     
    JamesArndt and PapaCUh like this.
  43. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    436
    This ocean project is amazing. I would gladly support with 20$ I'm very confused about all the oceans and water solutions. I'm looking for some sort of water surface that I can apply to any 3d shape in a situation where the player would sometimes be underwater and sometimes above water. Ideally the solution would have buoyancy and waves that interact with objects above it. Is any of that possible with the community ocean technology?
     
  44. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    53
    The shaders worked great in Unity 5.5, but since upgrading to 5.6.0p4, the reflections are doubled and the specular and skybox-reflection is completely crazy. Any ideas what is wrong or how to mend it? Github project hasn't been updated for 5 months.
     
    JamesArndt likes this.
  45. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi all.

    The project is not dead.

    I am aware of all the issues and 2 versions of the project will eventually come out. One commercial and one free.

    But I have to decide at some point to dedicate myself for a period full time on this.

    As for Unity5.6 I have the same github project running ok on a test scene. I would advice some users to clean the shader cache and reimport the ocean stuff.

    Untitled.jpg
     
    JamesArndt and st-VALVe like this.
  46. Nyuchen

    Nyuchen

    Joined:
    Sep 9, 2015
    Posts:
    16
    found this project today and love the progress from your first post about this to now.
    your work is amazing and you totaly deserve it to have a commercial version. :)

    what do you think will be the difference in the projects?
     
  47. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi.

    The commercial version should have some more advanced stuff.
     
  48. LeGiangAnh

    LeGiangAnh

    Joined:
    Nov 10, 2013
    Posts:
    113
    Hi @elias_t It is possible to simulate a fake water only (without physics waves) using this plugin?
    I need to have a water for my mobile game. So I need it max optimized.
     
  49. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,167
    Hi.

    Yes you could by using just the shader and the reflection c# code. But it could take some digging to do so.
     
  50. PapaCUh

    PapaCUh

    Joined:
    Jun 17, 2017
    Posts:
    6
    Hi @elias_t ! The problem I posted about the white square surrounding and blinking the boat happened in a clean project and the build was made using Unity 5.6.1.f1