| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- Shader "Custom/ParticleAddMulWithZWrite"
- {
- Properties
- {
- _TintColor("Tint Color", Color) = (1,1,1,1)
- _MainTex("Particle Texture", 2D) = "white" {}
- _GlowIntensity("Glow Intensity", Range(0,5)) = 2.0
- }
- SubShader
- {
- Tags { "Queue" = "Transparent" "IgnoreProjector" = "true" "RenderType" = "Transparent" }
- Pass
- {
- Tags { "Queue" = "Transparent" "IgnoreProjector" = "true" "RenderType" = "Transparent" }
- ZWrite Off
- ZTest LEqual
- Cull Off
- Blend One One
- ColorMask RGB
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- sampler2D _MainTex;
- fixed4 _TintColor;
- float _GlowIntensity;
- struct appdata
- {
- float4 vertex : POSITION;
- float4 color : COLOR;
- float2 uv : TEXCOORD0;
- };
- struct v2f
- {
- float4 pos : SV_POSITION;
- fixed4 color : COLOR;
- float2 uv : TEXCOORD0;
- };
- v2f vert(appdata v)
- {
- v2f o;
- o.pos = UnityObjectToClipPos(v.vertex);
- fixed4 c = v.color * _TintColor;
- // 先不乘alpha,因为alpha用亮度计算
- o.color = c;
- o.uv = v.uv;
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- fixed4 texcol = tex2D(_MainTex, i.uv);
- // 计算亮度作为alpha(黑色透明,白色不透明)
- float alpha = texcol.r * 0.3 + texcol.g * 0.59 + texcol.b * 0.11;
- texcol.a = alpha;
- // 预乘alpha
- texcol.rgb *= alpha;
- // 顶点颜色乘以贴图颜色(顶点颜色通常是白色或带调节)
- fixed4 col = texcol * i.color;
- col.rgb *= _GlowIntensity;
- return col;
- }
- ENDCG
- }
- }
- }
|