An example of sending custom data from Shuriken to a vertex shader in Unity 5.5

Hey guys,

Been playing around with the new feature of Unity 5.5 which allows you to send custom data via TEXCOORD channels from a particle system to a shader.

I’m using this in conjunction with Unity’s new colour picker, which allows each to select a random start colour.

The effect I want to achieve is to have a multi coloured particle system that also has an extra punch of vibrancy at the particles birth. Previously I would have achieve this effect by having a white to colour lifetime gradient:

which would often result in inefficient colour blending and a limited palate of colours to pick from.

But now with the ability to set up a selection of start colours:

I can get a nice range of colours without any weird colour blending issues.

In order to get a nice white hot burst at the start of the particle’s lifetime I can now pass the particle’s lifetime value to the shader via the renderer (ignore the pivot position - thats for some positional correction):

I then run that data through a custom shader:

		float4 frag(v2f i) : SV_Target
		{

			float4 t = tex2D(_MainTex, i.uv);
			float4 colour = t * i.color;

			// invert the lifetime value so that it  starts at 1(white)
			// apply a speed modifier for how quick the burst occures
			// amplify the brightness
			float4 lifeTimeGradient = (1 - i.lifetime.x * _LifeTimeBurstSpeed) * _LifeTimeBurstVibrance;

			colour.rgb += clamp(lifeTimeGradient,0,1) + _Vibrance;
		

			return colour;

		}

So this allows me to amplify the brightness of the particle over a certain period of it’s start lifetime. This is the end result:

6 Likes

Anyone have any other tips for utilising the new system? Keen too see some other techniques to try out