Search Unity

Physics [RELEASED] FluXY, eulerian GPU fluid simulator

Discussion in 'Tools In Progress' started by arkano22, Aug 4, 2021.

  1. cftcimert

    cftcimert

    Joined:
    Apr 4, 2018
    Posts:
    14
    Hi, when i use custom mesh in container, problem occurs. Target is not painting the container properly.
     
  2. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Hi,

    What do you mean the target is not painting “properly”? Could you share an example of this?

    Make sure your mesh has valid, non-overlapping UV coordinates. Fluxy works in texture space, so if your mesh’s UVs are incorrect so will the results.

    Please use the FluXY support email for further support requests.
     
  3. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281

    hi @arkano22 I just port this smoke from the smoke ring scene, and put 2 targets on the character's feet.
    I really like the left and right running effect, but the run toward / backward is really not satisfying.
    What can I do to make it right ?
    The run toward camera has too much smoke, and the run away from camera has nearly no smoke.
    I know Fluxy is projecting so toward/backward camera view will has issue. I just wanna see if there is way to go around this issue.

    Right now the temp solution is making the container looking at the camera, but angle a bit, by using a pivot child of camera (offset Position (0,-3.5,0) and look at that instead of the camera.
     
  4. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929

    Hi!

    Please write to the support email next time, It's easy to miss messages on the forum!

    Your temp solution is fine, another option would be to modify the velocity of the target based on the direction the character is running towards relative to the camera. (you can use a dot product between the camera's forward vector and the character's running direction to get a measure of this) Make the velocity smaller when the character is running towards the camera, and bigger when it's running away from it, that should help a bit. You can combine this with your current approach too.
     
    Spikebor likes this.
  5. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    I like that approach, thank you!
     
  6. Gustav

    Gustav

    Joined:
    Jun 10, 2013
    Posts:
    2

    Attached Files:

    blueivy and arkano22 like this.
  7. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    That's really, really cool! Thanks to you for using FluXY, and for sharing the work you've done with it :D
     
  8. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Just purchased this awesome looking asset but quite a few of the samples give errors, the player script gives error at runtime:

    NullReferenceException: Object reference not set to an instance of an object
    FluxySamples.SampleCharacterController.Update () (at Assets/Obi/Samples/Common/SampleResources/Scripts/CharacterController/SampleCharacterController.cs:67)

    I am on v2019.4.24f1

    Also some of the scenes have pink materials, all the URP ones:
    upload_2022-11-17_22-28-48.png
    Must I change something to get these working?

    Also, can you help me find the scene for this one:
    upload_2022-11-17_22-29-45.png
    I am really keen to try this for an offroad car game I am working on.

    Thanks!
     
    Last edited: Nov 17, 2022
  9. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Hi!

    Fluxy is only compatible with Unity 2019.4.30 or above, as stated in the store.

    I was unable to reproduce the null ref exception in the PlayerController, will try a lower Unity version to see if that has something to do with it.

    Regarding the URP scenes, these are designed to work with URP (as the name implies) so naturally if you’re using BIRP none of the shaders in these scenes will compile.

    let me know if I can be of further help,

    kind regards,
     
    khos likes this.
  10. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Wow, thanks for your quick reply!
    I just tested in version 2022 and the script error is not seen, I suspect it must be the Unity 2019 version I am on, Arrgg, I prefer not to upgrade that massive project to a new version just now. Maybe I can live without the player script.

    I am testing by installing URP, LOL, I did not realise I had to install the packages etc, what a newbie mistake. That works now.
     
    Last edited: Nov 17, 2022
  11. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    The player script is only used in the sample scenes, I haven't tested the actual simulation in older Unity versions but it *should* work for the most part (even in a not officially supported version) as it's just a vanilla fragment/vertex shader. If fluids do their thing in scenes that don't involve the humanoid player, I think it's safe to say it all works correctly.

    cheers!
     
    khos likes this.
  12. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    I love your asset, it is a pity as I have a large project that is not on URP and have to update to make use of the URP features that I really would like :) That could be big task and other assets might not work well. I know it is a long shot, is it possible to get a non-URP version of the other/all scenes/features?

    P.S. I own all your other assets, really nice ones! :)
     
  13. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Hi!

    FluXY 1.4 has just been published, this is a free update that includes flip book recording tools. Now you're able to take any container simulation and record it to a flipbook animation, which is a commonly requested feature.

    • Record and preview multiple takes in-editor.
    • Save flip book textures and fully setup materials.
    • Support for seamlessly looping animations.
    • Support for motion-vector based frame interpolation.
    • Included flip book playback shaders (raw and interpolated variants) compatible with all render pipelines.



    As always, suggestions/feedback are most welcome. Hope you find it useful!
     
    Last edited: Nov 30, 2022
    khos, adventurefan and florianBrn like this.
  14. The11thAlchemist

    The11thAlchemist

    Joined:
    Aug 10, 2020
    Posts:
    30
    Hello, Just making a suggestion. I've been reading through the forum and you suggest to send questions via email but I think it is better that it is on the forum. Many of us have run into the same problems and a simple search through the forum can resolve our issues. It isn't efficient to help only one person through email when you could help dozens/hundreds from a forum post.
     
  15. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Hi!

    While I agree that forums are a better platform for support, validating user invoices in the Unity forum is not possible/practical so using it is out of the question.

    Building, hosting and maintaining a custom-built forum where users can be easily validated, threads organized into subforums, etc adds a lot of extra work that is only justified if the volume of support requests exceeds a certain threshold. I did this for another asset of mine (Obi) that gets around 10-20 support requests per week, so it makes sense to build a community around it and gather knowledge in one place: in a few years, several thousand threads have been created on these forums.

    FluXY on the other hand rarely goes over 1 request per month and so far haven't identified recurrent/frequent questions (they seem to be of a wildly different nature), so for the time being it's just more efficient to answer them on an individual basis.

    If it ever gets to the point that FluXY reaches a significant volume of support requests, I will also create a forum specifically for it.

    Thanks for the suggestion! :)
     
    Last edited: Feb 21, 2023
  16. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    Wow Fluxy is so good, I wonder why it does not get much request (i.e people rarely use it?)

    I'm on my way to implement water for my game using Fluxy
    It's beautiful as is. Now I just want to use the Readback demo to implement spawning particle at character feet if velocity is at some value.

    upload_2023-2-25_17-54-36.png

    I notice there is lots of demo, but none is about spawning particle effect using readback. Is it hard to do?
    I call

    Code (CSharp):
    1. velocity = container.GetVelocityAt(transform.position);
    2.             density = container.GetDensityAt(transform.position);
    to update those 2 values at character feet, but there only density read. Why there is no velocity?

    upload_2023-2-25_17-55-33.png

    In the Solver I did set to readable everything tho

    upload_2023-2-25_17-58-22.png

    I hope more people using this tool.
     
  17. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    Update
    sorry I think I code it wrong and didn't save the file
    I managed to spawn based on the horizontal velocity mag if it is >4.
    upload_2023-2-25_18-35-39.png

    But now another problem is I can't detect character jump to spawn vertical water splash effect.
    The Velocity Y is always zero.
     
  18. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    Update 2
    ^w^
    I figure I won't need Fluxy's sample velocity to use this effect.
    For moving splash I spawn using character's current velocity.
    For jumping and landing splash I spawn using character controller's jump and land event
    both effects only need one thing from Fluxy, that is the status of "touching water" or not. That is handled by a Target Provider when provide character's Fluxy target, also mark character as "in water". And all is done.
     
    khos likes this.
  19. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    That looks stunning, Spikebor! great work. I didn't even get to help with the problem, you solved it yourself :D.

    let me know if I can be of any assistance.
     
    Spikebor likes this.
  20. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Hi, hopefully it would be ok to ask, but how did you get the particles to spawn, I don't quite understand what you did for that to work, would you mind explaining a bit more, it could be useful for others. E.g. how do you detemine "touching water" or not? Many thanks.
     
  21. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Sorry, to ask another question, is HDRP supported? (URP is not HDRP right) I cannot see that anywhere.
     
  22. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    HDRP is supported. See the store page, Overview->Render pipeline compatibility:
    https://assetstore.unity.com/packages/tools/physics/fluxy-2-5d-fluid-simulator-203795#description

    To elaborate on this: FluXY is render pipeline-agnostic, since it’s a physics engine it doesn’t really care how you render the simulation results: all it does is output a couple textures, one storing fluid density and another one storing fluid velocity. These can be used as input to any shader you write regarless of the render pipeline you’re using.

    To get you started, there’s a basic shader included that’s compatible with all render pipelines, and there’s some URP-specific sample scenes included that make use of more advanced shaders done using ShaderGraph. These can be converted to HDRP by adding it as a compilation target in ShaderGraph.

    cheers,
     
    khos likes this.
  23. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Ok thanks, another question if ok, if I change my project to HDRP will the URP samples (eg URP Rapids / URP Water) work there? I am specifically interested in this scene:
    upload_2023-2-27_23-31-20.png
    To work, but URP for my project will be difficult to move to, there are other assets I have that only URP..... not ideal.
    Hope I am not misunderstanding.
     
  24. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Fluid physics will work in HDRP right out of the box. As for the shaders, you'll have to either adapt the included ones (the water shader in that particular scene is done using ShaderGraph, so it's often just a matter of adding HDRP as a compilation target in the shader) or use your own.
     
    Last edited: Feb 28, 2023
    khos likes this.
  25. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Oh ok, shadergraph is included in Unity, I believe, correct? I have not tried that before, will see about it. Thanks
     
  26. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    Fluxy comes with a base code to derive from which is base class of TargetProvider, you use that class as base for your own class that will provide Fluxy targets yourself.

    What you will do is make a Trigger Collider, with a kinematic rigidbody object, and gather any Fluxy target that enter the Trigger collider by using OnTriggerEnter and OnTriggerExit event.
    Of course for this to work, any Fluxy Target which can be invoked by the OnTriggerEnter event should have a Unity's Collider attached.

    So now you have : a pig with Collider+FluxyTarget on it's body.
    The water body has A Trigger Collider with a script with OnTriggerEnter and OnTriggerExit to know when the pig enter or exit the water, also attach your Fluxy TargetProvider script.

    The pig has a public bool isOnWater in it's CharacterController class (if you make your own controller) or if you use asset store controller, you can use other way by adding a Component type "IsOnWater" you made, and use it as a method to know if the pig is on water or not.

    When pig enters: mark isOnWater on. add it's FluxyTarget to the Fluxy TargetProvider class's list.
    When pig exits: mark isOnWater off. remove its FluxyTarget from the Fluxy TargetProvider class's list.

    By now you have isOnWater status, the problem now not lie in Fluxy anymore, it will has to be handled from your character controller script.
    In any character controller, you already has the events OnJump, OnLand, and you use those event to spawn jump/land splash effect if you isOnWater.
    For the moving splash, you will spawn when character velocity reach some value, for me I set it to 3 (3 meter per second). This character velocity also not in Fluxy, it is in your Character Controller script.

    For now you see I can't share the code because for the most part, this implementation happens inside your Character Controller script, not Fluxy, either you make yourself, or edit it from any asset store asset.

    This sounds kinda involved coding from user, but that's the nature of Fluxy plugin, it's a kit to help make vfx.

    Let me know if you want this integration, I'll consider making a "Splash Effect with Fluxy" and put on the store for 5$, with coding integration, demo scene and splash particle effect.
     
    Last edited: Mar 2, 2023
    khos likes this.
  27. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    your plugin is stunning :p
     
  28. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    WOW, incredible info, many thanks, will read carefully :)
     
  29. Gawidev

    Gawidev

    Joined:
    Jan 28, 2021
    Posts:
    8
    Hey there, fond of this asset, however I'm running into an error consistently when using Unity 2022.2.14f1 and above. Simply by entering playmode on any scene with a Container and a Solver, this error is thrown once.

    [I]Blit material FluidSimulation uses dest texture as input, it's an undefined behaviour. Consider using double buffering.
    UnityEngine.Graphics:Blit (UnityEngine.Texture,UnityEngine.RenderTexture,UnityEngine.Material,int)
    Fluxy.FluxySolver:SimulationStep (Fluxy.FluxyStorage/Framebuffer,single) (at Assets/Plugins/FluXY/Scripts/FluxySolver.cs:342)
    Fluxy.FluxySolver:UpdateSolver (single) (at Assets/Plugins/FluXY/Scripts/FluxySolver.cs:594)
    Fluxy.FluxySolver:LateUpdate () (at Assets/Plugins/FluXY/Scripts/FluxySolver.cs:607)[/I]


    I think it might not even affect function at all, I've run into some other strange behaviour (and crashed my gpu) but that might simply be due to messing with storage values and mesh painting stuff. Regardless, could be important to address since it pops up so consistently.
     
  30. Gawidev

    Gawidev

    Joined:
    Jan 28, 2021
    Posts:
    8
    To follow up on the strange mesh painting behaviour, it seems like velocity is incorrectly projected onto mesh uv's that aren't unwrapped "vertically" (with uv's pointing up the same way the mesh does).

    Here's an example showcasing two containers with default settings, one with default plane and one with unity's default cube mesh. (Although I'm thinking that this might be a poor example due to weird uv's)


    I've also tested this with another simple mesh of my own, to ensure that there aren't any strange overlapping/inverted uv shenanigans contributing to the problem.


    This issue does make things hard to handle, and I cant quite tell why it's going on.

    Also another partially related issue; I see that the world-space gravity property works perfectly, however buoyancy seems to always go towards UV Y+ regardless of the rotation of the model.

    And finally, for a completely unrelated issue; the Position Offset property in the FluxyContainer's World category isn't documented in the user manual :) much less dramatic I know.
     
  31. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Hi!

    Seems like Unity is being overzealous, since the dest texture is never actually read in the fragment shader despite being bound to the material.

    The following code will raise an error, even if the "_Velocity" texture is unused by the material (which is completely valid code):

    Code (CSharp):
    1.  
    2. simulationMaterial.SetTexture("_Velocity", fb.velocityA);
    3. Graphics.Blit(fb.velocityB, fb.velocityA, simulationMaterial, 5);
    In the meantime, unbinding the velocity texture before the Blit() and then binding it again right after gets rid of the error. I'll release a patch for this, and raise a bug report with Unity since the error is incorrect in this case: seems like they just check all bound textures and throw an error if any of them is the destination texture, regardless of what the shader actually does with them.
     
    Last edited: May 9, 2023
  32. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    That's because target velocities aren't projected onto UVs at all: velocity is converted from world space to the container's local space. Only gravity, container acceleration and external forces (basically settings under the container's "World" foldout) are applied in tangent space, which I guess is what you mean by "projected onto uvs".

    Same as velocity, buoyancy is converted from world to local space. This is because buoyancy is intended to be used with planar containers to simulate 2.5D smoke, so typically there's no use in having per-fragment varying buoyancy direction.

    You can use external forces/gravity to sort-of simulate buoyancy if you wish to simulate smoke on the surface of an arbitrary mesh, though.

    Thanks for reporting this! will add it to the manual asap.
     
  33. Gawidev

    Gawidev

    Joined:
    Jan 28, 2021
    Posts:
    8
    Ah I see right, that makes perfect sense, thanks for clarifying. So I guess I would have to ask, what would be the recommended setup for mesh painting?
    My immediate assumption is that making an extra set of custom uv's particularly to be used for sim would be the play. I see that it would technically be possible to make a custom splat shader and class that inherits from FluxyTarget, but then the conversion process to world to tangent velocity would be its own ordeal.
    What would you recommend?
     
  34. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    If you want to paint velocity values on an arbitrary mesh, you have two options:

    - Author mesh UVs so that they align with the objects' local space (which won't always be possible, specially for complex objects). Note FluXY uses the first UV channel to calculate tangent space.

    - Write a custom splat shader for the targets, that converts local space velocity values (which is what the shader gets as input) to tangent space. This would work for the general case without the need to take special care of UVs, but it is considerably more expensive as it requires to build the worldToTangent matrix per-fragment in the splat shader.

    kind regards,
     
    Gawidev likes this.
  35. ulhaqihtisham137

    ulhaqihtisham137

    Joined:
    Jan 10, 2019
    Posts:
    2
    does it work with custome mesh ?
     
  36. ulhaqihtisham137

    ulhaqihtisham137

    Joined:
    Jan 10, 2019
    Posts:
    2
    i have a mesh and i got unwrapped uvs of that mesh how can i project fluid on that mesh uvs by taking the uvs as fluid container ?
     
  37. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    Hello, how can I make the effect framerate independent?
    effect broken at high framerate.
    upload_2023-7-28_22-33-17.png

    All good when the framerate is fixed at 60
    upload_2023-7-28_22-54-31.png
     
    newearlove likes this.
  38. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Would it be possible to convert the URP scenes / assets to BIRP one day, I'm hoping it might be. My project uses too many other BIRP type assets to convert to URP and I really want the lovely URP ones this awesome asset offers!

    When will we get an update, eg v 1.5 with sallow water sim! Please soon :)
     
    Last edited: Sep 25, 2023
  39. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Please use fluxy's support email for support requests, since I don't check the forums often.

    To make the effect framerate independent, select your FluxyTargets and use RateOverTime instead of RateOverSteps:
    http://fluxy.virtualmethodstudio.com/manual/1.4/target.html

     
    Last edited: Nov 13, 2023
  40. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    URP generally looks better than BIRP, so more visually complex sample scenes will continue to be authored for URP.

    However you can compile ShaderGraph shaders for any render pipeline by adding the pipeline to the "active targets" list: https://docs.unity3d.com/Packages/com.unity.shadergraph@12.0/manual/Graph-Target.html

    Most of the time this works well, some shaders might require minor adjustments when converting to other pipelines. For instance, the SceneDepth node doesn't work in the built-in render pipeline, so you'll need to build and pass a scene depth buffer to the volumetric shaders yourself. This is the URP volumetric fog scene rendered in BIRP without scene depth (so no correct intersection with the depth buffer), which is what you'll get when adding the built-in render pipeline as a target to the FluxyVolumetric shader.

     
    Last edited: Nov 13, 2023
    khos likes this.
  41. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,490
    Thanks! To check, will I be able to convert the following sample scene to BIRP:
     
  42. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    hi arkano22,
    did you tried the river mesh maker tool from NatureManufacture (Lava or River package)
    I think it's good to use with fluxy since the output mesh will have UV.
    I tried to make an uneven surface river to test out:
    upload_2023-12-4_11-45-19.png

    About the shape, don't know why it's not aligned perfectly with the base mesh (pink)
    upload_2023-12-4_11-45-59.png

    About the interaction (I did manually assign target to the container in playmode)
    this mesh can't do interaction.
    What is the requirement for a custom mesh to able to do interaction?

    This is the debug UV of the mesh.
    upload_2023-12-4_11-49-35.png
     
  43. dequevedo

    dequevedo

    Joined:
    May 31, 2013
    Posts:
    9
    Hi!

    Is it possible to render unity Fog over FluXY volumetric fog? I'm using URP and this is the undesired effect I'm having:

    upload_2024-4-7_14-37-38.png
     
  44. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929