Search Unity

Particle Falloff Shader

Discussion in 'Shaders' started by Voronoi, Dec 11, 2012.

  1. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    587
    I have been trying to create a cheap, 2D fluid type of effect for iOS and have run out of ideas. I've found sources for metaballs, vector based bezier curves and a few other ideas. The only thing that I've found that really comes close is the Funky Glow in the Unity Replacement shaders. That project does not work when switching to mobile, and I assume it's because it's a Render Texture effect that is not supported on iOS.

    I did manage to get the look I want using the built-in Image Effect - Color Correction Effect with a circle type texture. It rendered great in the editor, appeared to be supported for iOS but when I built it for an iPad 3 I got 1-3 fps. I believe it's because it's a camera effect and is using the entire image to recreate the effect. The 'fluid' shape is built by using additive particles, and the color correction clips the particle rendering to a nice outline.

    I'm thinking that a shader that is focusing only on the particles could do this without having to render the entire scene. Can anyone point me in a direction to figure this out? Since I'm not using geometry, it would need to be a shader that looks at a group of particles and how it's rendered, and then convert that to an outline. Here's a screen shot of what I was able to get working nicely in the editor:

    $Screen Shot 2012-12-10 at 6.57.24 PM.png

    To the left is the particle effect, and to the right is the rendering using a Camera set up with the Color Correction Effect. It feels very fluid-like, runs fine in the editor but is completely unusable on mobile.
     
  2. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    There are many aspects to fluids that you could try to recreate. For example: Shape, Reflection, Refraction, Fog (it's not strictly fog, but that's the name it's usually referred to when it comes to water graphics, because it is often rendered like volumetric fog), caustics and flow.

    So perhaps you should give some more details on how you want to use the fluid, to make it more likely that people give you a useful option :). (I'm guessing you're trying to mimic the shape of the outline of a fluid, is that correct?)
     
  3. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    587
    I think Fog is probably more what I'm looking at in terms of how it behaves. I'm not interested in refraction or true fluid physics, there is no collision involved or needed.

    What I'm trying to accomplish is a amoeba type of object, a macrophage to be exact. Rendered as an outline. This is for mobile, so I would like to have arms appear based on touch. If a person used 5 fingers, 5 arms would stretch out of the macrophage and move with the touch. I can accomplish the animation by using particles, where the body is one Particle System, with a few large soft particles. The sprouting arms are particle systems that shoot particles back to the center of the body.

    This gives a gooey, jelly like appearance when used with a Color Correction affect to sharpen up the edge of the particles. As I said, it works and looks great on the desktop, but as it relies on a Camera Effect it is totally unusable on mobile.

    If I make the particles solid circles, it is OK performance wise, but looks more like a bubbling fountain. I would like to try to keep the gelatinous like shape that is possible by using falloff on a gradient, but wanted to know if this was possible using a particle shader rather than an image effect.

    Conceptually,what I have now is taking radial gradients and overlaying them to create a blob. The gradient edge is clipped to a line.

    This is a javascript metaball example that is doing something similar, but I cannot think of how to do this in Unity that will work efficiently on mobile devices:

    http://www.somethinghitme.com/2012/06/06/2d-metaballs-with-canvas/
     
    Last edited: Dec 11, 2012
  4. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Well the first thing that's killing you is overdraw. When transparent materials (in this case, particles) get in front of each other, you end up having to re-render the space the stack of particles takes up multiple times, which usually results in performance drops. For mobile platforms, the game basically just gives up and reverts to Unity's hidden "Slideshow" rendering mode for cameras.

    It looks like the one advantage you're got is that there's no real perspective to be seen; you're just looking for a 2D outline.

    Out of curiosity, is this what you're looking for?



    Bear in mind that this is what happens to a human, you'll basically be applying it to a blob. It's lit should work with shadows, has diffuse and emissive, and some levels for clamping and edge thickness. Maybe there could be a 'solid' (transparent) interior colour as well. It's very responsive to vertex density; long edges and polygons give extra-wobbly and thick outlines, but dense polygons give less wobbliness and smaller outlines.


    EDIT: this is done in-shader, no render textures. Requires Shader Model 3 at the moment, but could probably be squeezed into SM2 if I wanted.
     
  5. John-Higuera

    John-Higuera

    Joined:
    Oct 14, 2012
    Posts:
    20
    Does any one know if is possible to have something like what can be see here:

    http://somethinghitme.com/projects/metaballs/

    What we are trying to do is to have is a particle emitter that move at the scene in 2D only, what we want to see is the closer particles get together like in the link demo above, any advise or clue about how to achieve this metaballs effect would be really appreciated.
     
  6. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    The Nvidia site is usually a good place to start looking. For example, this article.
     
  7. Drakorian-Labs

    Drakorian-Labs

    Joined:
    Feb 23, 2012
    Posts:
    88
    Hi, i know it's a bit late, and i haven't tried this, but:
    http://wiki.unity3d.com/index.php?title=MetaBalls

    It's about metaballs, maybe you can try it :)