Animated Mesh for Particle system? (Question)

Hey Folks,

I’ve got a question- Is it possible to have an animated mesh being emitted from the particle system in Unity?

I remember reading something about vertex animation as a way of storing the animation.

The reason I ask this is for an alternative to Flipbooks which can become very choppy with lower/higher lifetimes. I notice alot of people will use the flipbooks in games and that’s sometimes an issue.

Imagine a butterfly flapping it’s wings. That’s what I’m trying to create.

The idea here is to have a plane with 3 bones and a short animation of the wings flapping. That way the animation would play smoothly always and the only thing that’d be controlled by the lifetime is the opacity and speed.

Any ideas? Or would it require a script of some sort?

Generally the way you’d do something like this is using shader based animation. The short version is use vertex color or a UV value to flag specific vertices (the tips of the wings) and move them up and down in the shader with a sine wave and the vertex normal.

1 Like

The Texture animation module in Unity works on meshes, so you can also do something like this;

It’s not optimal, quite a lot of texture space wasted

This was made as a test to show that texture animation work on mesh particles, perhaps it could be made pretty? not sure

This was made using 5.6.2f1. Together with Render Alignment: Velocity (supported in Unity 2017?) it might look okay


Vertex deformation can provide great results, butterflies in video below was made using Vertex shader animation @bgolus mentioned.

The CryEngine vertex deformation shader supports Vertex colors so it allows you to paint attributes on the mesh that affect the Sine wave’s Phase, Frequency and Amplitude

You can see the butterflies here (was instanced using boids, not particles)

@bgolus Ok. I understand what you’re saying.
@Ludvig Yea, that first method is too wasteful and I might as well just use a flipbook without a mesh.

I guess my question here is “Is vertex animation possible in Unity’s ShaderForge, and how would you set it up?”

Below is an example of a shader I made trying to capture that vertex movement. It works in theory, but there’s some very apparent issues when its applied to Shuriken.

For one, the vertex animation doesn’t scale uniformly, so the smaller the particle is, the more stretched and distorted it becomes. It also increases the strength of the vertex offset as well. Is there a way to scale this information uniformly in local space and can I control the strength of the up/down movement better?

As of Unity 5.6 Particle Systems can pass custom data to the shader (via additional UV channels). Add one to pass the scale and multiply the vertex offset by that scale.

I believe I understand what you mean. So I’d replace the “Value” with a “Custom-Z” and multiply/divide it against the scale.

I’m still struggling with how to set it up. What kind of formula would you use to adjust the scale?

There’s one major issue I’m noticing- If you remove vertex off-set the scale of the particles is normal. If you add it back, it increases it’s size and distorts it.

I’m trying to clamp it someway to reduce the up and down range of the verts but retain the speed. The wings need to beat at a medium speed but not distort as much.

Oi I think i figured it out! I was just clicking around in the settings and found object scale. I multiply it down and it keeps the speed but scales down the movement range based on it’s size.

I just do the regular “vertex animation” then multiply it against scale at the end and it scales appropriately!

I’m a little surprised the ObjectScale does anything. I don’t use ShaderForge, but I assume that would just be the scale being pulled from the object to world matrix. For particles that shouldn’t do anything at all since that matrix isn’t going to be per-particle. This is what I was talking about.

But if it works, great!

Cool. I’ll check that out for sure! Also I have one more question-

Is there a way to attach a sub-emitter to the parent’s axis? I want to create a additive backing to my alpha blended particles so that I can scale/manipulate the additive backing separately.

Say I wanted to have some smiley’s spawning and falling to the ground. As they fall they radiate light (scale up and down repeatedly to fake glowing).

The issue I have is that inherit velocity is either offset wrong or doesn’t work for the sub-emitter. Is there a way to do this? I don’t want to use Add-Blend or Sprite sheets for this if possible.

Inherit velocity is for inheriting the game object’s velocity, so no it does not work for sub emitters. There are kind of three ways to do this.

Duplicate particle positions with a custom script
Have a script on your particle system that copies a parent particle system’s particle positions. This is the most accurate way to do what you want, but it’s slow and bug prone.

Use a fixed random seed
What I’ve done for more complex setups is disable “Auto Random Seed” and set both particle emitters to use the same seed. Then as long as they share identical emission and velocity values elsewhere they’ll have identical motion making them appear to be linked. This is probably the easiest method.

Custom shader with “Blend Add” (aka Premultiplied Alpha) blend
So I don’t actually mean use the “Blend Add” shader as it’s traditionally described (which, fyi, is just old school premultiplied alpha). Instead have a single shader that renders both sprites using the custom data properties to allow you to individually scale (by modifying the UVs in the shader) each, as well as animate the color independently. This is what I would personally do. Depending on what order you want them to render in (ie: all glows behind the smiley faces vs each face’s glow sorting) you could use a two pass shader and a combination of particle center and custom data to scale the glow particles.

@bgolus Ahhhhh- There’s a good work-around (use fixed seed)! I can’t believe I didn’t think of that haha.

I could probably get some kind of script from the programmer that manipulates the seed of the two systems at the same time. That way I could keep randomization and it would match up. If it’s possible that is.

Blend-add isn’t too bad and it’s a good suggestion to animate the color independently. Thanks for the suggestions!

1 Like