Unity for Games Profile picture
The leading platform for creating immersive and interactive 2D, 3D, and VR games on 20+ platforms | Part of the @unity solutions portfolio 🚀 🎮

Aug 31, 2021, 12 tweets

In case you didn’t know, there’s a very fun way to get more bang for your buck when using particle systems and custom shaders: custom vertex streams!

Let’s take a look at what these are, and how we can use them for more advanced particle effects! 🧵

@HarryAlisavakis #unitytips

@HarryAlisavakis As you already know, rendered models in Unity are made with triangles which consist of vertices. And vertices hold all essential information regarding these models, like their individual position, their UV coordinates or their vertex color!

The cool thing is that we can add any sort of arbitrary data to our vertices and use it in our custom shader however we like ✨ That’s what custom vertex streams in particle systems allow us to do: pass particle-related information to our vertices that we can use as we please!

The option to add custom vertex streams can be found under the Renderer module of your particle system. Enabling it will show you all the vertex streams that are already being used, like the UV coordinates and the vertex color!

Let’s now make a simple dissolve shader for us to use with our particle system, using shader graph! This is a simple unlit, double-sided #URP shader, with alpha clipping. The interesting thing here is to notice what drives the dissolve effect: the third component of our UVs.

🤷‍♂️ “But why?” I hear you asking. You might be used to using UV coordinates for texture sampling, where you only really use the x and y components. Well, let’s get back to the particle system and its custom vertex streams and add a new one, hopefully that will clear things out:

Next to each stream’s name, you’ll see where that data is stored. Here, the new stream is stored in “TEXCOORD0.z”, which corresponds to the third component of the first texture coordinate channel (aka UV0.z).

Here, I added the lifetime age percentage, so this value will start from 0 and go towards 1 during the particle's lifetime. With our shader, that will make our particles dissolve over their lifetime!

Applying the shader to the particle system can give us this neat result:

So that’s cool, but what if we wanted more control over lifetime?

Age percentage is good but it’s quite linear and not very helpful if we wanted to do more complex effects. The answer is this little module here, called “Custom Data”:

We can use “Custom1.x” instead of age percentage, which in turn allows us to use a curve that alters the value over the particle’s lifetime, similarly to built-in curves like “Size over Lifetime”.

So now we can get a lot more control over how our particles dissolve over time ✨

How cool is that?

There’s plenty of data you can pass over to custom vertex streams and there’s just so much stuff for which you can use them inside your custom shaders!

Can you think of any other creative uses for custom vertex streams? Let us know in the replies!

Happy VFXing! ✨

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling