Search Unity

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,367
    Hello. You just have to get the height of the waves at your desired positions.
    Take a look at the getHeight functions after line 1907 in the Ocean.cs script.
    Also if you have an array of Vector3 positions the Native batched functions are faster (take a look after line 142 in the uocean.cs script.

    As for the boat height, use the same functions relative to your ship's position points.
     
    JamesArndt likes this.
  2. st-VALVe

    st-VALVe

    Joined:
    Jan 8, 2014
    Posts:
    13
    Hello, Elias! Could you help me? Is there any chance to prevent spawning interactive foam from a ship on other tiles of the ocean? I need to have small tiles and I see interactive foam nearby my ship too.
     
  3. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi st-Valve.

    There are 3 options.

    1. Disable the interactive foam.

    2. Use a global array to feed the shader with the interactive foam.

    3. Use the getHeight functions to apply decals or a line renderer as the ship's trail.
     
    st-VALVe likes this.
  4. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
  5. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Actually I believe a simpler solution for "wakes" coming off the boat occurred to me. The ocean system here is already producing "interactive foam" coming off the ship. Now I am wondering what might be a good approach to using a custom "foam" texture that is actually maybe a ripple or "wake" texture. I am not super technically minded, but I'm thinking maybe adding the extra texture slot to the shader and then using that texture (rather than the shore foam texture) for the "interactive foam" in the Ocean.cs script?
     
  6. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    I believe that it has something to do on how the interactive foam is calculated.
    Since it is a relic from the stone age, I plan to remove it.
     
  7. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Yes that is not a bad thought. But we get again the limitation of using a global texture.

    Ok. Let me make some experiments in the next days and I will post here the results.
     
    JamesArndt and st-VALVe like this.
  8. st-VALVe

    st-VALVe

    Joined:
    Jan 8, 2014
    Posts:
    13
    Make us happy on this Xmas, Santa!!))
     
    JamesArndt likes this.
  9. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Check this out. Now wouldn't this be cool if we could get it working?

     
    iichiversii, Peter77 and elias_t like this.
  10. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Thought I'd post this here just being an open source advocate and all.

    So I'm making a game that is ship heavy and decided that for most of the same reasons you should use kinematic controllers for characters, you should do the same with boats (and buoyancy also).

    So I created a kinematic controller and kinematic buoyancy component. The controller uses the new ComputePenetration calls and you can configure how much objects get pushed away from each other. From just enough to not penetrate to several meters. You can also set objects by layer so that they only depenetrate or get the bouncy push back effect, so for examples boats colliding with each other vs boat colliding with a terrain.

    The buoyancy component is a bit more rough, I'd actually love it if someone could help to get that better. The up and down motion is ok but the rotation logic is very basic. It just takes a width/height and then calculates 4 positions, reads the water height at those, and then rotates using an angle from the opposite point.

    I also have a ship controller designed to work for player, ai, and remote input. I use it with my own networking setup but it's useful as a starting point for how to move the ship in various context's.

    In addition to the more obvious advantages, it also performs a great deal better. You can easily have several hundred buoyant kinematic objects with minimal cpu impact. The open source buoyancy script for example which everyone uses, would kill your performance with those numbers.

    I will be open sourcing it soon, but just a fair warning it's a developers tool and I have no intention of supporting it or having it's own forum thread. I'd be happy just to see it included in some other water based projects, I have no desire to support end users that aren't developers.
     
    JamesArndt, mgear and elias_t like this.
  11. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Yes something like this can be implemented but it would require a higher grid resolution since the system still works with tiles.

    I have a basic projection grid working but still needs polishing before it can get included in the release.
     
    Flurgle, RendCycle and JamesArndt like this.
  12. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi this sounds very interesting. If you post the scripts I will try to implement them.
     
  13. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I'll get it up on github this weekend. Shouldn't take any implementation really, just creating a couple of prefabs.
     
    elias_t likes this.
  14. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Hi there ! It seems that in our project, the zdepth for the shoreline is not correctly calculated. I've seen this issue on all other "soft particles" shaders, but the latest soft particle shader from Unity works well.
    Here's how it looks like on our game right now, it seems that the foam texture is applied on the meshes under the water rather than on the surface.

    I've tried to change the part of shader that is handling the shore line, but it's quite more complicated than a basic soft particle shader.
    Any ideas ? thanks !
     

    Attached Files:

  15. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Ouch. Another modification of the depth buffer behavior by Unity. Thanks Unity Team!

    Which version of unity are you using?
     
    JamesArndt likes this.
  16. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    I'm currently on the 2017.2.0p4 version, but I've noticed this issue since a long time (5.6+, maybe 5.5) on all custom soft particle shaders. Integrating the ocean system is quite new (replacing Suimono because of lack of PS4 compatibility), I would say since we upgraded to 2017.x versions.
     
  17. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    I've just downloaded and imported the latest Github into Unity 2017.2.0p4. The shore foam is looking correct here. By default it's a bit intense so by setting the "Shore Distance" to something small like a value of 2, and setting "Shore Strength" to a value of 1 (which is it's minimum) I got something that looked decently okay. Once thing that that bothers me is not having independent adjustment for foam around structures and boats vs. the foam for the shore. For instance to get good foam around a boat I use these values, but at the same time it sets those same values for my landmass shores which don't look right. The shores should have a longer shore distance value than a boat in the water.

    Also my second tweak is the UI background the Ocean object in the Inspector. It uses black text that looks okay in front of the light background at the top. Once the black text is over the bottom of the gradient it's near black on black and almost completely illegible. I always find myself going into the Ocean UI Inspector script and setting the opacity for the UI background really low so it's all legible.

    To do this I open up OceanGeneratorInspector.cs and on line 1342 I adjust this part:
    GUI.color = new Color(0.6f, 0.6f, 0.6f, 1f);
    to become this:
    GUI.color = new Color(0.6f, 0.6f, 0.6f, .2f);

    On the left is the too-dark-to-read original and on the right is the .2f alpha opacity change.

     
    Last edited: Jan 8, 2018
    Peter77 likes this.
  18. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Very interesting ! If you're right it means that there is some setup in our project that will change the behaviour of the shoreline (and soft particles in general) that doesn't apply on the new particle shaders from latest unity version.
    Our game is in deferred and uses the post process stack (v1). I will take a look to the graphics settings to check if there is anything that might break it.
    Thanks for your feedback !
     
  19. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    This has been discussed in the past.

    And I had started using a render texture for the depth so you could use Layermasks, on what object should get shore foam using the depth buffer. But with all the changes unity did, I got frustrated and dropped it. I will try it again.

    For now, the only way not having shore foam on your boat is to use the renderque to avoid writing to the zbuffer. But then you will loose shadows.
     
    JamesArndt likes this.
  20. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    cayou, the post process stack might play some role. Try to disable and look for any difference.

    Also close the project and delete the shader cache from the library to force the shaders to recompile.
     
    cAyouMontreal likes this.
  21. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Alright, I decided to start from scratch (new project) to see if I can find a way to reproduce the issue.
    Guess what, after downloading the project from github (downloaded the zip directly, master branch?), I've opened a test scene, and I have the same issue.
    Of course the shoreline on objects that have no "ends" (like a beach) will not have this issue (because you can't see it), but an object on the water, like the boat will have it.

    Edit: same results with 2017.3.0f3
    Edit2: When I look to the screenshots on the github page, it looks like the result is the same. Maybe I'm wrong here and I've expected something else from the shoreline effect ahah :D
     

    Attached Files:

    Last edited: Jan 8, 2018
    JamesArndt likes this.
  22. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    I stand corrected. I didn't look close enough to see the real issue happening. I can confirm the foam is not showing at the right render depth.

    Dude you've got enough on your plate. No expectations from me on this. I really wish I were more technically minded and could help implement these revisions and updates.
     
  23. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    good to know ! sounds like the same issue I have with all my soft particles shader. I've tried to update the code that is handling the zdepth of the shoreline but nothing worked correctly, I only had worse results.
    I've started from the new Unity soft particle shader, the code is quite different than you had to write before, but I don't know what exactly changed since.

    Thanks for the support, it's highly appreciated !
     
    JamesArndt likes this.
  24. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Ok the Kinematic vehicle/buoyancy stuff is up on github.

    https://github.com/gamemachine/kinematicBoatController

    It's a work in progress as I just put in the basics for our game and we will definitely be improving it later. It's good enough for us at this stage, it proves the direction is right.
     
    JamesArndt, elias_t and camta005 like this.
  25. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Thanks for the release. I will try it in the next days.
     
  26. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    One little thing, I had to scale down the ocean (the root) because it feels like it's very difficult to change the scale feeling with only the settings, all felt too big for our project (specially waves). Even an object from the example like the barrel is really big. After resolving all the issue with all ocean LODs meshes (they didn't like being scaled down), I still have an issue with buoyancy object. It looks like they don't take the scale of the ocean into account, and they still move depending on what the ocean would be on a scale of 1.
    I will take a look to the script that handle the buoyancy effect (the position from the ocean).
     
  27. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    I strongly recommend against scaling the root ocean object.

    The best way is to set the size of the tiles smaller. (In the Tiles section of the inspector.)
     
  28. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Can you explain why? I had issues with scaling ocean tiles and positioning them, but after some code fixing now it works well and I don't see more issues related to that (except the buoy script). The foam is fine, the shoreline is "fine" (when the zdepth issue will be fixed), and everything feels better in our game. I went from a feel of a ocean plane "tilting" to actual good looking waves.
    Changing the tile size didn't change a lot of thing on the simulation, it made it more precise, but the scale feeling remained the same.
    Having a general scale factor would be cool !
     
  29. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Because the whole simulation depends on a 1 to 1 scale as it is right now. This is why the buoyancy will not work correct.

    The getHeight functions will give you wrong results.

    If you still want to go this route you would want to adjust the getHeight functions according to your scale.
     
  30. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    And to get a little work of your back, I would advise to wait for the projected grid solution where we will get rid of the tile issues.
     
    JamesArndt likes this.
  31. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Sounds good ! Is there anywhere an official "road-map" of the plugin?
    Our project is to be released quite soon, I don't know if I will have the time to wait for new updates.
     
  32. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Sorry I can't give an exact date. But my first 3 priorities are the projected grid, zbuffer issues and interactive foam.

    So yes, if you are in a tight time budget Ι would suggest to go with the tile solution.

    Try to lower the tile sizes, and then play with the wave scale and choppiness settings to get your desired results.
     
    cAyouMontreal likes this.
  33. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Alright, thanks !
     
  34. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    It seems like if you move the ocean yourself (not by using the follow checkbox) the buoy will be a the wrong height too.
    Is there any way to tell the ocean to handle that offset?
     
  35. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Add this offset to the getHeight functions the buoyancy script is using.
     
  36. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    it looks like more an x/z offset than a y offset. Like the vertical movement is coming from a wrong position of the ocean.
     
  37. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Yes of course. The getHeight functions return a height at a x/z position.
     
  38. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Alright, I will try it, thx !
     
    JamesArndt likes this.
  39. CandyManCriminal

    CandyManCriminal

    Joined:
    Sep 15, 2014
    Posts:
    2
    gorgeous, but what about going under it?
     
    JamesArndt likes this.
  40. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    This is a tesselated water surface only. It's awesome looking, but if you're looking for something with underwater effects there are other packages that offer that. I don't know if there is a roadmap to add in underwater effects. I am sure you could roll your own using the Post Processing Stack combined with some code to determine if your camera is above the water surface or below it.
     
    CandyManCriminal likes this.
  41. CandyManCriminal

    CandyManCriminal

    Joined:
    Sep 15, 2014
    Posts:
    2
    welp, i've been up and down the internet gathering things to work on underwater effects to add to this... and then i noticed that it doesnt have an underside

    im still gunna mess with it tho
     
  42. JohnSmith1915

    JohnSmith1915

    Joined:
    Apr 21, 2016
    Posts:
    143
    JamesArndt likes this.
  43. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Hey there !
    Any fix planned for the issue where the shoreline foam is not correctly rendered?

    (btw applying the offset on the buoy position worked like a charm, I can now use them and move the ocean at the same time)
     
  44. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    Another question:
    Do you know if it's somehow possible to trigger some water splash effect when waves are hitting some geometry? It will add so much to my night storm scene.
    Thanks !
     
  45. Synaps3

    Synaps3

    Joined:
    Mar 31, 2014
    Posts:
    5
    Hi,
    I am having a problem with the rendering of the foam. For some reason I don't see this problem in the demo or some of the screenshots I've seen, but that could simply be that it's not very noticeable without objects that have a lot of holes in them.

    Anyway, the problem is that when the foam is turned on, all the trees and other objects on my island leave white traces around them (similar to when someone does a bad job with cutting out an image). The only way I can get it to go away is by disabling the foam, or disabling anti-aliasing. This only occurs when objects are in front of the water, not the entire map.
    foam.png
     
  46. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,983
    Has anyone made any progress on any dynamic displacement?

    It would be great to be able to get a wave to form at the front of a ship as it goes through the water!

    If noone is able to I will try and take a look myself at the weekend, but if anyone has made any progress even if unfinished I would love to know / continue it for you

    @elias_t perhaps?
     
  47. Lolo314

    Lolo314

    Joined:
    Feb 16, 2018
    Posts:
    1
    I've made some more impressive screenshots after some tweaks.
    I hope, you'll like it.
    Excellent project!!! Ocean_Simulation.jpg
     
  48. popandersson

    popandersson

    Joined:
    Oct 15, 2015
    Posts:
    6
    This is very nice and I'm impressed, but...
    If I add a 1.7meter character in Unity scale to the fishingboat it becomes a very tiny character. If I then rescale the fishingboat to match the character everything gets F***ed up. Is there any special reason for not using Unity scale? Can I do anything to fix it else then resize my character?
     
  49. popandersson

    popandersson

    Joined:
    Oct 15, 2015
    Posts:
    6
    I'm sorry. If I rescale the actually mesh everything seem to work just fine, so don't bother to answer.
     
  50. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi. Scaling the mesh is not right. You have to set the tile size (upper right of the inspector.)

    The demo is like this from the beginning to demonstrate a large ship. I will change this to a 1:1 scale in the next update.
     
    red2blue and MadeFromPolygons like this.