Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

The Community Ocean Shader (Open Source) Unity 5

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

  1. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
    I tried replacing the shoreline code with this code in 11 different places in the shaders and it did not fix the foam covering the ocean.My unity is 5.63p4.
     
  2. elias_t

    elias_t

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

    Please try this (and reimport the shaders):

    Code (CSharp):
    1.                 //SHORELINES
    2.                 #ifdef SHORE_ON
    3.                 //UNITY5.5
    4.                 #if defined(UNITY_REVERSED_Z)
    5.                     float zdepth = 1.0f - LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.ref)).r);
    6.                 #else
    7.                     float zdepth = LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.ref)).r);
    8.                 #endif
    9.                 float intensityFactor = 1- saturate((zdepth- i.ref.z) / _ShoreDistance);
    10.                 half3 foamGradient = _ShoreStrength - tex2D(_FoamGradient, float2(intensityFactor - i.bumpTexCoord.w, 0) + tangentNormal.xy);
    11.                 foam += foamGradient * intensityFactor * _foam;
    12.                 #endif
     
  3. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26

    Thank you for such a quick reply unfortunately this didnt work either. If turn off foam lod0 it disappears. Shader L1, L3, L5 and L7 have this error.

    Code (CSharp):
    1. undeclared identifier '_FoamGradient'
    2. Compiling Vertex program with SHORE_ON FOGON DCON
    3. Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP
    I would like to fix the foam as the shoreline doesn't look very good without foam.
     
    Last edited: Oct 27, 2017
  4. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    It seems that something is messed up with the shaders.

    I get the system working fine on unity 5.2.4, 5.6.4, 2017.1.1

    Try to redownload and retest.
     
  5. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
    Edit : Ok i've worked out basically the 2 mobile presets work and everything else doesn't .

    I am going to install 5.6.4 as thats the only other version that will work with Sinespace at the moment .If that doesnt work I will give up.
     
    Last edited: Oct 27, 2017
  6. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
    Ok I fresh installed 5.6.4 and the ocean is still completely covered in foam so I am really not sure how you have the version on github running in 5.6.4 if it wont run on a fresh install?.
     
  7. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Ok. Wait.

    I will send you a package.
     
  8. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
  9. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    I downloaded the project on github and it was ok.

    But when I exported a new package and created a new project I saw the full foam issue. I am looking into it now.

    It seems, because the githup repo has the compiled shaders of previous versions of unity, that it renders correct.
     
  10. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Please try this. It should work now.

    Code (CSharp):
    1.                 //SHORELINES
    2.                 #ifdef SHORE_ON
    3.                 //UNITY5.5
    4.                 #if !defined(UNITY_REVERSED_Z)
    5.                     float zdepth = 1.0f - LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.ref)).r);
    6.                 #else
    7.                     float zdepth = LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.ref)).r);
    8.                 #endif
    9.                    
    10.                     float intensityFactor = 1 - saturate((zdepth - i.ref.w) / _ShoreDistance);
    11.                     half3 foamGradient = _ShoreStrength - tex2D(_FoamGradient, float2(intensityFactor - i.bumpTexCoord.w, 0) + tangentNormal.xy);
    12.                     foam += foamGradient * intensityFactor * _foam;
    13.                 #endif
     
  11. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
    Yes when I opened the project it gave me a warning about it being compiled on another version and said it would fix it or I could close it .I did not get an option that allowed me to run it as it was.I Hope you work it out I will keep checking this thread in the hope you do and Thanks for all your help.

    Edit: Ok I will give that a try thanks.
     
  12. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    There is not harm in upgrading it. It is in unity 5.2.4 version.
     
  13. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
    Ok when I add that code too the Ocean,shader in 7 places and L1, L3,L5 and L7 I get shaders errors on L1,L3,L5 and L7.
    this same error on all

    Code (CSharp):
    1. undeclared identifier '_FoamGradient'
    2. Compiling Vertex program with SHORE_ON FOGON DCON
    3. Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP
     
  14. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Hi these are lower quality shaders. The have not foam gradient.

    For them you should use:

    Code (CSharp):
    1.                     //SHORELINES
    2.                     #ifdef SHORE_ON
    3.                     //UNITY5.5
    4.                     #if !defined(UNITY_REVERSED_Z)
    5.                         float zdepth = 1.0f - LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.ref)).r);
    6.                     #else
    7.                         float zdepth = LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.ref)).r);
    8.                     #endif
    9.                     float intensityFactor = 1 - saturate((zdepth - i.ref.w) / _ShoreDistance);
    10.                     foam += _ShoreStrength * intensityFactor * _foam  ;
    11.                     #endif
     
  15. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
    Ok I am not getting compile errors now but still have foam covering ocean. So what you are saying is I should only add the other code to the ocean shader?. If so that's what I have now done and it still has the bug.


    Edit: Ok Thanks elias let me know when its updated
     
    Last edited: Oct 27, 2017
  16. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Wait I am updating now the repo.
     
  17. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    ok.

    Wrong update. A second will follow.
     
    Last edited: Oct 27, 2017
  18. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
    Ok Tried the new repo and have exactly the same bug?.
     
  19. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    I updated the repo again. Please redownload.(the one that has the change "Shore Foam Fix final")

    It seems that Unity played me with the z-buffer between versions.

    To verify I downloaded the repo and imported to a new project.
     
  20. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
    Ok ill download again .I have worked out something don't know if will help. 3 of the demos I cannot turn shore foam on without the bug but the Ocean_with_ships_mobile demo I can and it works correctly ?.
     
  21. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
    Downloaded again and it still doesn't work .I tried the prefab and all the demos only that one demo works .

    What is different about the demo "Ocean_with_ships_mobile" ?. That is allowing it to work.
     
    Last edited: Oct 27, 2017
  22. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    I have imported the new repo in new projects on unity 5.6 and 2017.1 and it works.

    I also opened it on macos and was ok again.

    i don't know more on what is happening to you.

    Try this as an experiment. Open the Ocean shader and make a small change (write a comment) and save it.
    It will force the shader to recompile.
     
  23. Xulain-SineSpace

    Xulain-SineSpace

    Joined:
    Oct 14, 2017
    Posts:
    26
    I have solved it for some reason in my player settings dx11 was below dx9 .I dragged dx11 above dx9 and now it works.I am really sorry if I have wasted your time and thanks for all your help.
     
  24. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Don't worry this issue was an ongoing adventure for the past months because of unity changes on the z-buffer.

    Good to know you solved it although it should work with dx9 also.
     
  25. sfasan666

    sfasan666

    Joined:
    Oct 30, 2017
    Posts:
    1
    Hi

    Just a quick question, is there a plan to make the shader 2-sided so that that ocean surface can be seen from below?
     
  26. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Well yes.

    But the project is on hold now until I make the split to the free and the commercial version.

    Which might not last long since I plan to use the lib in a game of mine.
     
  27. Sr-Liermann

    Sr-Liermann

    Joined:
    Jan 7, 2015
    Posts:
    68
    Hello! I try to switch the boat for an Warship, but I would a help to decress bouncy factor, I had try to decress some values on this script, but no have a sucess.
     
  28. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Hi. If you could send me in a private message your ship I could try to set it up for you.
     
  29. vectorCharlie_f

    vectorCharlie_f

    Joined:
    Sep 12, 2017
    Posts:
    10
    Hi @elias_t
    I have noticed that switching the global fog on and off doesn't work with a scene that contains the Ocean. Is there something in the Ocean script that locks the fog setting? Thanks!
     
  30. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Hi. This should actually work. On which Unity version did you observed this?
     
  31. vectorCharlie_f

    vectorCharlie_f

    Joined:
    Sep 12, 2017
    Posts:
    10
    @elias_t This is with Unity 2017.1.1p2

    Also... I just wanted to check to see if you had looked into being able to take the randomness out of the simulation. (ie. identical every time it plays back)

    Thanks!
     
  32. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Ok. I will check with 2017.1.

    yes I was able to identify the issue. I have to compile in the next days all the plugins. i will post here the update.
     
  33. vectorCharlie_f

    vectorCharlie_f

    Joined:
    Sep 12, 2017
    Posts:
    10
    Awesome! Thank you :)
     
  34. gsimons

    gsimons

    Joined:
    Oct 3, 2017
    Posts:
    5
    Hey there,

    I would love to show off this great ocean in multiple camera views at the same time, but unfortunately this causeses flickering in two of the 3 views. Any idea on how to fix this? Thanks again!
     
    Last edited: Nov 13, 2017
  35. TeslaCuil

    TeslaCuil

    Joined:
    Apr 1, 2017
    Posts:
    2
    Has anyone experienced an issue where some objects are reflected and some are not?

    Example:


    There are 3 specific prefabs that are being reflected regardless of if they are obscured or not, while everything else (the buildings and the )

    EDIT: I realized that it has something to do with objects that are being dynamically occluded. If I turn off dynamic occlusion for the buildings, they will be reflected, but it has a huge hit on framerate. It is still odd though, because the dock there is reflected regardless of whether it is set to dynamically occlude.
     
  36. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    update 15/12/2017

    • Added the ability to load and use a fixed Gaussian table, so that the simulation can be predictable. -- To be able to use this set the flag in the inspector to use a fixed table. Then save your preset in Play mode. -- Afterwards use the presetLoader function to load your preset after the Initialize() function of the simulation.

    • Separated the loadPreset function to its own class.

    • Fixed the issues of the inspector not saving changes !
    https://github.com/eliasts/Ocean_Community_Next_Gen
     
    arnoob and hopeful like this.
  37. odival

    odival

    Joined:
    Jun 11, 2014
    Posts:
    57
    Hi Elias, I have some questions:
    - does the fixed gaussian table improves fps or - apart from being fixed - there's no difference compared to the random table?
    - is it possible to switch presets on runtime?
     
  38. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Hi the fixed table was a request from some users who wanted to have a predictable behavior of the simulation. Along with the time variable it is useful for multiplayer.

    It does not affect performance.

    Yes it is possible to switch at runtime as long as the grid resolution is the same on the current and the preset to load.
     
    odival likes this.
  39. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,913
    2017.2.0p4 The Inspector UI for the Ocean script appears completely blank. The console keeps spamming this error message now. Any ideas?



    When I commented out this line (Line 183) "currentPreset = EditorGUILayout.Popup(currentPreset, presets);" The UI sort've appears without a background (looks really funky). However when I hit the Play button the scene errors out and pauses play.
     
    Last edited: Dec 18, 2017
  40. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Hi. I just installed Unity2017.2p4 and all was working fine.

    Have you updated all the files from github?

    (And I want to make a statement here: Unity has lost the ball with the updates. Breaking changes everywhere. They truly made Hell the life of Asset publishers.)
     
    hopeful, odival and JamesArndt like this.
  41. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,913
    Yeah this is the latest from Github. I am manually placing the folders into an existing project, but it's also doing it on a clean empty project. Not sure how to fix but it's clear they have something to do with the UI Inspector and maybe presets. This is what I am seeing.

     
  42. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    . Then I suspect that it is the hardcoded string of the presets in the editor script. Change this to fit your folder structure.

    I think I must change this to find the presets folder automatically.
     
    JamesArndt likes this.
  43. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    update 19/10/2017

    • The Presets path is now found automatically.
    [Edit: reuploaded to fix also the BuoyancyInspector.cs script.]

    https://github.com/eliasts/Ocean_Community_Next_Gen


    If you don't want to download the github project again replace the hardcoded presetPath = HardocodedPath in OceanGeneratorInspector.cs and BuoyancyInspector.cs

    with this:

    Code (CSharp):
    1.         var script = MonoScript.FromScriptableObject( this );
    2.         presetPath = Path.GetDirectoryName( AssetDatabase.GetAssetPath( script ))+"/_OceanPresets";
     
    Last edited: Dec 19, 2017
    JamesArndt and Lars-Steenhoff like this.
  44. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,913
    That was the fix. The other fix was me just to put the folders in the same locations at they would come in at default. I have this habit of tidying things up into minimal amount of folders and in this instance it caused the scripts not to be able to locate that folder. Your fix did the trick!
     
    elias_t likes this.
  45. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    Yes i have that habit too.

    The lib is still far from what I wanted it to be. The biggest motive to improve it now is that I will be using it in my own game.
     
    one_one, hopeful and JamesArndt like this.
  46. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,913
    Well you are doing an outstanding job providing updates and bug fixes to the project.
     
    Peter77 and hopeful like this.
  47. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    Amazing job.
    Thank you for all what you do guys.
     
  48. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,913
    Has anyone commented yet on how to potentially make "wakes" that come off the bow of a moving ship? Not like the foam, but actually displaced ripples in the water?
     
  49. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,366
    To do that, you would have to run an extra simulation layer of the bow wakes and apply it to the affected tiles.
     
    JamesArndt likes this.
  50. JamesArndt

    JamesArndt

    Unity Technologies

    Joined:
    Dec 1, 2009
    Posts:
    2,913
    I was looking at Suimono and it appeared the "ripples" weren't displacement at all, they looked like decals with normals or something. I think I could add that to this system, but would need to figure out how to get the decals to "stick" to the tile with maybe a small offset. Also a quick question...I am implementing bow spray and I was wondering if the ocean scripts are reading the ships height off the ocean surface...the height from anywhere really on the ship, preferably from the deck or middle.
     
    Last edited: Dec 24, 2017