Search Unity

Assets Shader based fluid

Discussion in 'Works In Progress - Archive' started by arkano22, Feb 19, 2020.

  1. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,928
    Hi there,

    I have a few physics-related assets in the store, one of them is a particle-based fluid simulator (Obi Fluid). Many people have asked if it can be used for things like sweat on a character, rain, blood on the walls, etc, the answer is almost always no (that is, if you want your game to run faster than 4 fps :)).

    So I've spent some days working on a fully fragment shader-based fluid simulator, that eventually I'd like to make available for a few bucks. It can simulate flow on any object, following its shape and surface details:



    As of now, it only runs in the built-in pipeline. It takes a grayscale fluid density texture as input (that you can initialize with any values you like, in the video above I'm splatting circular shapes at random locations whenever I move the mouse around), and produces a normals/density map to be used for rendering. In the video I used the output normal map as-is, and the density map to colorize the underlying material.

    The parameters that can be controlled are:

    - Gravity direction and intensity (expressed in world space).
    - Evaporation rate (that is, how long does the fluid stay on the surface)
    - Surface tension (how strong the attraction between fluid molecules is, high values will form drops and tendrils/streaks)
    - Hydrophylism (control surface stickiness, high values will cause fluid to stick instead of running down the surface)
    - Surface detail (how much detail of the surface normal map is used for the simulation)

    I'm looking for initial feedback, and use cases that you can come up with. What would you use it for, and how?
     
    Last edited: Feb 19, 2020
    Mauri, mgear, jamespaterson and 2 others like this.
  2. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    316
    Looking good, I'd definitely be interested. Your intro paragraph pretty much summed up what it could be used for, but also rain on windows, which could (optionally) use a refraction parameter e.g for water being on glass.
     
  3. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,765
    That looks very nice indeed. Will you be able to wipe areas dry?
     
  4. jaelove

    jaelove

    Joined:
    Jul 5, 2012
    Posts:
    302
    please support unity 2017, I'd definitely use this for sweat and blood effects for my characters
     
  5. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    401
    Looks cool!
     
  6. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,928
    Cool idea, shouldn't be difficult to do, will make sure to add an example of this. Frosting the glass where no fluid is present would make it look like it's cold outside!

    Sure, the input is just a grayscale image (white where there's fluid, black where there isn't). Simply splatting a black image anywhere in the map would remove the fluid there. This could be cool for windscreen wipers. Also, adding external forces like wind and similar stuff should be simple enough, thinking of first person racing :)

    Should run in 2017, haven't tested. It only uses very basic stuff. Will try to make it support a wide range of versions.
     
  7. jaelove

    jaelove

    Joined:
    Jul 5, 2012
    Posts:
    302
    Could you possibly add this effect to a custom shader i'm already currently using?
     
  8. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,928
    It's not finished yet, when it is it will be available in the store.
     
  9. jaelove

    jaelove

    Joined:
    Jul 5, 2012
    Posts:
    302
    No, I know! I'm asking if it's possible to combine this shader with a current skin shader that I am already using? I don't want to replace my current skin shader but i'd like to add this effect to it to simulate sweat and blood.\
    Also it would be nice if you could have multiple effects layered like sweat and then blood that flows over or something.
     
  10. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,765
    Perfect, look forward to getting this when it is available, actually got a couple of your assets I need to investigate in the future :) If you need any testers :)
     
    Last edited: Feb 20, 2020
    arkano22 likes this.
  11. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,928
    Sorry, i misunderstood the request! :confused: The fluid shader outputs a normal map and a grayscale density map (packed in a single texture, rgb for the normals and alpha forthe density) so yes you can use those to add any effect on top of a existing shader. How to apply them is up to you though, most of the time you would tint the albedo using the density map, and add the fluid normal to the existing material’s normal.

    If you have multiple fluid (normal/density) maps, nothings stops you from stacking these as you see fit on top of your material.
     
  12. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,765
    Will this support wind speed and direction with possibly turbelence values. I am currently using RainDropFx which supports that but I am all sorts of issues with it as a system so looking for an alternative.
     
  13. arkano22

    arkano22

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

    Yes, wind speed and direction can be just added to the gravity access value (which is already configurable).

    "Turbulence", it depends on what you consider turbulence to be. If you mean spatially variable wind speed and direction, probably not as that would require to read a world space 3D texture of some sort which is quite expensive.

    However, you can add surface variability by using a noisy normal map (that would only be used for fluid motion, not for surface rendering).
     
  14. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,765
    That should work for a windscreen effect, great. Another query, will it be possible to share the generated drops across multiple objects, Iam thinking for multiple cars so that the cost of creating the drops for a windscreen could be shared by a few cars?
     
  15. jaelove

    jaelove

    Joined:
    Jul 5, 2012
    Posts:
    302
    How's it coming along?
     
  16. jaelove

    jaelove

    Joined:
    Jul 5, 2012
    Posts:
    302
    Any update on this?
     
  17. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,765
    Any news :)