DistanceFade-AnimBlendAlpha.shader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  2. Shader "Mirza Beig/Particles/Distance Fade/Anim Alpha Blended" {
  3. Properties {
  4. _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
  5. _MainTex ("Particle Texture", 2D) = "white" {}
  6. _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
  7. _FadeMin("Fade Min", Range(0.0, 10.0)) = 1.0
  8. _FadeMax("Fade Max", Range(0.0, 10.0)) = 2.0
  9. }
  10. Category {
  11. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
  12. Blend SrcAlpha OneMinusSrcAlpha
  13. ColorMask RGB
  14. Cull Off Lighting Off ZWrite Off
  15. SubShader {
  16. Pass {
  17. CGPROGRAM
  18. #pragma vertex vert
  19. #pragma fragment frag
  20. #pragma target 2.0
  21. #pragma multi_compile_particles
  22. #pragma multi_compile_fog
  23. #include "UnityCG.cginc"
  24. sampler2D _MainTex;
  25. fixed4 _TintColor;
  26. struct appdata_t {
  27. float4 vertex : POSITION;
  28. fixed4 color : COLOR;
  29. float4 texcoords : TEXCOORD0;
  30. float texcoordBlend : TEXCOORD1;
  31. UNITY_VERTEX_INPUT_INSTANCE_ID
  32. };
  33. struct v2f {
  34. float4 vertex : SV_POSITION;
  35. fixed4 color : COLOR;
  36. float2 texcoord : TEXCOORD0;
  37. float2 texcoord2 : TEXCOORD1;
  38. fixed blend : TEXCOORD2;
  39. UNITY_FOG_COORDS(3)
  40. #ifdef SOFTPARTICLES_ON
  41. float4 projPos : TEXCOORD4;
  42. #endif
  43. UNITY_VERTEX_OUTPUT_STEREO
  44. };
  45. float4 _MainTex_ST;
  46. float _FadeMin;
  47. float _FadeMax;
  48. v2f vert (appdata_t v)
  49. {
  50. v2f o;
  51. UNITY_SETUP_INSTANCE_ID(v);
  52. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  53. o.vertex = UnityObjectToClipPos(v.vertex);
  54. #ifdef SOFTPARTICLES_ON
  55. o.projPos = ComputeScreenPos (o.vertex);
  56. COMPUTE_EYEDEPTH(o.projPos.z);
  57. #endif
  58. o.color = v.color * _TintColor;
  59. float4 viewPos = mul(UNITY_MATRIX_MV, v.vertex);
  60. float distance = -viewPos.z - _ProjectionParams.y;
  61. float alpha = (distance - _FadeMin) / _FadeMax;
  62. alpha = min(alpha, 1.0);
  63. o.color.a *= alpha;
  64. o.texcoord = TRANSFORM_TEX(v.texcoords.xy,_MainTex);
  65. o.texcoord2 = TRANSFORM_TEX(v.texcoords.zw,_MainTex);
  66. o.blend = v.texcoordBlend;
  67. UNITY_TRANSFER_FOG(o,o.vertex);
  68. return o;
  69. }
  70. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  71. float _InvFade;
  72. fixed4 frag (v2f i) : SV_Target
  73. {
  74. #ifdef SOFTPARTICLES_ON
  75. float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
  76. float partZ = i.projPos.z;
  77. float fade = saturate (_InvFade * (sceneZ-partZ));
  78. i.color.a *= fade;
  79. #endif
  80. fixed4 colA = tex2D(_MainTex, i.texcoord);
  81. fixed4 colB = tex2D(_MainTex, i.texcoord2);
  82. fixed4 col = 2.0f * i.color * lerp(colA, colB, i.blend);
  83. UNITY_APPLY_FOG(i.fogCoord, col);
  84. return col;
  85. }
  86. ENDCG
  87. }
  88. }
  89. }
  90. }