Saturday, September 26, 2015

Unity doesn't change particle color when render is set to mesh? (Probably a bug)


I've got a particle system with Render Mode set to Mesh. Then I applied a material to it, which is just white with the default shader. Now I can't change the start color nor the color over lifetime etc. As far as I know that shouldn't happen, right? I'm using Unity 5.5.0f3


This is what my PS looks like with the material :



This is what I achieved with 3 particle systems with 3 different materials, but actually, I don't want these materials. Instead, I want to set the start color property of the particle system to apply some color. The material solution restricts me in terms of random start color and stuff like this.




Answer




I'm not sure why you say "The material solution restricts me in terms of random start color and stuff like this."


You can get random start colours into a material just fine. As I said in my first comment, all you need to do is use (or create) a material that uses the mesh's vertex colours.


For example, you can Create->Shader->Standard Surface Shader (since it appears you want lighting to apply to your meshes), and then make two small modifications:


    CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0

sampler2D _MainTex;

struct Input {

float2 uv_MainTex;

// Modification 1: add a vertex colour parameter to the Input struct.
float4 vertexColor : COLOR;
};

half _Glossiness;
half _Metallic;
fixed4 _Color;


void surf (Input IN, inout SurfaceOutputStandard o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;

// Modification 2: multiply the albedo by this vertex colour.
c *= IN.vertexColor;

o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;

}
ENDCG

Create a material using this shader and assign it to your particle system. Now you can play with colours in the particle system as much as you want!


Animation of a particle system generating many different coloured cubes


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...