UI Particle AddMultiply.shader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. Shader "UI Extensions/Particles/~Additive-Multiply" {
  2. Properties {
  3. _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
  4. _MainTex ("Particle Texture", 2D) = "white" {}
  5. _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
  6. _StencilComp ("Stencil Comparison", Float) = 8
  7. _Stencil ("Stencil ID", Float) = 0
  8. _StencilOp ("Stencil Operation", Float) = 0
  9. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  10. _StencilReadMask ("Stencil Read Mask", Float) = 255
  11. _ColorMask ("Color Mask", Float) = 15
  12. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
  13. }
  14. Category {
  15. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
  16. Blend One OneMinusSrcAlpha
  17. ColorMask RGB
  18. Cull Off Lighting Off ZWrite Off
  19. ZTest [unity_GUIZTestMode]
  20. SubShader {
  21. Stencil
  22. {
  23. Ref [_Stencil]
  24. Comp [_StencilComp]
  25. Pass [_StencilOp]
  26. ReadMask [_StencilReadMask]
  27. WriteMask [_StencilWriteMask]
  28. }
  29. Pass {
  30. CGPROGRAM
  31. #pragma vertex vert
  32. #pragma fragment frag
  33. #pragma target 2.0
  34. #pragma multi_compile_particles
  35. #pragma multi_compile_fog
  36. #include "UnityCG.cginc"
  37. #include "UnityUI.cginc"
  38. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  39. sampler2D _MainTex;
  40. fixed4 _TintColor;
  41. struct appdata_t {
  42. float4 vertex : POSITION;
  43. fixed4 color : COLOR;
  44. float2 texcoord : TEXCOORD0;
  45. };
  46. struct v2f {
  47. float4 vertex : SV_POSITION;
  48. fixed4 color : COLOR;
  49. float2 texcoord : TEXCOORD0;
  50. UNITY_FOG_COORDS(1)
  51. #ifdef SOFTPARTICLES_ON
  52. float4 projPos : TEXCOORD2;
  53. #endif
  54. };
  55. float4 _MainTex_ST;
  56. v2f vert (appdata_t IN)
  57. {
  58. v2f v;
  59. v.vertex = UnityObjectToClipPos(IN.vertex);
  60. #ifdef SOFTPARTICLES_ON
  61. v.projPos = ComputeScreenPos (v.vertex);
  62. COMPUTE_EYEDEPTH(v.projPos.z);
  63. #endif
  64. v.color = IN.color;
  65. v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
  66. UNITY_TRANSFER_FOG(v,v.vertex);
  67. return v;
  68. }
  69. sampler2D_float _CameraDepthTexture;
  70. float _InvFade;
  71. fixed4 frag (v2f i) : SV_Target
  72. {
  73. #ifdef SOFTPARTICLES_ON
  74. float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
  75. float partZ = i.projPos.z;
  76. float fade = saturate (_InvFade * (sceneZ-partZ));
  77. i.color *= fade;
  78. #endif
  79. fixed4 tex = tex2D(_MainTex, i.texcoord);
  80. fixed4 col;
  81. col.rgb = _TintColor.rgb * tex.rgb * i.color.rgb * 2.0f;
  82. col.a = (1 - tex.a) * (_TintColor.a * i.color.a * 2.0f);
  83. UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
  84. return col;
  85. }
  86. ENDCG
  87. }
  88. }
  89. }
  90. }