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

Physics Water 2D Tool - GPU based ripple water, realistic buoyancy, water flow & animation

Discussion in 'Tools In Progress' started by Nicrom, Feb 23, 2015.

  1. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    By the way, for my LWRP update I plan to support Unity 2019.1.0 and above, is that ok with you?
     
    Lars-Steenhoff likes this.
  2. Innocent-Dev

    Innocent-Dev

    Joined:
    Apr 1, 2015
    Posts:
    23
    Yes its its ok thanks
     
    Nicrom likes this.
  3. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,465
    Yes just go straight to URP
     
  4. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    The URP will be available starting with Unity 2019.3 which is currently in beta. The current version of my LWRP update works with Unity 2019.1 and 2019.2, but not with 2019.3. The change from LWRP to URP is not just in name, there are internal changes that break the compatibility with custom shaders that work on older versions of Unity. Also if I set the minimum version to 2019.3, the users that want to stay on Unity 2019.1 or 2019.2 LWRP will not be able to use this update.
     
  5. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,465
    I understand. and its good to keep compatibility with a wide range of
    versions.

    I do also think most users who want to stay on one version will want to stay at an LTS version, meaning 2019.4 or 2018.4 and 2019.4 will have only URP support.

    But I'm sure you will support URP at some point when its more meanstream.
     
  6. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Once this update is done, I'll work on a compatibility update with 2019.3 and URP, so by the time Unity 2019.3 stable version gets released, Water 2D Tool should work with URP.
     
    Innocent-Dev and Lars-Steenhoff like this.
  7. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,465
    Great to hear! Thanks
     
    Nicrom likes this.
  8. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Water 2D Tool v1.9 is available on the Unity Asset Store.

    Hello everyone.

    Water 2D Tool v1.9 is now available on the Unity Asset Store.


    Upgrade Water 2D Tool shaders and materials to LWRP.

    If you download Water 2D Tool in a Unity project that uses LWRP or upgrade a project to LWRP, you will get a lot of shader errors. This is happening because by default the Water 2D Tool shaders and materials are not compatible with LWRP. To upgrade the shaders, right click on the Water2D_Tool folder, select Import Package->Custom Package. In the window that pops up go to Water2D_Tool/'Assets/LWRP folder and import Water2DTool_LWRP.unitypackage. If the error are still present in the console, clear them manually. Sometimes Unity doesn't clear them automatically even when nothing generates an error.

    IMPORTANT:
    • For the ripple shaders to work correctly, enable Depth Texture and Opaque Texture. This options can be enabled in the LWRP asset.
    • Currently LWRP is supported only for Unity 2019.1 and 2019.2.


    Differences between the LWRP and Build-in Renderer Pipeline.

    When you create a GPU based water object you will see that the top mesh is positioned a little lower than it should. This happens only in the Editor. At run time the top mesh is positioned correctly.




    Visually the water looks about 95% the same as in the Build-in Renderer Pipeline.

    Build-in Renderer Pipeline.


    LWRP.



    The excetion is, how the water looks when the camera is below the water line. Because of how the LWRP works its impossible to make the bottom of the top mesh look like in the Build-in Renderer Pipeline. In the Build-in Renderer Pipeline you can grab the contents of the screen, by using GrabPass in the shader and you could do that whenever you needed it. This meant you could stack multiple transparent objects with distortions and they would be rendered correctly. In LWRP there is no GrabPass. There is an alternative called _CameraOpaqueTexture, but this is a global GrabPass performed only once after all the opaque objects are rendered. So if you have multiple transparent objects that need the content of the screen behind them to perform some kind of image distortion and these objects are overlaying, only the last one will be visible. As a result of this, you can't see the top mesh when the camera was below the water line. To fix this problem I change the render queue of the top mesh material when the camera is below the water line, so that it is drawn before the LWRP performs the global GrabPass, but as you can see from the image below, it doesn't look exactly like in the Build-in Renderer Pipeline.

    Build-in Renderer Pipeline.


    LWRP.


    The way the water looks depends mostly on how the scene looks and what deep and shallow water colors you use, so its possible to hide the fact that the water uses an unlit shader.

    Best regards,
    Nicrom.
     
    Last edited: Sep 10, 2019
    Too-Nerd-To-Die and Innocent-Dev like this.
  9. Nyro

    Nyro

    Joined:
    Aug 23, 2013
    Posts:
    18
    Hi, is it possible to make the ripples move with the flow? Im making a game where there is a stopped ripple source, and i want to make it look like the water is flowing.
     
  10. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi. I'm sorry, but currently this is not possible.
     
  11. matonachtmann

    matonachtmann

    Joined:
    Mar 6, 2018
    Posts:
    1
    Hey!

    How can i make thewater more transparent?
    I am making a game where i will be diving under water and it is hard to see the character.

    Thank you.
     
  12. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi.

    I assume you are taking about the GPU based water. If so, then for the front mesh you can use the Opacity slider to decrease the water opacity. Also try to disable the toggle Fog.

    Best regards,
    Nicrom.
     
  13. Pauleta

    Pauleta

    Joined:
    Aug 8, 2013
    Posts:
    20
    Hello, I just bought the asset from asset store but I am having a problem with ripple damping on mobile. I tried to tweak the damping value but this problem still persists. You can see that the waves get wild on the right of the screen. Can you help me, please?
     
    KingsHere likes this.
  14. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi.

    This is happening because, some mobile devices do not support the Render Texture format and Filter mode, used by Water 2D Tool GPU based water.

    Open the Water2D_Ripple script, go to line 75 and try to change
    Code (CSharp):
    1. private RenderTextureFormat rtFormat = RenderTextureFormat.RFloat;
    to
    Code (CSharp):
    1. private RenderTextureFormat rtFormat = RenderTextureFormat.RHalf;

    Also go to line 414 and change
    Code (CSharp):
    1. bufferCurrent.filterMode = FilterMode.Trilinear;
    to
    Code (CSharp):
    1. bufferCurrent.filterMode = FilterMode.Bilinear;
    This should fix the problem for some devices.
     
  15. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    @Pauleta , I forgot to mention, this problem seems to affect only the devices that use the OpenGLES2 or OpenGLES3 Graphics API. Those that use the Vulcan API are not effected.
     
  16. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi @Pauleta, I'm sorry for getting back to you so late.

    I tested on my Redmi Note 7 and found than setting the FilterMode to Point fixes the problem when using OpenGLES2 or OpenGLES3 Graphics APIs.

    Open the Water2D_Ripple script and on line 413 make sure FilterMode is set to Point
    Code (CSharp):
    1. bufferCurrent.filterMode = FilterMode.Point;
    Also on line 75 change the code back to this
    Code (CSharp):
    1. private RenderTextureFormat rtFormat = RenderTextureFormat.RFloat;
     
    KingsHere likes this.
  17. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,492
    This looks like an amazing asset. Wonderful effects!

    Before i buy it, I'd need to know whether it supports my usecase though:
    Does it support air pockets?
    That would mean having a cut-through mesh that forms a cave which is half-filled with water and thus have a surface inside. Outside the mesh should be water too and another "main" surface way above. The water of the cave should seamlessly connect with the water around.

    Huge thanks!
     
  18. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi
    Hi. I'm sorry but, the water mesh can only be a rectangle and can't have holes in it. The front and top of the water are 2 separate game objects, each with its own rectangle mesh.

    Best regards,
    Nicrom.
     
  19. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,492
    Wow, thank you for the fast answer!
    Hmm, I had the most hope in your asset in this regard (compared to other UW effect ones). Is there a specific reason that the water mesh can only be rectangular? I am proceduraly generating the cave mesh already (and also a flat shape for everything the player cannot see), so I could create the right shape of mesh for water too if that is the main issue. Rectangular water-surface would not be a problem.
     
  20. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    The Water 2D Tool code expects the water to be a rectangle so if for example you want the front mesh to have holes, it would require some major modifications to the code.
     
  21. bluevideogame

    bluevideogame

    Joined:
    May 31, 2018
    Posts:
    10
    The reflection works the first time I add it to the game, but if I try to turn off the game and press start again it causes this error - How can I fix?

    MissingComponentException: There is no 'Camera' attached to the "New Water2D_TMReflection-79131944-for-SceneCamera" game object, but a script is trying to access it.
    You probably need to add a Camera to the game object "New Water2D_TMReflection-79131944-for-SceneCamera". Or your script needs to check if the component is attached before using it.
    ThreeEyedGames.DecaliciousRenderer.OnPreRender () (at Assets/Assets - Effects/Decalicious/Scripts/DecaliciousRenderer.cs:109)
    UnityEngine.Camera:Render()
    Water2DTool.Water2D_PlanarReflection:RenderReflectionFor(Camera, Camera) (at Assets/Water2D_Tool/Assets/Scripts/Utils/Water2D_PlanarReflection.cs:281)
    Water2DTool.Water2D_PlanarReflection:RenderHelpCameras(Camera) (at Assets/Water2D_Tool/Assets/Scripts/Utils/Water2D_PlanarReflection.cs:141)
    Water2DTool.Water2D_PlanarReflection:WaterTileBeingRendered(Transform, Camera) (at Assets/Water2D_Tool/Assets/Scripts/Utils/Water2D_PlanarReflection.cs:158)
    Water2DTool.Water2D_PlanarReflection:OnWillRenderObject() (at Assets/Water2D_Tool/Assets/Scripts/Utils/Water2D_PlanarReflection.cs:169)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  22. DantePinto

    DantePinto

    Joined:
    May 21, 2019
    Posts:
    4
    Hi,

    I am working in my solo indie game in Unity 2D and I also bought you Water 2D Tool solution, but I am having a problem to solve in it, let see if you can help me.

    Reading your guide I noticed that the water meshes cannot be rotated, and I wanted to rotate the top mesh so the its waves appear in my 2D game with ortographic camera, as the image attached try to show.

    So I tought why not change the positions in Y axis of the last half of the vertices (as enumerated in the guide the last half of the vertices are the ones (in the top mesh) that are further away from the camera) so the mesh can be seen in camera as I desire.

    I dont know if you can understand what I explained, but the top mesh must "fake" a perspective as I do in my tilemaps (in the water mesh will be real perspertive though), so I thought changing the Y value of the vertices further away from camera would work. Can you help me find were I must change the code, because I am totally lost digging. I tried lots of things without success.

    Thanks in advance. Love your work.
     

    Attached Files:

  23. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi.

    Open the Water2D_Tool script, go to
    Code (CSharp):
    1. GenerateTopMeshDataWithTiling()
    method, line 699 and paste

    Code (CSharp):
    1. if (z == 1)
    2.       vertPos.y += 1f;
    before the line below.

    Code (CSharp):
    1. ChildDMesh.AddVertex(vertPos, UV, true);
    This will move the back of the top mesh 1m above the water line. You can change 1f with another value. After you save the script, resize the water so that the mesh is rebuild or press Rebuild Water Object button. Also make sure the Z Segments field value is 1.
     
    DantePinto likes this.
  24. malyKuba

    malyKuba

    Joined:
    Jan 30, 2013
    Posts:
    9
    Hi, any plans for HDRP support?
     
  25. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi. I am currently busy with other projects and do not have the time to work on porting the shaders to HDRP, but that may change in the future.
     
  26. codingDevil

    codingDevil

    Joined:
    Feb 13, 2020
    Posts:
    4
    Hello. Is there any tutorial to make skybox reflection 2D water? I tried follow the setting in BigLake_Lit but didn't succeed.
     
  27. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hello @dragondragoon4.

    Can you show me a screenshot of the problem you have?.

    By the way I have a Discord server. If you want, you can join. It will be easier for me to help you with your problem
     
  28. capjeff

    capjeff

    Joined:
    Mar 9, 2020
    Posts:
    3
    Hi

    I want to make an endless 2D runner based on your water.
    I animated water to moving blocks, as in the animation tutorial.

    A ship can change its direction of movement.

    When a ship changes direction (from left to right), the waves also change their direction and velocity. Why?

    How can I keep the direction of wave motion independent of the movement of a block of water and keep the velocitys the same?

    I already read a similar question, where did you advise turning to the list with speeds. If this solution is suitable and could you please explain in more detail how I can do this.

    Many thanks!
     
    Last edited: May 15, 2020
  29. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi.

    Can you record a small video that showcases the issue you have?
     
  30. capjeff

    capjeff

    Joined:
    Mar 9, 2020
    Posts:
    3
    Thanks for the quick response :)

     
  31. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    From what I can see, the direction of the waves stays the same when the ship changes movement directions. When the ship starts to move in the oposite direction of the wave movement, it creates the ilusion that the waves move faster.
     
  32. capjeff

    capjeff

    Joined:
    Mar 9, 2020
    Posts:
    3
    Fixed, sorry for the spent time :)
    Thx for your job!
     
    Nicrom likes this.
  33. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    Asked by mail early last month, but probably ended up in the spam (no reply), posting it here in case someone else is trying to achieve something similar and running into the same problem.

    ---
    Wanted to see how difficult it would be to integrate your asset in my project and while experimenting with it I ran into a weird issue, possibly a bug in unity, but since it's reproducible I thought I'd at least show. It's a bit long to explain, so bear with me.

    So, in the 2d renderer, with blur posteffect on a background camera in non-HDR using stacking, when the walls move the water doesn't 'fill the gap'. Captured everything in a video, but the video-capture doesn't show things like context menu's opening, so details below. To see the issue, skip to the end at 2:20 where the walls start moving:


    Repro steps:
    - starting a new URP project
    - Import water 2d tool (upgrade project shaders).
    - select scene Sandbox_01
    - create a new base camera, child of main-cam
    - edit urp/runtime/scriptablerenderer and change camerastacking from false to true // not yet officially supported(!)
    - select main camera, change to overlay
    - select new camera, add maincamera to the stack (not possible without the urp/runtime change).
    - enable postprocessing on new camera (not on maincam)
    - add global volume, add override, "bokeh" and set it to some high value (so it's obvious it is blurring)
    - create 2d experimental renderer
    - set the active universalRP to use the 2d renderer (instead of default forward renderer)
    - disable HDR
    - create new layer "BackgroundLayer"
    - Set Background + all children in hierarchy to be part of this layer
    - Set culling mask of the new camera to only BackgroundLayer
    - Set culling mask of the maincamera to all except BackgroundLayer

    Run the scene. Background wil be nicely blurred.
    However where the walls move, the water looks broken.

    Disabling HDR will "fix" it however also disables posteffects, probably a unity bug.
    Disabling posteffect also "fixes" it.
    Using the forward renderer works (both when HDR is enabled or disabled).

    But it's not possible to have a nicely blurred background/posteffect + working water in the 2d renderer.

    Admitted, stacked camera's are not officially supported in the 2d experimental renderer, and it's quite likely this is a bug in Unity itself, so understandable if you don't want to further investigate.
    ---

    Note that in the meanwhile one of the Unity developers mentioned the 2d renderer will get official support for camera stacking in the next URP update, so maybe the problem will "solve itself" (alternatively I'll post a bugreport with Unity at that point).
     
  34. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi @rboerdijk.

    I've checked my email and found no missed emails. Not sure what happened. Can you tell me your email?

    I'll look into this issue and see if I can find what causes this behaviour.

    By the way, if you use Discord, you can join my Discord server. It will be easer for me to help you with your issue.

    Best regards,
    Nicrom.
     
    Last edited: Jun 7, 2020
  35. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    @rboerdijk I think I found the problem. You need to enable the "Post Processing" toggle on both cameras.
    In my project this fixed the issue.
     
    rboerdijk likes this.
  36. King_of_L1mbs

    King_of_L1mbs

    Joined:
    Jun 15, 2019
    Posts:
    18
    Hi @Nicrom. Just got your tool for a small game and like it so far. I have a problem though:
    I need to have a UI-Knob at the bottom of my screen, but the water asset somhow blocks OnDrag-recognition. UI-Buttons work but not dragging. Hope you can help.
     
  37. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi @King_of_L1mbs. What version of Unity do you use and what type of water? By the way, if you use Discord, you can join my Discord server. It will be easer for me to help you with your issue.
     
  38. King_of_L1mbs

    King_of_L1mbs

    Joined:
    Jun 15, 2019
    Posts:
    18
    Oh, I'm sorry! Just realized I had messed up my code and it was pure coincidence that the drag stopped working right where the waterline began.
    Thanks for the quick reply though!
     
    Nicrom likes this.
  39. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    Does this work in VR?
     
  40. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi, I do not have a VR device, so I can't say for sure if it works or not
     
  41. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    I would be using this for Oculus Quest 2 development. I think it strips out depth buffer from shaders. Is this something the asset relies on?
     
  42. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    The GPU based ripple water shaders use the depth. These are the shaders that have real time reflections
     
  43. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    Thanks for the quick response. Maybe I’ll give it a try and see if it works.
    Is there an easy way to add foam where object interact with the water or shoreline?
     
    Nicrom likes this.
  44. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    The GPU based water shaders have foam simulation.
     
  45. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
  46. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
  47. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    95
    Hey Nicrom,
    Thank you for this tool! It really fits the feeling of the project I'm working on.
    That said, I'm running into a problem where the ambient waves just stop working. No other advanced feature is used, just that. Is there anything in particular I should be doing to make sure that the method for that runs?
     
  48. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Hi.
    What version of Unity are you using?
    What pipeline are you using Built-In, LWRP or URP?
     
  49. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    95
    Built-In Pipe Line, Unity 2019.4.3f1
    - GPU 2.5D Water with Box Collider.

    Here's an odd thing. If I enable it, and start Play, it starts up for a second and then the waves go flat.

    However if I disable it, and start it while in Play mode, the waves work the way they're supposed to. Doing the same thing by flipping the ambientwaves variable in code does not work.
     
    Last edited: Dec 24, 2020
  50. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    419
    Can you record a video of the issue?
    By the way, if you use Discord you can join my Discord server. It will be easier for me to help you with your issue.