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. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Sorry, unfortunately you can't do that out of the box, as using obstruction objects/textures includes quite a lot of precalculations done on the CPU. But what you do can do, however, is directly update the obstruction array, which would be a lot like using a dynamic obstruction texture.
    Basically, you create a new C# class that inherits DynamicWaterSolverSimulation (or any solver you use). Then, in StepSimulation() simulation you update the FieldObstruction field with your values. FieldObstruction is a byte[] where value of 0 corresponds to a grid node being fully obstructed, and value of 255 means no obstruction. Refer to documentation and included Solver scripts for examples.
    Feel free to PM if you have any problems implementing this.
     
  2. sloopidoopi

    sloopidoopi

    Joined:
    Jan 2, 2010
    Posts:
    244
    Thanks for the quick response. Good to know thath it's in general possible. Did you thought about implementing a dynamic solution for the assetstore? Before hacking something together I always prefer to have a solution right in the official asset-store version from the main developer ;)
     
  3. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    The problem is, it's not really possible in general. Unfortunately, I don't know about any good solutions for implementing obstructions in a generic way that'd fit all (or at least most) use-cases. If there ever was one - it'd probably already be implemented :) Even very advanced and expensive water simulation systems have a lot of trouble with that. That's why I made it possible to easily extend the system - that allows you to adapt it to your exact situation, if possible.
     
  4. sloopidoopi

    sloopidoopi

    Joined:
    Jan 2, 2010
    Posts:
    244
    Ok, I see. Another question: Can I propagate ripples with touch input or is it only with mouse input?
     
  5. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    You can do touch as well. Actually, the included demo script supports touch, you can test the demo .apk on a Android device.
     
  6. sloopidoopi

    sloopidoopi

    Joined:
    Jan 2, 2010
    Posts:
    244
    Ok, bought it! (With this fast customer support I can't resist :D )
     
  7. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hi ZimM,

    I wonder if there is a way to make a smooth transition between planes ? I mean say putting side by side 64x64 planes and activating calculation on demand preserving waves connections (for performances reason). Of course far planes would be hidded by any way.

    Thanks !
    David.
     
    Last edited: Nov 22, 2013
  8. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hmm, I haven't thought about it. I'm pretty sure it is possible with some coding work, but that'd at least eat quite a lot of memory, which may not be good for mobile. I wonder what effect do you want to achieve? Basically, a very huge dynamic water plane?
     
  9. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    It would be used to make a racing game, so i would not really need a huge environment, but maybe 30/50 meter in front (then the rest hidden by fog or anything with buoyancy/calculation deactivated) and 10/20 meters wide.

    I would target high end devices, i don't think performances would be the problem, but correct transitions from planes to planes would be needed. That said i didn't tough the system was high on memory, what would be the cause then ?

    Thanks !
     
    Last edited: Nov 22, 2013
  10. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    I see. Well, it is not currently possible out of the box, but I like the idea, so I'll try to add this for an update :) Can't give any ETA, though.
     
  11. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Cool !

    No problem, i have a game to update before which may take a lot of time, but then it could be my next project :)

    Thanks for the answers,
    David.
     
  12. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    This would be a weird usage, but do you think this could be adapted for flowing snow? (something kinda like the sand in Journey)
     
  13. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    I think yes, but it's really not worth it, as that'd probably eat enormous amounts of memory and CPU power... From what I've seen, the sand in Journey is much simpler.
     
  14. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Indeed, Journey's sand surface is modelled as a polygon surface then subdivided into a finer mesh guided by splines at runtime and deformed locally. Not much simulation and wotnot going on there
     
  15. leuchtfeuer

    leuchtfeuer

    Joined:
    Jan 9, 2014
    Posts:
    5
    Hi,
    Can i combine this water with simple water physics and how performant is it on mobile devices when i have many water and also complete oceans? I have a block system in my game what happens when i place 1 water block next to a other waterblock will they combine?
     
    Last edited: Jan 10, 2014
  16. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    1) Water buoyancy physics are already included with the asset, but you can use any solution you want without problem.
    2) That depends on what you are trying to achieve. If you are using interactive ripple simulation - you can have as many water bodies as you want, but interacting with more than one of them simultaneously would crawl on mobile. Oceans are pretty much out of luck. Also note that included water shaders are not really well-optimized for mobile, they are mostly for demo purposes.
    3) No, water planes don't combine automatically. You can always do that yourself, though, but on doing that in runtime on mobile would probably be slow too. This asset is more optimized for rare updates.
     
  17. Elit3d

    Elit3d

    Joined:
    Jan 25, 2014
    Posts:
    21
    Is there a way to make it work with first person?
     
  18. ZimM

    ZimM

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

    I assume you want to get the underwater fog and character ripples? The setup is exactly the same as with the third person demo. If you are are using the standard First Person Controller, do the following:
    1) Add DW_CharacterRipples script to the First Person Controller object.
    2) Add UnderwaterFog script to the "Main Camera" object that is child of First Person Controller object.

    I've just did a quick test and that worked for me.
    Hope this helps.
     
  19. Elit3d

    Elit3d

    Joined:
    Jan 25, 2014
    Posts:
    21
    didnt seem to work. I got this so far:

    http://gyazo.com/17736e86c7418ea5d95e5636d6a1a8c7
     
  20. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Well, this is slightly odd, and seems like it has something to do with the scene setup... Please check the following:
    1) Is the Character Controller collider really touching the water surface? Probably the Skin Width is too high.
    2) Does the DynamicWater object has "DynamicWater" tag?
    3) The setting the Splash Force to something really big like 1000. Probably your scene has somewhat different scale.
    It's really hard to tell what's the problem here without the actual scene. Could you please make a screenshot of your scene? Or it would be even better if you make a simple scene that reproduces the problem and send it to me - in that case I'll be able to find a solution much quicker without making guesses.

    Best wishes
     
  21. Elit3d

    Elit3d

    Joined:
    Jan 25, 2014
    Posts:
    21
    Got it working, all I did was move the water up slightly! Weird. Thanks for the help sir!
     
  22. Elit3d

    Elit3d

    Joined:
    Jan 25, 2014
    Posts:
    21
    another question is there a way to make it so that when the water brushes up shore it creates a foamy effect just like the beach and will play a sound?
     
  23. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Unfortunately, it is not possible at the moment by using this asset only. It is, however, possible by using a third-party shader. See webplayer demo for a scene with Tasharen Water. I can't guarantee that every shader will work, but it is not impossible.

    $foam.jpg
     
  24. Elit3d

    Elit3d

    Joined:
    Jan 25, 2014
    Posts:
    21
    Awesome thanks!
     
  25. ValrikRobot

    ValrikRobot

    Joined:
    Jun 26, 2013
    Posts:
    206
    Hi, great water system. Im just trying to find out if its possible to use this
    system on different shapes of water. Still planes just with squares cut out of
    it. $water.jpg

    So I could generate a mesh, all on one plane but with bits cut off it as it were
     
  26. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Sorry for slow reply, was really busy yesterday.

    Only rectangular meshes are supported, but it is possible to achieve what you want by clever usage of obstruction array and a special shader. Something similar is done in Obstruction Geometry demo scene - a special shader does not renders parts of the water that are obstructed, and obstruction field is generated from a texture. The shader used in that demo is "Water Reflective Simple (Obstruction Alpha)", it is commented, so you can start from it. What you'll have to do is to programmatically generate an obstruction field array according to your configuration and set it to FieldObstruction property of the simulation solver (documentation link). Or just use an obstruction texture if you don't need the shape to change.
     
    Last edited: Mar 6, 2014
  27. Mayalicious

    Mayalicious

    Joined:
    Feb 21, 2014
    Posts:
    12
    I have a custom sink model that i modeled. I want to put the water inside this sink. How can i do that? Anybody can help me? Thanks.
     
  28. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi there.
    What exactly are you having problem with? Just create a DynamicWater object and put it in your sink to fit the model.
     
  29. Mayalicious

    Mayalicious

    Joined:
    Feb 21, 2014
    Posts:
    12
    How will i fit it to my custom sink model? My sink model is oval. Dynamic water object is cube shaped.

    It looks like this. $water.jpg

    Also do i need to apply my own water shader?
     
    Last edited: Mar 18, 2014
  30. Mayalicious

    Mayalicious

    Joined:
    Feb 21, 2014
    Posts:
    12
    ZimM can you help please?
     
  31. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Ah, I see. In that case you'll have to use obstruction geometry and a special shader that doesn't draws the occluded parts of water plane. See "Obstruction geometry" demo for exactly that.You have two options: use other model as obstruction geometry that will match the shape, or draw a corresponding obstruction texture.
     
  32. Mayalicious

    Mayalicious

    Joined:
    Feb 21, 2014
    Posts:
    12
    No mate it does not work. Here is the strange and ugly result. As you can see obstruction doesnt work also my waves are very strange. Water makes crazy movements all the time. What i am doing wrong?

    $waterProblem.jpg
     

    Attached Files:

  33. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    The obstruction system does work, but it may be a little tricky to setup. In your case, the easiest way is probably to make an obstruction texture and apply it to the water plane with "Bake obstruction data into mesh" checked. I've made a simple scene to help you, see the attached package and the screenshot.
    $2014-03-20_00-34-25.jpg
    As for the weird waves - how are interacting with the water? If you are using the included DW_MouseSplash script, then this means your scene is not up to scale with the default values of that script. Try changing Splash Force and Splash Radius fields to something smaller.
     

    Attached Files:

  34. Mayalicious

    Mayalicious

    Joined:
    Feb 21, 2014
    Posts:
    12
    Thank you very much. I solved the strange wave issue like you said. But i still dont understand obsructure texture system. The sink that you made for demo is not a perfect circle. Its oval shaped. But your texture is perfect circle. How does it work? I used your obstructure texture on my sink model but it still doesnt hide the party that i dont want very well. Also last question is there a possibility to use realtime reflection in the water?
     
  35. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    The obstruction texture is stretched across the water plane. The water plane is of non-square shape - it is rectangular, so the circle is stretched to look like oval. Because of this, it may be a bit tricky to adapt the obstruction texture to the shape of your sink, but it is still possible (a simple way is to take a screenshot of your sink, create a b/w mask from it and then stretch the image to fit a square shape). Real-time reflections are possible, but not included in the asset - unfortunately, I can't implement them at the moment, as I don't have Unity Pro. A way to solve this problem is to use some third-party water shader that has realtime reflection and then adapt it to add support for obstruction textures, but that obviously requires some shader coding work, which may be not-so-trivial.
     
  36. Sam-K

    Sam-K

    Joined:
    Mar 23, 2013
    Posts:
    27
    Hi, I'm making a boat simulation. Basically what i need is the boat to interact with water like when the boat moves on water in makes ripples or water is pushed away that kinda effect. Is this possible ?
    the effect you have in pool scene when we swipe on water with finger or mouse thats all what i need to be integated with the boat scenes water.
    Is there any work around like if we could place multiple pool scene water side by side or add the interaction freature in boat scene water.
     
  37. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Hi there,
    sorry for slow reply. The dynamic ripples effect doesn't actually scales good for big water bodies. It'd probably be fine on PC, but not on mobile. In any case - that feature is planned and actually partially implemented, but there is currently no workaround, sorry :(
     
  38. jason-fisher

    jason-fisher

    Joined:
    Mar 19, 2014
    Posts:
    133
    Is it possible to define a 3D grid with a profile like this and have the water fill the space properly?

    X = obstruction
    ~ = water
    empty = air


    XX~~~~~~XX
    XX~~~~~~XX
    XX XXXXXX
    XX XX
    XXXXXX XX
    XX XX
    XXXXXXXXXX
     
  39. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Unfortunately, Dynamic Water simulates only the water plane, thus it has no solution for simulating the water flow in 3D.
     
  40. Deathnote

    Deathnote

    Joined:
    Nov 26, 2013
    Posts:
    52
    can i used my costum water shader with Dynamic Water system?
     
  41. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,286
    I have one small issue, to get a good effect on my pool, i have set the power high and while the ripples are great, near the hero that has the component to create them i get a big spike, that goes over the hero head

    Is there a way to determine a max height of the ripple ?
     
  42. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    @Deathnote
    Yes, you can easy pretty much any custom shader you have.

    @nasos_333
    That's a rare situation. Maybe you can try increasing the radius of the splash a little bit and decreasing the force? That usually helps.
    There is no height limit option, but if you really need it, look in DynamicWaterSolverHeightmap.cs for the following line:
    Code (csharp):
    1. field[index] += drop * force;
    so you can hack it like
    Code (csharp):
    1. field[index] += Mathf.Min(drop * force, 5f);
     
    Last edited: Aug 28, 2014
  43. Sam-K

    Sam-K

    Joined:
    Mar 23, 2013
    Posts:
    27
    HI ZIM,
    Im using your plugin. It works fine with the boat provided in demo . but when i use my custom boat they behave strange. Their movements are distorted.
    Can you tell me the proper steps to setup my custom boat to make it work like yours.
    Or It will work only with the boat provided ? I tried to adjust the fields in inspector for the buyoyancy force script and other.
    I know it has to do with colliders but i have tried a lot and it didnt work. As there is no proper documentation so I need your help in this.
     
  44. ZimM

    ZimM

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

    how exactly is the movement distorted? Can you show a screenshot of your boat inspector? The buoyancy works with any model. Basically, you'll need to have a collider set to your boat object (for a boat it will be a Mesh Collider most likely) and a Buoyancy Force component. Then, try setting the Quality slider in Buoyancy Force component to a maximum value - there is a chance that there is not enough buoyancy voxels generated. Also try just using the boat object from the demo scene, replacing the model with our own and see how it works then.

    -Serhii
     

    Attached Files:

  45. Sam-K

    Sam-K

    Joined:
    Mar 23, 2013
    Posts:
    27
    Mesh doesnt works but box does. I already did this.
    Its definitely an issue on the colliders end and some field values.
    Anyways heres an image from my scene.
    $Screen Shot 2014-04-18 at 11.21.29 AM.png

    I want a motor boat like behaviour. But it is behaves like the boat in the demo scene. which is effected alot by the waves. What i mean by this is when i accelerate the boat it moves in forward direction and then starts coming back like with the waves for 1 secs and then moves forward again. So a to and fro motion.
    Previously the quality settings value was 12 but now i changed it to max 15. It was working before too.
     
  46. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    This is odd. Are you using the latest version of Dynamic Water? I remember fixing some boat-related bugs there... I can't reproduce "moving backwards" behaviour in the included demo scene. Even when boat controls are not touched, it stays fixed in the same XZ position, except the obvious Y change by the waves (and not going backwards in any case). Could you please make a simple reproduction scene and PM it to me so I can examine the source of the problem?
     
  47. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    I was wondering if it'd be possible to add a toggle option to not average normals when calculating the normals. I still want normals on my water mesh, but I don't want them averaged, just faceted essentially.

    I want to do this in code, but I see you have a compiled Android library (which I appreciate!) and so I figured it might better to just request this and get a new version of the plug-in instead of doing it myself and being locked to C# only.
     
  48. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    It is doable, but this is a bit more work than just not-averaging the normals. In the current version, water mesh triangles actually share vertices, so in order to achieve a faceted look each vertex has to duplicated. That will lead to reduced maximum mesh resolution, but I guess it is not a problem since you want a faceted look anyway :)

    So yeah, I think I'll include that in an update. Can't really tell any ETA, though - awfully busy for at least a month :/
     
  49. jf3000

    jf3000

    Joined:
    Dec 31, 2013
    Posts:
    166
    Gee not even real water, gI go under and I see the land, fake water, disappointed.
     
  50. ZimM

    ZimM

    Joined:
    Dec 24, 2012
    Posts:
    963
    Sorry to hear it doesn't fits your needs. What do you mean under "not real water"? Dynamic Water System is designed, first of all, as physics and simulation asset.
    Regarding seeing the land when submerged - have you checked the UnderwaterFog script that serves exactly that need? Basically, just drop it on your camera and you're done. You can see that effect in action in Character demo scene.
    That said, if you really don't like it - PM me and I'll be happy to issue a refund for you.

    Best,
    - Serhii