Particle Add.shader 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. Shader "Particles/Additive" {
  2. Properties {
  3. [HDR]_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. }
  7. Category {
  8. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
  9. Blend SrcAlpha One
  10. ColorMask RGB
  11. Cull Off Lighting Off ZWrite Off
  12. SubShader {
  13. Pass {
  14. CGPROGRAM
  15. #pragma vertex vert
  16. #pragma fragment frag
  17. #pragma target 2.0
  18. #pragma multi_compile_particles
  19. #pragma multi_compile_fog
  20. #include "UnityCG.cginc"
  21. sampler2D _MainTex;
  22. fixed4 _TintColor;
  23. struct appdata_t {
  24. float4 vertex : POSITION;
  25. fixed4 color : COLOR;
  26. float2 texcoord : TEXCOORD0;
  27. };
  28. struct v2f {
  29. float4 vertex : SV_POSITION;
  30. fixed4 color : COLOR;
  31. float2 texcoord : TEXCOORD0;
  32. UNITY_FOG_COORDS(1)
  33. #ifdef SOFTPARTICLES_ON
  34. float4 projPos : TEXCOORD2;
  35. #endif
  36. };
  37. float4 _MainTex_ST;
  38. v2f vert (appdata_t v)
  39. {
  40. v2f o;
  41. o.vertex = UnityObjectToClipPos(v.vertex);
  42. #ifdef SOFTPARTICLES_ON
  43. o.projPos = ComputeScreenPos (o.vertex);
  44. COMPUTE_EYEDEPTH(o.projPos.z);
  45. #endif
  46. o.color = v.color;
  47. o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  48. UNITY_TRANSFER_FOG(o,o.vertex);
  49. return o;
  50. }
  51. sampler2D_float _CameraDepthTexture;
  52. float _InvFade;
  53. fixed4 frag (v2f i) : SV_Target
  54. {
  55. #ifdef SOFTPARTICLES_ON
  56. float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
  57. float partZ = i.projPos.z;
  58. float fade = saturate (_InvFade * (sceneZ-partZ));
  59. i.color.a *= fade;
  60. #endif
  61. fixed4 col = 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord);
  62. UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
  63. return col;
  64. }
  65. ENDCG
  66. }
  67. }
  68. }
  69. }