Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Dynamic Water System [Released]

Discussion in 'Assets and Asset Store' started by ZimM, Aug 14, 2013.

  1. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    421
    I am using this water system in a unique way, for a game where the ground is actually solid but moves. I'm trying to make it so that an object is vertically 'locked' to the surface of the water and moves exactly with it. It looks like the existing system isn't entirely meant to do this (I could be wrong - please correct me if I am!). So, I am looking to write a custom component that will grab the Y height of the wave at the current X/Z position of the water plane. Though I so far have not figured out how to do that. Could you please give me a tip on...

    1.) Is there an existing way to make it so an object is 'locked' to the Y surface of the water?
    2.) If no to 1., how would I determine the Y height of the water at a specific position in world space?

    Thank you! :)
     
  2. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @DCalabrese
    Hi there,

    1) no, unfortunately
    2) yes, actually, there is exactly a method for that :) See DynamicWater.GetWaterLevel(float x, float z) ("Returns water level at the given position in world space."). Use the docs - they exist for a reason ;)
    Hope this helps.

    -Best,
    Serhii.
     
  3. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    421
    I actually did use the docs and used that exact function. ;)

    However it was returning a value of "-infinity" when I used it, so I thought it might have been returning the water level in a more localized form to the system than to the actual world. So that leads me to - what would cause it to give a value of -infinity when I put in a proper X / Z coordinate?

    Here's my code:
    Code (csharp):
    1.  
    2.     void Update ()
    3.     {
    4.         float waterHeightAtPos = crowdWaterDetector.GetWaterLevel(transform.position.x, transform.position.z);
    5.         Vector3 raftPos = transform.position;
    6.         raftPos.y = waterHeightAtPos;
    7.         transform.position = raftPos;
    8.     }
    9.  
     
    Last edited: May 13, 2014
  4. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hmm, it only returns -infinity only if the position you are querying is outside the water boundaries (so there is no water there). The arguments to that method are definitely in world space, so it's odd you're getting wrong results (assuming the arguments are correct)... I've made a simple test scene (attached), please take a look at it and compare with your situation.
     

    Attached Files:

  5. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Oh, and if you use WaterDetector script - make sure your object has a Rigidbody, as WaterDetector relies on trigger colliders to work.
     
  6. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    421
    Looks like it was the lack of the rigid body that was causing the problem. I pulled out WaterDetector now that I can see it really wasn't needed for what I was doing and fashioned it after the code you sent over. Thank you for the assistance!
     
  7. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    421
    One item I am struggling with a little bit still here is accuracy. It seems that if I have a larger body of water, the accuracy of the vertical position returned by GetWaterLevel can be a bit off, unless I also turn up the quality to be pretty high. High quality nukes performance on mobile, so I need to keep the quality around 20 - 25. Is there a way to make the vertical position returned by GetWaterLevel to be more accurate to the actual vertical position of that point on the mesh? If not, might there be a way to use a Raycast down to the water which, in turn, could return the collision point and then use that as our actual point against the surface?
     
  8. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Well, Dynamic Water System isn't actually designed for large water bodies, so unfortunately there is no built-in way to do that. GetWaterLevel returns the value at the nearest grid node, and with quality around 20-25 that may be quite off... The problem is - the visible mesh is actually the approximation of smooth surface using the low-resolution data, not the other way around, so there is no easy way to make it more accurate, as basically, what you want is getting a accuracte value of approximation of accurate value of another kind :) You can't do a raycast with MeshCollider, obviously, as that will make everything crawl even on PC.
    However, there is a very ugly way to do that, though - use the actual mesh triangles and make a custom pseudo-raycasting code against them. This will work as you want it to work, but it's hard to say how big amount of work will that require. I will keep this in mind for a possible update, but that may require reworking things quite a lot. For now, unfortunately, I can only recommend rewriting GetWaterLevel for your needs (and I understand you don't really want to get through all that code, but I won't have enough time to implement this myself for at least two weeks).
     
  9. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    421

    Okay, that indeed answers my questions there. For the time being then perhaps this water system isn't the best solution for what I need to accomplish. Though the system itself is awesome and I already know a couple future projects I will be using it for, both of which don't have the unique requirements of this current project. :)
     
  10. DziDAI

    DziDAI

    Joined:
    Dec 6, 2012
    Posts:
    68
    is it possible to specify the radius of the wave?
    I would like to restrict the movement of the waves

    Thanks
     
  11. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Could you please clarify? Not sure what do you mean under "radius of the waves"... If you are creating waves with DW_MouseSplash script, try adjusting the Splash Radius field.
    The movement of the waves itself can be restricted in two ways: by using obstruction geometry or by using obstruction texture. See Pool and Obstruction demo scenes as references, they use both techniques.
     
  12. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Hi.

    Are there sources for native plugins?
    What are performance gains using them?
     
  13. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi,
    sources for native plugins are not included in the package at the moment, but I can send them if you need that, just PM me. The performance gain differs a lot on different platforms and devices, but on average, it is something like 30-40%.
     
    Last edited: May 20, 2014
  14. IanStanbridge

    IanStanbridge

    Joined:
    Aug 26, 2013
    Posts:
    334
    It might be an idea to also include the source as well as a DLL . Looking at the changes coming in Unity 5 people will probably want the source code so it can take advantage of the new compiler in Unity 5. If for your asset the performance difference in using a dll is 40% it makes sense to use that as default for Unity 4 users but Unity 5 users will probably want it recompiled to take advantage of the new compiler.

    Why not include an archive of the source so that people can recompile it if they want ? I think a lot of users will start being wary about buying assets without the source because they won't know how well they will work with unity 5.
     
  15. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Do you mean the newly-announced IL2CPP? It has nothing to do with that, really. Dynamic Water System uses hand-written C++ code for some math-heavy parts of code on Android and Windows standalone, other platforms use regular C# code that was always open. What valyard was asking for is the source code to a native dll, which is less that 1% of the code. And regarding that:
    1) IL2CPP will be initially used only on WebGL platform, and who knows how many time will come until other platforms are supported?
    2) IL2CPP only works with IL code produced by C#/UnityScript compiler, so there is no way it can speed up a C++ dll. It is a completely different universe
    3) C# code compiled with IL2CPP will get a performance boost for other platforms without any actions from users.

    Not really. IL2CPP works on IL level, which means that compiled C# dll will be processed by it as well.

    So basically - there are zero problems with supporting IL2CPP, either it is closed or open source, it won't be slower in any case. And future transition to IL2CPP, while increasing the performance of .NET code, will be quite seamless.

    Having said that, there is no problem in including the native library source :) I'll do that in a update for sure (and probably increase the list of platforms that use it).

    UPD: And if you mean the API changes that are coming in Unity 5... Well, I'm pretty sure these changes could easily break 90% of code assets on the Asset Store, and that indeed would render closed-source libraries useless. This is not the case, though: DWS C# source code will always be open, and I surely will adapt it to the changes that'll come in Unity 5.
     
    Last edited: May 20, 2014
  16. Tanshaydar

    Tanshaydar

    Joined:
    Apr 20, 2011
    Posts:
    33
    Hi;
    I'm unable to have a WebPlayer build, EncodeFloat.cs is seemingly the problem. Is it crucial to the rest of the calculation, or can I play with it?
     
  17. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    There is no EncodeFloat.cs in Dynamic Water System, so this is unrelated. Check other assets that you use.
     
  18. Tanshaydar

    Tanshaydar

    Joined:
    Apr 20, 2011
    Posts:
    33
    Ops, I'm really sorry, I put some relevant scripts together and I thought it was Dynamic Water System's, my bad.
     
  19. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Hey there, it's been about a month and I just wanted to follow up on non-averaged/faceted normals for the water. Would be lovely to have this for lowpoly style games like ours :)

    I understand you may be just now getting some time to work, just wanted to send a reminder.
     
  20. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    True, just got some free time, so I'll probably implement that feature sometime next week. Stay tuned :)
     
  21. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,291
    Thanks, i will try that
     
    ZimM likes this.
  22. hellodarren2000

    hellodarren2000

    Joined:
    Jun 17, 2014
    Posts:
    2
    Hi. I'm using the Water object from the DW_Boat scene but am having trouble in reducing the vertical size of the waves (I want them to be much smaller so they are more of a ripple). I've tried changing a bunch of the settings, such as the Waves Amplitude and Steepness, but it doesn't seem to be having any effect.

    Would it also be possible to somehow visually fade the water out around the edges? So in the middle it has full alpha value then it slowly disappears outwards until the water can't be seen at all?

    Any help appreciated.
     
  23. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    The water in that demo consists of three independent waves that are added together. It sound like you've only changed some of them. You can also removing all the waves from the Advanced Ambient Wave Solver component and setup them according to your needs.
    Yes, but you'll have to modify the water shader for this. I've made a quick example based on the water used in DW_Boat scene:
    2014-06-19_00-14-58.jpg
    I've attached the modified shader file. Just use this shader a texture with alpha that fades near the edges.
     

    Attached Files:

  24. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Quick question about non-averaged normals. Right now we have a non-simulated ocean that I'm animating by using the Mesh class with C#, since I need to access the vertex data in sequence. Would it be cheaper to just use your system and an ambient component, since it's heavily optimized? The Mesh class can get kind of expensive for larger meshes.
     
  25. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    It's hard to say without knowing how are you animating the ocean now. The ambient waves components are optimized quite heavily, but there are no miracles - a large Mesh still has the overhead. It's worth giving a try, thought
    P.S. Sorry about the delay with implementing non-averaged normals =/ I'll finish that in a few days.
     
  26. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,291
    Hi

    I have been using a shader with the water that gives me a message

    "Shader wants tangets, but the mesh DynamicWaterMesh doent have them"

    I think this affects the specular or the water, though i am not 100% certain. Is there a reason i get this message ?

    Is there a way to provide the shader the tangets it wants ?

    Thanks

    EDIT: Found it, there was an option to get tangets :), just noticed :)
     
    Last edited: Jun 23, 2014
  27. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Glad you've found it :) Just in case someone else will be having the same problem - when using normal-mapped shaders, you must set tangents by enabling this option:
    2014-06-24_01-47-16.png
     
  28. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,291
    Is there a recommended shader to use if i would like to have reflection + refraction in real time ? Plus the specular highlights that are already there.
     
  29. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    To be honest, I can't recommend any because I usually write my own shaders for specific situations. I have used Tasharen Water and it worked okay, though.
    Also, note that there is an issue with realtime reflections - they look wrong when the waves are really big, that happens because the reflection texture is usually rendered like a mirror, which is not the case for the big waves. It still looks correct when waves are not that big, though.
     
  30. Unititi

    Unititi

    Joined:
    Mar 6, 2013
    Posts:
    20
    When I use Water simple shader I am bumped with erros like that 'syntax error : unexpected token 'triangle'
    Plz help me!
     
  31. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    This should not happen. What platform are you building for? What version of Unity are you using? Also, please try creating a new empty project, importing Dynamic Water System into it and see if it works then.
     
  32. Unititi

    Unititi

    Joined:
    Mar 6, 2013
    Posts:
    20
    Hi zimM. I'm using 4.5 version. And i need to building for android.Samsung galexy s5. and..I tried creating a new project. Still appeared error massage with purple texture... Other textures is ok. only watersimple and watersimple(additive) are don't works..
     
  33. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Yes, I've managed to reproduce the issue, Expect a fix soon.
     
  34. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Try these updated shaders, hopefully they'll work for you now.
     

    Attached Files:

  35. auroxi

    auroxi

    Joined:
    Dec 31, 2012
    Posts:
    85
    This asset is fantastic. I have one question that I could do with an answer on please; I have resized the width and height from the default 20/20 to 100/100. The issue being that now the ripples are much more 'blocky' and not tight to the player (if that makes sense?). It's like the resolution or something needs to be adjusted to match the size of the larger plane.

    I've tried changing the density and messing with every other option visible however nothing seems to change this blocky/low res behaviour.

    The 'Splash Radius' setting on the player is the closest variable I can see to adjust this behaviour. Yet when setting this to 0.000001, it still isn't close enough to the player so it leaves a realistic 'V' trail.

    The same also happens with the SplashZone, the water droplets create 'chunks' instead of small drops.

    Any help is appreciated.
     
    Last edited: Aug 7, 2014
  36. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi there,
    yes, the water is a quad mesh, and it is the size of the quad that defines the "blockiness". When you increase the size of the water plane, the number of quads stays the same, but their size grows, naturally. So you are right that you have to increase the mesh resolution, and the "Quality" parameter controls just that. Be warned that it'll increase resource consumption, though.
    I also have to say that dynamic ripples won't look good either way if you scale the water plane big enough. That's why the Boat demo only has ambient waves - there is just no way to make grid dense enough. Unfortunately, this limitation isn't an easy one to remove, so the best you can do at the moment is crank up the Quality, and hopefully, it'll look better.
    In two words, the smaller the water, and the higher the Quality - the more details can be reproduced.
     
  37. Jack62Lewis

    Jack62Lewis

    Joined:
    Jun 17, 2013
    Posts:
    105
    Hi,
    I found your character ripples code on the first page of this thread. Is there a version of this that works for players that use capsule colliders instead? I tried editing to fit my needs but couldn't get anywhere with it.
    Thanks
     
  38. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi there,
    try the script I've attached. It should work on pretty much any object that has a collider and a non-kinematic rigidbody.
     

    Attached Files:

  39. Imillionaire

    Imillionaire

    Joined:
    Dec 14, 2012
    Posts:
    60
    Is there anyway to put a collider under boats that pushes the water mesh down so that even when there are intense waves, the water doesn't rise over the boat/ship.
     
  40. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Not really, the mesh can't be "pushed down" that easily. It is kind of possible in a quirky way by modifiying the wave function to somehow take boat geometry into account, but that sure won't be easy...
     
  41. Imillionaire

    Imillionaire

    Joined:
    Dec 14, 2012
    Posts:
    60
    is there any easy way to try to prevent water from rising over the ship. i'd like to be able to simulate stormy ocean waves, without them passing through the floor of the boat
     
  42. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Have you seen the included Boat demo? It uses the depth mask technique to prevent waves passing through the floor of the boat already.
     
  43. SpaceCadet

    SpaceCadet

    Joined:
    Jul 29, 2013
    Posts:
    16
    Hi is there a way to change the colour of the water?
     
  44. toxtronyx

    toxtronyx

    Joined:
    Aug 21, 2014
    Posts:
    114
    Hi! The webplayer demos look very impressive. Has anyone tested it with U5? And another question upfront: Is it possible to work with different water meshs in one scene containing different detail options? Lets say I want only one water object that has collision and buoancy etc. and the rest shall only look nice?
     
  45. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Sorry for the really slow reply.
    Sure thing. Just change the Color and Reflection Color material properties. The skybox cubemap also influences the perceived color. Note, though, that Dynamic Water System is mostly a physics/simulation asset, so the included shaders are mostly for demo purposes.
    The current version isn't fully compatible with Unity 5, but I already have an internal updated version that supports Unity 5. I was reluctant to release it because Unity 5 is still in beta and things were prone to change, but I'll probably update the asset quite soon, and definitely before Unity 5 is released.
    Regarding your question - sure thing, as each mesh instance is totally separate, you can setup each instance individually.
     
    toxtronyx likes this.
  46. toxtronyx

    toxtronyx

    Joined:
    Aug 21, 2014
    Posts:
    114
    Sounds perfect for me. I'll probably buy the asset before the end of the year.
     
  47. cjrussel14

    cjrussel14

    Joined:
    Jun 20, 2014
    Posts:
    69
    hey i follow exactly the tutorial in your website but it doesn't work.. im using unity 4.5.5f

    here is my settings : prob2.jpg


    prob1.jpg
     
  48. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    What exactly isn't working? The screenshot looks fine to me, except the Quality of 4 shouldn't be that way. Set it to 200 or something like that.
     
  49. cjrussel14

    cjrussel14

    Joined:
    Jun 20, 2014
    Posts:
    69
    it is just like that when on play mode.. no ripples,movement,etc..i don't know what i missed
     
  50. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    1) I can't see any buoyant object that is supposed to make ripples on your screenshot.
    2) You can't really get dynamic ripples that react to physics on a water plane of that scale. Dynamic ripples only actually work on small water bodies like pools. For a large water body like yours, you have to use a different Solver component (DynamicWaterSolverAmbientSimple, for example). Please see the included Boat demo on how it can be done.