Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

The Community Ocean Shader (Open Source) Unity 5

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

  1. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204
    Right now you cannot go further then the 15 tiles per dimension.

    The y=30 is not used anywhere, you can ignore it.

    The 512x512 is the size of a tile. The smaller you have it the better the resolution of the mesh will be resulting more realistic waves.

    You can change the surrounding disc if you want to give the infinite ocean impression.
     
  2. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,237
    Yea i noticed tried increasing it to 2048 but then had to increase to 128x which hit performance. Noticed another issue was wondering why this occurs. Basically camera at 1k view is fine but increase it and it gets this spotlight kind of effect as can be seen in the image.This becomes noticible from around a 2k viewrange and gets worse the further the camera can render distanceview.png
     
  3. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204
    This has to do with fog support or fog distance cancellation on the main and the lod shaders.
    Either enable fog and/or fog distance cancellation on all lods or not.
     
  4. sniperisa

    sniperisa

    Joined:
    Sep 20, 2015
    Posts:
    14
    When you use less than 15 tiles and a smalller tile size, the ocean gets really small, i think.
    I use the highest possible values and can still see that it ends in the distance.
    So i have a really big blue painted plane just below the ocean that functions as the horizon.

    The resolution is really not great then. I had the idea of creating a bow wave at the ships position by simply raising the water a the ships location. I dropped the idea because of 2 problems:
    1. The resolution with 512x512 is so bad that the ships position jumps around and is the size of 1/3 of the ship.
    2. It seams the water mesh height is resetted each frame, so I only created a water mountain that loosly moves with the ship (My Idea was that the wave is highest at the ships position and lowers it self every frame as the ship moves to create the effect).
     
  5. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204
    Make sure you have the fixed disc enabled and set at 'large' (you can find what large means in the code and change this to your needs.)

    Also disable shader lods to get the same shading on the lod tiles.

    The disc works best if fog is enabled. Otherwise it will not get the same color as the tiles. In that case use a fog color to enable a blending between the disc and the tiles.
     
  6. sniperisa

    sniperisa

    Joined:
    Sep 20, 2015
    Posts:
    14
    Or i just lower the max-possible camera angle :)
     
  7. sniperisa

    sniperisa

    Joined:
    Sep 20, 2015
    Posts:
    14
    I don't want to use fog. Maybe in a map where I want the player to have limited viewing distance but not everywhere.

    I even played with the idea of simulating the curviture of the earth by lowering the Y-value of ships that are far away of the player :)
    But i dropped the idea because the ships would have to be more than 11 km apart to get that effect, when I remember it correct.
    That distances would slow the pace of the game too much.
     
  8. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,237
    Dude get with the times the earth is clearly flat you have been lied to!
     
  9. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,237
    Well i decided to try the ocean in a scene other than the preset ones and it does this.The disc centres round the target but the important bit goes off on its own. I tried to create my own ocean prefeb but it just keeps crashing the editor no clue why. My process to create new prefab.
    1 Create empty
    2 tag it Ocean
    3 add ocean script (leave as is)
    4 run..crash
    5 add discs to mpty
    6 run..crash
    7 create prefab drag prefab of one of the scenes onto it. run works but only like in the picture
    Why does my attempt to create the ocean crash the editor its identical from what i can tell to the package prefab?
    oceantrouble.png
     
  10. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204
    Hi. Unfortunately I have not created a package to import to other projects yet. I will create one today and post it here.
     
    Last edited: Jan 12, 2017
  11. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,237
    Oh thx man. Still confused why creating my own prefab crashes unity what magic did you use ?
     
  12. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204
    Here it is: https://dl.dropboxusercontent.com/u/13373268/ocean.unitypackage

    1. Import this in your project.
    2. Drag the ocean prefab into your scene.
    3. Make sure you assign a directional light as the sun in the ocean inspector.
    4. [optional] assign a target (boat/ship) to follow.

    If you move the 'Ocean' folder inside another folder make sure you change this line:

    Code (CSharp):
    1. presetPath = Application.dataPath+"/Ocean/Editor/_OceanPresets";
    in the OceanGeneratorInspector.cs file at line 98, to follow your path.

    Very important:

    If you want the lib to run faster and to make use of the native libs use the following preprocessor directives: NATIVE, SIMD, THREADS
     
    Last edited: Jan 12, 2017
  13. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    176
    I'm having a problem with the buoyancy script.
    I created a rectangular solid as a test boat "hull" and tried to mimic the settings from the fishing boat.
    However, the "hull" sits quite low in the water.
    I tried changing the rigidbody mass, the buoyancy script "buoyancy" factor and Y offset.
    I tried expanding the size of the box collider and moving it lower.
    All to no effect.

    What are the factors that determine how high an object "floats" in the "ocean"?
    FYI: My ocean transform sits at 0,0,0.

    Thanks.
    -- Paul
     
  14. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,237
    What i do is just parent my boat to the scene boat then turn the rendereres off for the scene boat. just resize the scene boat to match your hull. if you don't come right worth a try
     
  15. elias_t

    elias_t

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

    Yes the buoyancy script is far from perfect, but it is quite easy to modify it.

    For now:

    1. Have your pivot point of the mesh at the center of the hull.
    2. Make an empty object and make your mesh a child to it.
    3. attach to the empty object the box collider and the buoyancy script.
    4. Try to have the pivot points of the hull and the collider to be at the same position.
    5. Play with the offsets of the box collider.

    Untitled.jpg
     
  16. Usko

    Usko

    Joined:
    Jul 5, 2014
    Posts:
    1
    Hi guys, you did very good job, i like it a lot.
    I`m having a problem using FPS player in the scene on the boat. The player jumps quickly on the boat and creates vibrations on the camera.
    The player has rigidbody and the boat also (i`m using default FPS player from unity).
     
  17. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    176
    I still can't seem to get a "boat" to float properly; it always sits too low in the water.
    I downloaded a free 3D model and tried using that and still the same problem.
    I don't know if the issue is the models I'm using, something I'm setting incorrectly, or what.
    If anyone is willing to take some time to look at the boat and see if they can figure out my failing, I would appreciate it.

    Thanks.
    -- Paul

    To that end, I've attached a package with the boat I'm using.
    Use the prefab called, "vagabond_prefab".
    The only thing it need is to have a buoyancy script and a boat controller script attached.
    I included screen shots of the settings for the scripts below.

    upload_2017-1-12_21-35-38.png
    upload_2017-1-12_21-35-59.png
     

    Attached Files:

  18. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204
    Hi. The vibrations possibly come from your physics settings.
    If you attach a camera on the boat you will see that the vibrations do not come from the buoyancy.
     
  19. elias_t

    elias_t

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

    I have created a project package with the boat set up as needed.
    The secret for smaller boats is to reduce the tile size and to make a larger box collider for the buoyancy script.




    Untitled.png

    I have added also a boat controller with some variables that you might want to change.

    The lib right now works better with bigger ships but I will change this in the future.

    Also make sure to add these preprocessor directives in your player build settings to take full advantage of the libs speed:

    Untitled2.png



    Here is the package (Open the scene 'Ocean_with_ships_HQ' ) : https://dl.dropboxusercontent.com/u/13373268/vagabond.unitypackage
     
    hopeful likes this.
  20. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    176
    Elias, Thank you SO much for getting that sorted. I would still be floundering (literally and figuratively) around without your help.

    Couple of questions:
    1) If I scaled the model up WITHIN Unity, would that make any difference, or should the model stay scaled at 1,1,1?
    2) If I scaled the model up in Blender to be about the size of the fishing boat then it should work with mainly the same settings as the fishing boat, correct?

    Thanks.
    This is truly awesome!
    -- Paul
     
  21. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204
    Better keep the scales as 1 unit = 1 meter.
    The fault is mine, because in the beginning I used a scaled up boat, so my demo scenes adapted to it.
     
  22. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,237
    Elias still going to work on allowing for extra tiles above the 15?
     
  23. elias_t

    elias_t

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

    Yes. I am going to change also the lod system, so this will affect tile count.
    I will put back in the radial grid and later the screen space grid.

    I have gathered over the past year also some good improvements some users made.
     
    VKirillov likes this.
  24. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,237
    Oh sweet i will keep an eye two as oeften as can can spare them on this post
     
  25. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    294
    I have a little question here. Is there any way to make water deferred? Our team needs it for SSR, It's not like this water is using grab passes to render reflections and refractions. So, how can we make it compatible with deferred rendering path, if there is a way to do it?
     
  26. elias_t

    elias_t

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

    It works with deferred.Just make sure that textures that are associated with the ocean materials have 'bypass sRGB supersampling' checked on.

    Untitled.png
     
  27. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    294
    Well, shoot, there's no such thing. I do remember it being present in the previous versions of Unity under the Advanced tab. But that tab is totally absent now.

    EDIT: Never mind. It disables by unchecking sRGB. But still after disabling it water still renders in forward renderer according to the frame debugger.
     

    Attached Files:

    Last edited: Jan 16, 2017
  28. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204
    Ah sorry. You meant making the shader using the deferred rendering path.
    Well this needs some conversion.
    It is not in my priorities right now. If you make anything please post it here.
     
  29. VKirillov

    VKirillov

    Joined:
    Oct 19, 2016
    Posts:
    3
    That IS the first improvement that ocean script needed! thank you a lot! I was waiting for it for almost a year))
     
  30. imgodot

    imgodot

    Joined:
    Nov 29, 2013
    Posts:
    176
    Is there any way to create a projector or decal or ??? that can be used on the Ocean?
    I'm looking to highlight a selected boat with a colored circle on top of the ocean.
    I tried using various projectors and they seemed to have minimal effect on the ocean surface.

    Thanks.
    -- Paul
     
  31. ahardy

    ahardy

    Joined:
    Feb 11, 2015
    Posts:
    10
    Hi all,
    Did someone manage to fixe the zdepth issue with d3d11 in forward rendering that prevent the shore effect from being active ?
    In the last repo I grabbed, there is a change in the shader for the z_reversed compilation instruction, but the only effect it has is applying the shore effect on all the water surface. Did someone manage to overcome this ?

    Cheers,
     
  32. IronDuke

    IronDuke

    Joined:
    May 13, 2014
    Posts:
    132
    Is the repo link in the OP the latest version? This thing looks impressive, though the price is even better.:D Totally want to try it out.:cool:

    --IronDuke
     
  33. DARKMOON01

    DARKMOON01

    Joined:
    Dec 7, 2015
    Posts:
    2
    This is a great project, and very useful. Could you possibly give me advice on how to create shore foam? I have been working with the settings, from the December Git, and I cannot seem to find a way to make foam when the waves hit the beach. Any advice would be appreciated!
    This is for oculus vr touch under unity pro. upload_2017-2-21_16-25-8.png
     

    Attached Files:

  34. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    374
  35. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,070
    I think @elias_t has been doing most of the work. ;)
     
    Flurgle likes this.
  36. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    374
  37. elias_t

    elias_t

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

    I have uploaded a new update that includes only the fix for the shoreline effect for Unity5.5 or newer:

    https://github.com/eliasts/Ocean_Community_Next_Gen

    What holds a bigger update back is that I want to render the depth in a render texture and use a mask on what to be rendered in it.

    This would allow the exclusion of ships/boats from the shoreline effect and an easy implementation of the shadows support.
     
    VKirillov, Lohrion and hopeful like this.
  38. DARKMOON01

    DARKMOON01

    Joined:
    Dec 7, 2015
    Posts:
    2
    That is impressive! I am guessing this work on any of the scenes. Thank you. This is an impressive undertaking, @elias_t. If I come up with any mods, I will be posting.
     
    elias_t likes this.
  39. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    This was an amazing drop in script for a complete newbie like me!

    Only thing, and this seems to be general across ALL ocean script packages I've seen so far, but I have a boat with an actual interior and when go inside there's water going right through everywhere. :)

    Also, since I'm a complete newbie, I did a quick google, but can someone tell me where to put the NATIV, SIMD, THREADS commands? I'm going to try to run this on a HTC Vive, so I need all the performance I can get.
     
  40. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204

    Hi.

    About your last question.

    File->Build Settings->Player Settings-->Other Settings--->Scripting Define Symbols.
     
  41. Armada_

    Armada_

    Joined:
    Sep 5, 2014
    Posts:
    9
    Hi @elias_t, thanks for all your hard work developing this shader.

    I downloaded your latest version from GitHub yesterday and loaded the project in Unity 5.5.1, but I noticed the shore foam now carpets the entire ocean, even when there's no land present (see below).

    ShoreFoam1.png ShoreFoam2.png

    I get the same result when importing the ocean into a separate project I recently upgraded to 5.5.1, but an older version of the ocean worked as expected in 5.4.1.
    The only way I managed to avoid this issue is by disabling the shore foam, but ideally I'd like to use this feature in my own project.

    Is there a setting I need to change to fix this, or could it be a bug?
     
  42. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204
    Hi it looks like that the ocean meshes are writing to the zbuffer where they shouldn't.

    My last test was on unity5.5p4.
    I will download 5.5.1 and get back to you.
     
  43. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    Can someone please share some settings to get a calm, but detailed ocean for real life scale? Ie, lots of small waves, say maximum 40cm high and 1 meter across? (Guess that's 0.4 x 1 Unity units.)

    My project is on a 12 meters long yacht for use in VR, and I can only ever either seem to get crazy large waves, which engulf the entire ship, or a completely flat sea.

    Also, any tips on how to prevent the water from getting into the boat would be appreciated. Someone mentioned applying this shader to a custom mesh, but I can't figure it out.

    EDIT: Forgot to mention that, regardless of windspeed or wave speed, the water/foam textures on the ocean always seem to be directionally moving, which is quickly causing me to be nauseous in VR...

    EDIT: One more thing... I can't seem to get the global fog image effect to work on the ocean, if I attach it to the SteamVR camera. It works great on my boat, but the ocean seems unaffected.
     
    Last edited: Feb 26, 2017
  44. mmonje

    mmonje

    Joined:
    Apr 26, 2015
    Posts:
    4
    VKirillov likes this.
  45. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,204
    radimoto, Aubrey-Falconer and hopeful like this.
  46. Aubrey-Falconer

    Aubrey-Falconer

    Joined:
    Feb 13, 2008
    Posts:
    434
    Hi friends! Mmonje's shore foam fix is working nicely for me.

    Does anyone have an idea on the best way to incorporate distance fog in Deferred rendering mode? The Global Fog postprocessing effect appears to have no effect. Elias - any chance the zbuffer updates you are working on for shadowcasting will enable postprocessing fog as well?
     
  47. Tesrym

    Tesrym

    Joined:
    Dec 2, 2012
    Posts:
    56
    http://i.imgur.com/3SHDCC7.mp4
    I dont know how to add this animated image properly, but I hope you can click it and have a look.
    Squares appear close to me, and I don't know how to remove them :(
    They appear if I turn on reflection OR refraction.

    I also get full foam in all of the presets except greyStorm, mobileFastQ, mobileLowQ and ocean1_fullReflRefr
     
  48. elias_t

    elias_t

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

    This comes unfortunately from the old design of the shader which applies per vertex the reflection.
    It should change in the future.

    The 2 things you could do right now to minimize the effect is to use higher resolution grids and not allow the camera to come very close to the sea.
     
    Tesrym likes this.
  49. ZeroGround

    ZeroGround

    Joined:
    Dec 21, 2016
    Posts:
    2
    Hey there @elias_t ! First let me thank you for this "development-diary" and the work you poured into this project itself, you are a god :D (Works magnificent on Asus Zenfone Selfie with lod 6-7 even )
    I was wonder if i wanted to have something like a texture that acts as an alpha-mask above the ocean how and where should i put it in the shader/or script?
    (eg.: to make an effect where the outer rim of the ocean blurs into nothingness based on said texture's alpha values - same as whats possible with fade rendering mode in Unity 5's standard shader )

    I tried to read through all the development process and questions posted here but its possible that I didn't notice a similar question to mine. If that is the case I apologize for repeating it :)
     
  50. elias_t

    elias_t

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

    First of all I want to apologize for taking again a long time for an update. By the time I found time to work on this lib another job came up.

    I am in a catch22 situation right now regarding shadows + shore line foam: When we have shadows then the meshes write to the camera depth buffer and then the whole ocean gets covered by foam.

    The workaround I was working on was to render the depth to a render texture and use this for shore lines. But the constant changes Unity along 5.x versions added a lot of frustration to it and I have this on hold.

    @ZeroGround. Look for the #ifdef FOGON directives in the transparent shader lods and use something like the manual fog procedure to influence the alpha of the shader.
     
    st-VALVe likes this.
unityunity