MinionsArt

SpriteDistortAura.shader

Oct 30th, 2018
3,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Sprite/Distort Aura" {
  2.     Properties{
  3.         [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  4.         _Distort("Distort Texture", 2D) = "grey" {}
  5.         _Color("Color", Color) = (1, 0, 1, 1)
  6.         _Offset("Offset", Range(-4,10)) = 0
  7.         _Multiplier("Sprite Multiplier", Range(-2,2)) = 1
  8.         _Scale("Distort Scale", Range(0,10)) = 3.2
  9.         _SpeedX("Speed X", Range(-10,10)) = 2
  10.         _SpeedY("Speed Y", Range(-10,10)) = -3.2
  11.         _EffectSize("Effect Size", Range(-0.1,0.1)) = -0.03
  12.         _EffectOffset("Effect Offset", Range(-0.1,0.1)) = 0
  13.         _Brightness("Brightness", Range(-10,10)) = 1.5
  14.         _Opacity("Opacity", Range(-5,10)) =1.2
  15.         [Toggle(ORDER)] _ORDER("Aura Behind", Float) = 1
  16.         [Toggle(ONLY)] _ONLY("Only Aura", Float) = 0
  17.         [Toggle(GRADIENT)] _GRADIENT("Fade To Bottom", Float) = 1
  18.     }
  19.         SubShader{
  20.             Tags
  21.         {
  22.             "Queue" = "Transparent"
  23.             "IgnoreProjector" = "True"
  24.             "RenderType" = "Transparent"
  25.             "PreviewType" = "Plane"
  26.             "CanUseSpriteAtlas" = "True"
  27.         }
  28.         // stencil for (UI) Masking
  29.         Stencil
  30.        {
  31.            Ref[_Stencil]
  32.            Comp[_StencilComp]
  33.            Pass[_StencilOp]
  34.            ReadMask[_StencilReadMask]
  35.            WriteMask[_StencilWriteMask]
  36.        }
  37.         Cull Off
  38.         Lighting Off
  39.         ZWrite Off
  40.         Blend One OneMinusSrcAlpha
  41.  
  42.         Pass {
  43.  
  44.             CGPROGRAM
  45.             #pragma vertex vert
  46.             #pragma fragment frag
  47.             #pragma shader_feature ORDER               
  48.             #pragma shader_feature GRADIENT            
  49.             #pragma shader_feature ONLY
  50.             #include "UnityCG.cginc"
  51.  
  52.             sampler2D _MainTex, _Distort;
  53.  
  54.             struct v2f {
  55.                 float4 pos : SV_POSITION;
  56.                 half2 uv : TEXCOORD0;
  57.             };
  58.  
  59.             v2f vert(appdata_base v) {
  60.                 v2f o;
  61.                 o.pos = UnityObjectToClipPos(v.vertex);
  62.                 o.uv = v.texcoord;
  63.                 return o;
  64.             }
  65.  
  66.             float4 _Color;
  67.             float _Offset;
  68.             float _Brightness;
  69.             float _EffectSize;
  70.             float _EffectOffset;
  71.             float _Scale;
  72.             float _SpeedY, _SpeedX;
  73.             float _Opacity;    
  74.             float _Multiplier;         
  75.  
  76.             fixed4 frag(v2f i) : COLOR
  77.             {
  78.  
  79.             half4 c = tex2D(_MainTex, i.uv);
  80.             c *= c.a;
  81.  
  82.             // scale UV
  83.             float2 scaledUV = (i.uv * (1 +_EffectSize)) - _EffectOffset;
  84.             // UV movement
  85.             float timeX = _Time.x * _SpeedX;
  86.             float timeY = _Time.x * _SpeedY;
  87.  
  88.             //move the distort textures uv and scale them
  89.             float d = tex2D(_Distort, float2(i.uv.x * _Scale + timeX, i.uv.y * _Scale + timeY)) * 0.1;
  90.             // set the texture over distorted uvs
  91.             float4 r = tex2D(_MainTex, float2(scaledUV.x +d , scaledUV.y +d));
  92.            
  93.             // multiply by alpha for cutoff
  94.             r *= r.a;
  95.  
  96.             #if GRADIENT
  97.             // gradient over UV vertically
  98.             r *= lerp(0, 1, (i.uv.y + _Offset));
  99.             #endif
  100.             #if ORDER
  101.             // delete original sprite's alpha to only have the outline
  102.             r *= (1 - c.a);
  103.             #endif
  104.             // extra color tinting with multiplier to original sprite
  105.             float4 tinting = _Color + (c * _Multiplier);
  106.             // add brightness
  107.             r += (_Brightness * r.a) * tinting;
  108.             // set effect opacity
  109.             r = saturate(r *_Opacity);
  110.             #if ONLY
  111.             return r;
  112.             #endif
  113.             return r + c;
  114.         }
  115.  
  116.         ENDCG
  117.     }
  118.         }
  119.             FallBack "Diffuse"
  120. }
Advertisement
Add Comment
Please, Sign In to add comment