Advertisement
Guest User

VertexSpikeDissolve.shader

a guest
Jul 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Particles/VertexSpikeDissolve"
  2. {
  3.     Properties
  4.     {
  5.         _Noise("Vert Noise Texture", 2D) = "white" {}
  6.         _Scale("Vert Noise Scale", Range(0,10)) = 0.5
  7.         _NoiseFrag("Frag Noise Texture", 2D) = "white" {}  
  8.         _FragScale("Frag Noise Scale", Range(0,2)) = 0.5
  9.         _ExtraNoise("Overlay Noise Texture", 2D) = "white" {}
  10.         _ExtraScale("Overlay Noise Scale", Range(0,2)) = 0.5
  11.         _Color("Overlay Noise Color", Color) = (1,0.5,0,0)
  12.         _Tint("Tint", Color) = (1,1,0,0) // Color of the dissolve Line
  13.         _EdgeColor("Edge", Color) = (1,0.5,0,0) // Color of the dissolve Line)
  14.         _Fuzziness("Fuzziness", Range(0,2)) = 0.3
  15.         _Stretch("Dissolve Stretch", Range(-2,4)) = 0.4
  16.         _Growth("Growth", Range(0,2)) = 0
  17.         _Spike("Spike", Range(0,2)) = 0
  18.             _Cutoff("Cutoff", Range(0,1)) = 0
  19.         _Delay("Dissolve Delay", Range(0,2)) = 0
  20.         [Toggle(SOFT)] _SOFT("Soft Spikes", Float) = 1
  21.         [Enum(UnityEngine.Rendering.BlendOp)] _BlendOp("Blend Op", Int) = 0// 0 = add, 4 = max, other ones probably won't look good
  22.     }
  23.         SubShader
  24.         {
  25.             Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" }
  26.             Blend One OneMinusSrcAlpha
  27.             ColorMask RGB
  28.             Cull Off Lighting Off ZWrite Off
  29.             ZTest Always
  30.             BlendOp[_BlendOp]
  31.  
  32.             Pass
  33.             {
  34.                 CGPROGRAM
  35.                 #pragma vertex vert
  36.                 #pragma fragment frag
  37.                 // make fog work
  38.                 #pragma multi_compile_fog
  39.                 #pragma shader_feature SOFT
  40.  
  41.                 #include "UnityCG.cginc"
  42.  
  43.                 struct appdata
  44.                 {
  45.                     float4 vertex : POSITION;
  46.                     float3 uv : TEXCOORD0;// .z has particle age
  47.                     float4 color : COLOR;
  48.                     float4 normal :NORMAL;
  49.                 };
  50.  
  51.                 struct v2f
  52.                 {
  53.                     float3 uv : TEXCOORD0; // .z has particle age
  54.                     UNITY_FOG_COORDS(1)
  55.                     float4 vertex : SV_POSITION;
  56.                     float4 color: COLOR;
  57.                    
  58.                 };
  59.  
  60.                 sampler2D _Noise, _NoiseFrag, _ExtraNoise;
  61.                 float4 _Noise_ST, _Tint, _EdgeColor, _Color;
  62.                 float _Scale, _Cutoff, _Fuzziness, _Stretch, _EdgeWidth, _Growth, _Spike;
  63.                 float _Delay, _ExtraScale, _FragScale;
  64.                 v2f vert(appdata v)
  65.                 {
  66.                     v2f o;             
  67.                     o.uv.xy = TRANSFORM_TEX(v.uv.xy, _Noise);
  68.                     UNITY_TRANSFER_FOG(o, o.vertex);
  69.                     float3 noise = tex2Dlod(_Noise, float4(v.uv.xy * _Scale, 1, 1));// noise texture for spikes
  70.                    
  71. #if SOFT
  72.                     v.vertex.xyz +=  (noise.r* v.normal) * _Spike;// creating spikes without the step cutoff, more shallower spikes
  73. #else
  74.                     v.vertex.xyz += step(_Cutoff, noise.r) * (v.normal * _Spike);// harsh spikes using step cutoff
  75. #endif     
  76.                     v.vertex.xyz += (v.normal *  (v.uv.z)) * _Growth;// increase overall size over particle age
  77.                     o.vertex = UnityObjectToClipPos(v.vertex);
  78.                     o.uv.z = v.uv.z - _Delay;// subtract a number to delay the dissolve
  79.                     o.color = v.color;         
  80.                    
  81.                     return o;
  82.                 }
  83.  
  84.                 fixed4 frag(v2f i) : SV_Target
  85.                 {
  86.                     half4 noise = tex2D(_NoiseFrag, i.uv.xy  * _FragScale);// dissolve texture
  87.                     half4 extraTexture = tex2D(_ExtraNoise, i.uv.xy * _ExtraScale);// extra overlay texture
  88.                     float combinedNoise = (noise.r + extraTexture.r) / 2; // combining noise for a more interesting result
  89.                     float dissolve = smoothstep(_Stretch * i.uv.z, _Stretch * i.uv.z + _Fuzziness, combinedNoise);// smooth dissolve
  90.                     float4 color = lerp(_EdgeColor,_Tint, dissolve.r);
  91.                     color += (extraTexture * _Color); // add extra texture (colored)
  92.                     color *= dissolve; // multiply with dissolve so theres no bleeding
  93.                     color *= i.color;// multiply with the color over time                  
  94.  
  95.                     // apply fog
  96.                     UNITY_APPLY_FOG(i.fogCoord, color);
  97.                     return color;
  98.  
  99.                 }
  100.                 ENDCG
  101.             }
  102.         }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement