Advertisement
Guest User

ParticlesLightning.shader

a guest
Aug 30th, 2022
2,971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Particles/Lightning" {
  2.   Properties {
  3.     [HDR]_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
  4.     _MainTex ("Particle Texture", 2D) = "white" {}
  5.     _Gradient("Gradient Texture", 2D) = "white" {}
  6.     _Stretch("Stretch", Range(-2,2)) = 1.0
  7.     _Offset("Offset", Range(-2,2)) = 1.0
  8.     _Speed("Speed", Range(-2,2)) = 1.0
  9.   }
  10.  
  11.   Category {
  12.     Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
  13.     Blend One OneMinusSrcAlpha
  14.     ColorMask RGB
  15.     Cull Off Lighting Off ZWrite Off
  16.  
  17.     SubShader {
  18.       Pass {
  19.  
  20.         CGPROGRAM
  21.         #pragma vertex vert
  22.         #pragma fragment frag
  23.         #pragma target 3.0
  24.         #pragma multi_compile_particles
  25.         #pragma multi_compile_fog
  26.  
  27.         #include "UnityCG.cginc"
  28.  
  29.         sampler2D _MainTex, _Gradient;
  30.         fixed4 _TintColor;
  31.  
  32.         struct appdata_t {
  33.           float4 vertex : POSITION;
  34.           fixed4 color : COLOR;
  35.           float4 texcoord : TEXCOORD0;
  36.           UNITY_VERTEX_INPUT_INSTANCE_ID
  37.         };
  38.  
  39.         struct v2f {
  40.           float4 vertex : SV_POSITION;
  41.           fixed4 color : COLOR;
  42.           float4 texcoord : TEXCOORD0;
  43.           float2 texcoord2 : TEXCOORD3;
  44.           UNITY_FOG_COORDS(1)
  45.           UNITY_VERTEX_OUTPUT_STEREO
  46.         };
  47.  
  48.         float4 _MainTex_ST;
  49.         float4 _Gradient_ST;
  50.         v2f vert (appdata_t v)
  51.         {
  52.           v2f o;
  53.           UNITY_SETUP_INSTANCE_ID(v);
  54.           UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  55.           o.vertex = UnityObjectToClipPos(v.vertex);
  56.          
  57.           o.color = v.color;
  58.           o.texcoord.xy = TRANSFORM_TEX(v.texcoord,_MainTex);
  59.           o.texcoord2 = TRANSFORM_TEX(v.texcoord,_Gradient);
  60.  
  61.           // Custom Data from particle system
  62.           o.texcoord.z = v.texcoord.z;
  63.           o.texcoord.w = v.texcoord.w;
  64.           UNITY_TRANSFER_FOG(o,o.vertex);
  65.           return o;
  66.         }
  67.  
  68.        
  69.         float _Stretch, _Offset;
  70.         float _Speed;
  71.  
  72.         fixed4 frag (v2f i) : SV_Target
  73.         {
  74.          
  75.           // Custom Data from particle system
  76.           float lifetime = i.texcoord.z;
  77.           float randomOffset = i.texcoord.w;
  78.  
  79.           //fade the edges
  80.           float gradientfalloff =  smoothstep(0.99, 0.95, i.texcoord2.x) * smoothstep(0.99,0.95,1- i.texcoord2.x);
  81.           // moving UVS
  82.           float2 movingUV = float2(i.texcoord.x +randomOffset + (_Time.x * _Speed) ,i.texcoord.y);
  83.           fixed tex = tex2D(_MainTex, movingUV)* gradientfalloff;
  84.  
  85.           //cutoff for alpha
  86.           float cutoff = step(lifetime, tex);
  87.  
  88.           // stretched uv for gradient map
  89.           float2 uv = float2((tex * _Stretch)- lifetime + _Offset, 1) ;
  90.           float4 colorMap = tex2D(_Gradient, uv);
  91.  
  92.           // everything together
  93.           fixed4 col;      
  94.           col.rgb = colorMap.rgb * _TintColor * i.color.rgb;
  95.           col.a = cutoff;
  96.           col *= col.a;
  97.          
  98.           UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
  99.           return col;
  100.         }
  101.         ENDCG
  102.       }
  103.     }
  104.  
  105.   }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement