Advertisement
Guest User

MaskedParticleDissolve.shader

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