Search Unity

Cocuy - Fluid Simulation for Unity

Discussion in 'Assets and Asset Store' started by Musiu-Bar, Apr 6, 2015.

  1. cparki3

    cparki3

    Joined:
    Jan 13, 2014
    Posts:
    41
    I actually found the issue was simply frame rate related. I had it locked to like 60fps on my dev machine and let it run wild at 300fps on my gaming rig. Basically the effect was finishing so quickly that it looked like it wasn't working. Looks fantastic now. Thanks for following up!
     
  2. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    Oh, great! Glad to know it's working well now! Curious to see what else you do with it, please share some pictures when you get a chance :)
     
    cparki3 likes this.
  3. pgeorges-dpt

    pgeorges-dpt

    Joined:
    Apr 7, 2016
    Posts:
    43
    Hi :) Can your fluid simulation be used on a plane in 3D space?
     
  4. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,526
    So it should work on iOS with metal and OS X now?
     
  5. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,526
    Just bought it because @elbows confirmed it :)

    and here's a screenshot on the Mac :)

    Pragma to 4.5 did the trick
     

    Attached Files:

    elbows likes this.
  6. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,526
    @elbows what was the THREAD_COUNT number you ended up with for iOS?
     
  7. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,526
    I got it to work with #define THREAD_COUNT 8 , but its really a bit slow on Apple TV 4, on iPhone 7 plus runs very fluid
     
    elbows likes this.
  8. Aiden83

    Aiden83

    Joined:
    Dec 12, 2016
    Posts:
    6
    I purchased this asset but can't use it because it does not support multiple colors... everything is based on a unique colors gradient.

    Will you add multiple colors anytime soon?

    If not, is a refund something possible?
     
  9. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    Yes the simulation runs in 2D but it can be applied as a texture to a 3D plane.
     
  10. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    Hi Aiden83,

    Cocuy has support for multiple colours but only one colour ramp per simulation. What kind of multiple colour effect are you looking to do?
     
  11. Aiden83

    Aiden83

    Joined:
    Dec 12, 2016
    Posts:
    6
    I would like to have 2 or more fluids of different colors, like for example a red fluid vs a blue fluid va a green fluid... all 3 interacting with each other. My goal is to make player generating fluid of their own color... I did not see how to do that knowing the fluid surface only have one color gradient applied to all the fluids in simulation.
     
  12. Aiden83

    Aiden83

    Joined:
    Dec 12, 2016
    Posts:
    6
    No news? No answer? Please?
     
  13. Letscoder

    Letscoder

    Joined:
    Aug 13, 2017
    Posts:
    3
    Hello! Could you tell me which settings you have used in Android apk demo?
    I've got slide show when tried to launch this scene in my build.
     
  14. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    Hi,

    Ok, I understand what you're trying to do. We are working on supporting several colors within the same simulation. How would you envision it working when two (or three in your example) colored fluids mix? I ask to get a better understanding of what you guys are trying to do and make sure what we're doing is useful in the end.

    Thanks
     
  15. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    Hi Letscoder,

    What settings do you mean? Settings for the build or for Cocuy?
     
  16. Gontz

    Gontz

    Joined:
    Oct 27, 2016
    Posts:
    11
    Hello,
    Any news regarding the colours mix support in the same simulation? We want to use cocuy to simulate how colours interact with each other.

    When do you think the update will come?

    Thanks
     
  17. Letscoder

    Letscoder

    Joined:
    Aug 13, 2017
    Posts:
    3
    Them both.
    In ocassion with Android Build I have that:

    upload_2017-8-15_18-27-5.png

    Quality settings

    upload_2017-8-15_18-28-17.png


    I am using Unity 2017.1.0f3.Project with only asset imported.

    With default demo Mid settings(Fluid Simulator) I have around ~10 fps on three devices + artifacts(Google Pixel XL Android 7.1; Samsung Galaxy S7 Edge Android 6.0; Xiaomi Redmi Note 2 Android 5.0).If I choose Low or High preset, fluid is not simulated at all.Simulate Quality change has no influence on work.

    upload_2017-8-15_18-29-8.png

    I've also tried all Unity 5.x versions from 5.0.2, but only 5.5.3 works(with artifacts), though perfomance is also quiet awful(~20).

    Link to Google Drive with apk
     

    Attached Files:

  18. Aiden83

    Aiden83

    Joined:
    Dec 12, 2016
    Posts:
    6
    I want all colors to mix if they should mix, like colored gas. The role of Cocuy in my game is mainly aesthetic and do not impact gameplay but we could easily imagine some games (or a future development of my current game) with the possibility to get the % of each colored fluids in simulation or at least the % of the 3 RGB components.

    Will the multiple colored fluids be supported? And if so, what ETA?
     
  19. Wolk

    Wolk

    Joined:
    Jul 12, 2014
    Posts:
    59
    Hello, any idea how to make a negative pressure area. Eg, i want the fluid to flow into a confined object (when there's an opening)
     
  20. shinyu83

    shinyu83

    Joined:
    May 8, 2017
    Posts:
    1
    Last edited: Aug 29, 2017
  21. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    @Letscoder
    Could you send us your email address (via DM or to our email address) so we can talk better directly to find what's going on with your build?

    @Aiden83
    We've made some progress with the mixing of colours and sent you a private message about it.

    @Wolk
    It's not part of Cocuy, but you could create a script that modifies the underlying velocities so that they all point towards a particular point. A point to start would be the Velocity Manipulator and AddVelocity function of the FluidSimulator script. However, I'd suggest you create a new kernel function inside the Compute Shader (Cocuy_Simulation.compute) so you can modify all the velocities with only one call to the shader, similar to the AddVelocity kernel.

    @shinyu83
    We've emailed you how to remove the problems you're having.
     
  22. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    Hi all!

    A couple of weeks ago we uploaded a new version of Cocuy that fixes that problem a few of you were having where the fluid would "explode" when changing the velocities near the edges of the simulation. (@juuuuun I believe you were having this issue?).

    Also in that version we added tweak to the Thread Count to support iOS/Metal! As usual let us know if you have any issues!

    Cheers!
     
  23. Halograph

    Halograph

    Joined:
    Jun 26, 2017
    Posts:
    1
    Hi,

    1. Is it possible to merge two fluid entities?

    Imagine two suns in space, they get near each other, start to eat on each other until they merge to a black hole.
    Something like this:

    The result would be a new fluid of defined size.


    2. Also the opposit effect would be of big interessed to me. So you seperate an entity into two.

    3. Is it possible to make the fluid react to a "magnet"? Like smoke gets sucked into a vent?

    Thanks!
     
  24. nsfnotthrowingaway

    nsfnotthrowingaway

    Joined:
    Feb 18, 2016
    Posts:
    48
    Does this work on console? (PS4, XBox One, Switch)
    I know they support compute shaders, but I keep seeing Windows only, and DX11.
     
  25. planetmatrix

    planetmatrix

    Joined:
    Dec 8, 2015
    Posts:
    38
    Hi, Can this be achieved with Cocuy?
     
  26. Nrjwolf

    Nrjwolf

    Joined:
    Mar 2, 2014
    Posts:
    4

    Still can't play it for android build, what's wrong? I have updated.
    nrjwolf@gmail.com
     
  27. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,664
    Cocuy needs Compute Shaders and your target Hardware might not support them. More informations here:
    https://docs.unity3d.com/Manual/ComputeShaders.html

    If you're unsure if your device supports Compute Shaders, use SystemInfo.supportsComputeShaders to check first.
    1. Create an empty Scene, add a "UI Text" (GameObject > UI > Text) and make the element a bit larger in width (Rect Transform > Width)
    2. Paste the following code into a C# script called SystemInfo.cs:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class SystemInfo : MonoBehaviour {

    public static bool supportsComputeShaders;
    public Text CSAvailability;

    void Start () {
    CSAvailability.text = "[Compute Shader supported?] " + SystemInfo.supportsComputeShaders;
    }

    }

    3. Attach the script onto the Main Camera or an empty GameObject - it doesn't matter
    4. Drag & drop the Text GameObject into the "CS Availability" field in the script.
    5. Now, make a test build for your device and run that build on your device (!)

    Should the text say "[Compute Shader supported?] False", then your device doesn't support Compute Shaders.
     
    Last edited: Nov 26, 2017
  28. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    Hi @Halograph ,

    1 and 2. That kind of effect seems very specific. You'd have to play around with different particle and velocity manipulators to get something like that. In the promotional video there's something slightly similar with the sun-like objects that interact with each other, have a look at it here:
    .

    3. Cocuy doesn't come with that specific behaviour out of the box, but you could create your own velocity manipulator to make the particles all flow inwards towards a particular point.

    Hi @sagarkar,
    That's exactly the kind of movement Cocuy simulates! But remember it only does a 2D simulation. Have a look at the screenshots and video in the asset store page (link) to see how that looks like.

    Hi @nsfnotthrowingaway,
    It does work on consoles as they support Compute Shaders (check this link for supported platforms: link)
     
  29. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    Thanks @Mauri :)

    @Nrjwolf, as was said, it seems your Android version doesn't support compute shaders :(. In addition to what Mauri recommend, you can have a look at the supported platforms here
     
  30. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    Hi All!

    Just wanted to announce that starting today Cocuy is On Sale for 25% Off!
    The offer is part of the Asset Store's Mega Sale! Valid until December 8th!
     
  31. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,664
    You're welcome :) I hope this helps, Nrjwolf *crossing fingers*
     
  32. Deleted User

    Deleted User

    Guest

    Beautiful simulation! I'm trying to use it with a dynamic collider and Polygon Blocker script. I added this line:
    Code (CSharp):
    1. m_collider = GetComponent<PolygonCollider2D>();
    In BlockFluid(), to refresh the shape of the collider.

    Otherwise it wouldn't update the collider shape. The problem now is that the fluid seems to be approximating the collision in some places, while following the collider very closely in others. Screenshot of what I'm seeing attached. You can see that the fluid is tight against the collider to the right of the image and up top, but is cut off diagonally as it moves further down into gap.

    The effect I'm after is a dynamic 2D terrain, which the player can shape to direct rivers. I'm open to other solutions too.
     

    Attached Files:

    Musiu-Bar likes this.
  33. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    Hey @Cherdyakov,

    That probably has to do with "Static" obstacles. In your case they need to be dynamic. Let me get back to you tomorrow to show you how to get around it.
    Thanks!
     
    Deleted User likes this.
  34. Musiu-Bar

    Musiu-Bar

    Joined:
    Apr 6, 2015
    Posts:
    58
    @Cherdyakov I had misread what you had posted before. The issue is that you have concave polygons which weren't supported by Cocuy. However, I just coded a solution for the polygon blocker to add that functionality! I still want to run some more tests and then submit it to the asset store. If you want it sooner, send me an email or PM and I can send you a preview :)

    Thanks again!
     
    Deleted User and Inspeinre like this.
  35. Deleted User

    Deleted User

    Guest

    That's great! I can work on other things for now, I'll be in touch if I need it before you update on the asset store though. Thanks a bunch.
     
  36. FunkyFancy

    FunkyFancy

    Joined:
    Nov 23, 2016
    Posts:
    9
    Hello :) I'm also interested in your build settings and the settings of the simulation from your android demo like @Letscoder.
    On my Google Pixel 2 XL your demo run's very smooth but the Touch demo from your asset is a bit laggy in my build :/
    When i used custom settings i ended up with 2 - 14 fps :D

    Btw. it's a realy cool asset! Thanks for that :)
     
  37. dmind

    dmind

    Joined:
    Jan 13, 2016
    Posts:
    1
    can i use this assets to shake and mix a image texture? like a image filter..

    it seem to not be... Or, can each particle have each a color?
     
  38. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    Awesome asset! Now with the Compute Shader support, I'm integrating this into a game we're releasing on PC / Mac and Consoles. I just made a test build for PlayStation 4, however I found that it doesn't render at all on that platform. Usually with shaders on PS4, it spits out errors if they don't work, but in this case literally 'nothing happens'. No errors, no warnings, nothing. Based on https://docs.unity3d.com/Manual/ComputeShaders.html the PS4 should be a supported platform for compute shaders.

    Could you please advise on how to set this up properly to work there?

    Thank you!!
     
  39. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    NOTE: Realized I should have included this info as well - the fluid simulation zone appears as transparent on PlayStation 4. There is no 'pink error shader' displayed. So it seems like maybe it's there but for some reason the fluid simulation is just not running or something?
     
  40. FunkyFancy

    FunkyFancy

    Joined:
    Nov 23, 2016
    Posts:
    9
    I just wanted to include Cocuy in an AssetBundle but i'm getting a few errors. Or isn't it possible to load compute shaders from an AssetBundle?
    upload_2017-12-10_20-21-43.png

    EDIT: Okay i only forgot to build the bundles also for standalone and enabling "Require ES3.1" for Android fixed mobile render issues :rolleyes:
     
    Last edited: Dec 10, 2017
  41. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    MORE INFO!

    I found there actually are 2 errors occurring (I didn't catch them before due to my build settings). The errors I get on PlayStation 4 are...

    Code (csharp):
    1.  
    2. Shader error in 'Cocuy_ParticleArea.compute': All kernels must use same constant buffer layouts; '_ParticleSize' property found to be different
    3.  
    4. Shader error in 'Cocuy_Simulation.compute': All kernels must use same constant buffer layouts; '_Static' property found to be different
    5.  
     
  42. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    AH! It was a but in Unity's plugin. We got it fixed. For anyone else trying to get this to work on PS4 and getting this issue, search the PS4 forums for the error and you'll fine the resolution!
     
  43. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    And now that I've gotten past all of THAT.... I've found the asset to be absolutely unusable. Which makes me extremely sad.

    I am running Unity 2017.2.0p4 on Windows 10.

    1.) The prefab mentioned in the documentation does not actually work. Add it to a scene, follow the instructions, and nothing happens. No warnings, no errors, no nothing. Just... nothing happens.
    2.) The only way I have found to get a working fluid sim is to copy / paste it from one of the Demo scenes.
    3.) None of the code is namespaced.
    4.) When multiple fluid simulations are in the same scene, a bug will prevent all but one from working correctly. To fix the bug, you have to change the Area Resolution on the Particles Area component at runtime to be a different value. This seems to reset the component and the simulation begins to function..... BUT....
    5.) When you change that Area Resolution on one Particle Area, the OTHER Particle Areas will break their rendering. This means you can only realistically have one Fluid Sim in a single scene (which is... confusing... as one of their Demo Scenes has multiple. But trying to build this yourself does not seem to work right. (Below image shows what happens to other particle simulations when you change the resolution on a different one. The one on the right originally was not playing at all at runtime, however the one on the left was playing. So I changed the area resolution on the one on the right, and the one on the left then broke and started rendering as shown in the image).

    upload_2017-12-14_13-7-46.png


    I would LOVE LOVE LOVE to be able to use this asset in our game, if we can get these issues resolved. I would even be happy to help fix them if that's needed!
     
    hopeful likes this.
  44. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422

    Ok, so one major element figured out - the X and Z sizes of all Fluid Simulators in your scene _MUST_ be exactly the same. If any of them are different, you'll get the issue I posted the screenshot of above.
     
    hopeful likes this.
  45. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,526
    good to see you finding solutions
     
  46. FunkyFancy

    FunkyFancy

    Joined:
    Nov 23, 2016
    Posts:
    9
    @RedVonix oh i got the same problem with the multiple simulations, thanks for figuring out :)

    I noticed that the Fluid PolygonCollider only works when the whole collider is inside of the simulation area. Just a little corner outside and it doesn't work :D
    It took me some hours to figure that out :'D
     
    hopeful and RedVonix like this.
  47. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    Ok, so next problem. If you Disable an object that has the Fluid Simulator on it, then Re-Enable it, you absolutely break things. You'll get spammed with this bug coming from a bunch of different places in the Cocuy code:

    Code (csharp):
    1.  
    2. NullReferenceException: GetRef
    3. UnityEngine.ComputeShader.SetBuffer (Int32 kernelIndex, System.String name, UnityEngine.ComputeBuffer buffer) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/ComputeShaderBindings.gen.cs:129)
    4. ParticlesArea.Update () (at Assets/Plugins/Cocuy/Scripts/ParticlesArea.cs:208)
    5.  
    I've done some basic looking into it so far, and it looks like the simulation does not cleanly shut down and restart. Trying to code a fix for that, but could really use some help from the developers.
     
    FunkyFancy and hopeful like this.
  48. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    Posted in the main Unity shader forums for help. Link below for anyone else stuck on this issue:
    https://forum.unity.com/threads/dis...-computeshader-breaks-the-shader-help.508944/
     
    FunkyFancy likes this.
  49. FunkyFancy

    FunkyFancy

    Joined:
    Nov 23, 2016
    Posts:
    9
    Maybe we should make a summary with something like google docs for all the hints / problems / tricks we are discovering :D
     
    RedVonix likes this.
  50. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    I have the suspicion this asset has never actually been used in a game before... A lot of these feel like the kind of bugs I'll personally find when I write a new tool then do a series of unit tests to debug it.
     
    sbtp, hopeful and FunkyFancy like this.