Trail.shader 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Shader "FORGE3D/Trail" {
  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. _UVPan ("Trail UV Pan", Float) = 0
  7. }
  8. Category {
  9. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  10. Blend SrcAlpha One
  11. AlphaTest Greater .01
  12. ColorMask RGB
  13. Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
  14. SubShader {
  15. Pass {
  16. CGPROGRAM
  17. #pragma vertex vert
  18. #pragma fragment frag
  19. #pragma multi_compile_particles
  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. #ifdef SOFTPARTICLES_ON
  33. float4 projPos : TEXCOORD1;
  34. #endif
  35. };
  36. float4 _MainTex_ST;
  37. float _UVPan;
  38. v2f vert (appdata_t v)
  39. {
  40. v2f o;
  41. o.vertex = mul(UNITY_MATRIX_MVP, 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. return o;
  49. }
  50. sampler2D_float _CameraDepthTexture;
  51. float _InvFade;
  52. fixed4 frag (v2f i) : SV_Target
  53. {
  54. #ifdef SOFTPARTICLES_ON
  55. float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
  56. float partZ = i.projPos.z;
  57. float fade = saturate (_InvFade * (sceneZ-partZ));
  58. i.color.a *= fade;
  59. #endif
  60. return pow(i.color * _TintColor * tex2D(_MainTex, float2(i.texcoord.x + _UVPan * _Time.x, i.texcoord.y)), 1);
  61. }
  62. ENDCG
  63. }
  64. }
  65. }
  66. }