粒子特效使用的材质球,如果通过动画控制shader的某个参数,例如溶解阈值,所有的粒子都会按照相同的数值变化,如果需要每个粒子在自己的生命周期内按照曲线变化,则可以通过customData实现。
1.ParticleSystem中勾选CustomData,支持8个通道,可以选择固定参数或者曲线
2.ParticleSystem中勾选Render中的Custom Vertex Streams
添加custom1和custom2两个通道,各支持四个通道
注意不可以调整上图内UV和Custom的顺序,上图就是默认添加后的顺序;
uv = TEXCOORD0.xy
Custom1.xy = TEXCOORD0.zw Custom1.zw = TEXCOORD1.xy
Custom2.xy = TEXCOORD1.zw Custom2.zw = TEXCOORD2.xy
由于uv占用了TEXCOORD0寄存器,因此Custom2.zw存在了TEXCOORD2寄存器
Shader "Unlit/TestCustomData"
{Properties{_MainTex ("Texture", 2D) = "white" {}_TestValue("TestValue1",Range(0,0.5)) = 0.2}SubShader{Tags { "RenderType"="Opaque" }LOD 100Pass{CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"float _TestValue;struct appdata{float4 vertex : POSITION; float4 customData1 : TEXCOORD0; float4 customData2 : TEXCOORD1; float4 customData3 : TEXCOORD2; };struct v2f{float2 uv : TEXCOORD0; float4 vertex : SV_POSITION;float4 testData1 : TEXCOORD1;float4 testData2 : TEXCOORD2; };sampler2D _MainTex;float4 _MainTex_ST;v2f vert (appdata v){v2f o;o.vertex = UnityObjectToClipPos(v.vertex);o.uv = TRANSFORM_TEX(v.customData1.xy, _MainTex);o.testData1.xy = v.customData1.zw;o.testData1.zw = v.customData2.xy;o.testData2.xy = v.customData2.zw;o.testData2.zw = v.customData3.xy;return o;}fixed4 frag (v2f i) : SV_Target{ fixed4 col = tex2D(_MainTex, i.uv);//col *= i.testData1;col = i.testData2;return col;}ENDCG}}
}