Unity Shader for Shuriken Particle System

I know many people are curious about how to make shaders available for Shuriken Particle System to use, the concept is very simple!!

The key is just the INPUT COLOR given by Shuriken Particle System:

20150411_01

The input color is the only value that particle system can pass to shaders. And of course shaders must grab this value and use it to calculate the output color.

This is the same case as those GUI plugins like NGUI and Unity 2D sprites, they let you have different colors on different sprites but just using the same material.

20150411_02

Okay now, so how to “grab” the input color? Let’s start with an SURFACE SHADER example of changing the unity default Mobile/Diffuse Shader into a particle-system-supported transparent diffuse Shader.

1. duplicates the shader you want to edit, prepare a texture and creates a material. Assign the material with shader and texture. You can always download Unity default shaders package here. Below is the texture I used:

20150411_03

2. Remember to change the setting of the texture if you want to use the texture alpha value.

20150411_04

3. open up the shader and edit the Mobile/Diffuse shader as follows:

20150411_05

4. you now have a Particle diffuse shader xD!

20150411_06

What about unlit shaders? It is better to use VERTEX and FRAGMENT shaders if you are not interacting with lights (cheaper in performance) Here is the example. Again, I used Unity default Unlit/Transparent shader:

20150411_07

Easy enough right?

To be inspired, the input color is a float4 value…..that means you have four 0-to-1 floating point numbers to play with! Beside using them to control colors and alpha, they can also be used to control the magnitude of different effects like distortion, dissolve, displacement…more and more!

****

Here are some videos that I made particle dissolve shaders for my partner. He used the shaders and create different effects:

They are of course vert and frag shaders. The dissolve effects used the input color alpha as the variable to decide whether that pixel should be vanished or stay visible.

Hard dissolve used ‘step’ function:

http://http.developer.nvidia.com/Cg/step.html

Soft dissolve used ‘smoothstep’ function:

http://http.developer.nvidia.com/Cg/smoothstep.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s