ParticleAddMulWithZWrite.shader 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. Shader "Custom/ParticleAddMulWithZWrite"
  2. {
  3. Properties
  4. {
  5. _TintColor("Tint Color", Color) = (1,1,1,1)
  6. _MainTex("Particle Texture", 2D) = "white" {}
  7. _GlowIntensity("Glow Intensity", Range(0,5)) = 2.0
  8. }
  9. SubShader
  10. {
  11. Tags { "Queue" = "Transparent" "IgnoreProjector" = "true" "RenderType" = "Transparent" }
  12. Pass
  13. {
  14. Tags { "Queue" = "Transparent" "IgnoreProjector" = "true" "RenderType" = "Transparent" }
  15. ZWrite Off
  16. ZTest LEqual
  17. Cull Off
  18. Blend One One
  19. ColorMask RGB
  20. CGPROGRAM
  21. #pragma vertex vert
  22. #pragma fragment frag
  23. #include "UnityCG.cginc"
  24. sampler2D _MainTex;
  25. fixed4 _TintColor;
  26. float _GlowIntensity;
  27. struct appdata
  28. {
  29. float4 vertex : POSITION;
  30. float4 color : COLOR;
  31. float2 uv : TEXCOORD0;
  32. };
  33. struct v2f
  34. {
  35. float4 pos : SV_POSITION;
  36. fixed4 color : COLOR;
  37. float2 uv : TEXCOORD0;
  38. };
  39. v2f vert(appdata v)
  40. {
  41. v2f o;
  42. o.pos = UnityObjectToClipPos(v.vertex);
  43. fixed4 c = v.color * _TintColor;
  44. // 先不乘alpha,因为alpha用亮度计算
  45. o.color = c;
  46. o.uv = v.uv;
  47. return o;
  48. }
  49. fixed4 frag(v2f i) : SV_Target
  50. {
  51. fixed4 texcol = tex2D(_MainTex, i.uv);
  52. // 计算亮度作为alpha(黑色透明,白色不透明)
  53. float alpha = texcol.r * 0.3 + texcol.g * 0.59 + texcol.b * 0.11;
  54. texcol.a = alpha;
  55. // 预乘alpha
  56. texcol.rgb *= alpha;
  57. // 顶点颜色乘以贴图颜色(顶点颜色通常是白色或带调节)
  58. fixed4 col = texcol * i.color;
  59. col.rgb *= _GlowIntensity;
  60. return col;
  61. }
  62. ENDCG
  63. }
  64. }
  65. }