Guest User

DistortOverlay.shader

a guest
Jan 31st, 2020
201
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Hidden/Distort Overlay"
  2. {
  3.     Properties
  4.     {
  5.         [HideInInspector]_MainTex("Texture", 2D) = "white" {}
  6.         _RenderTexture("Render Texture", 2D) = "black" {}
  7.         _Noise("Noise", 2D) = "white" {}
  8.         _DistortStrength("Distort Strength", Range(0,0.2)) = 0.1
  9.         _ShadowC("ShadowColor", Color) = (0.1, 0.1, 0.1, 0.1)
  10.         _NScale("Noise Scale", Range(0,10)) = 2
  11.         _LightMultiplier("Light Circle Smoothness", Range(0, 5)) = 3
  12.         _ExtraLight("Light Strength", Range(0.5, 5)) = 1
  13.         _OuterEdge("Outer distort Edge", Range(0, 10)) = 0.8
  14.         _InnerEdge("Inner distort Edge", Range(0, 10)) = 0.8
  15.         _SPeedX("Scroll Speed X", Range(-5, 5)) = 0
  16.         _SPeedY("Scroll Speed Y", Range(-5, 5)) = -1
  17.     }
  18.         SubShader
  19.     {
  20.         // No culling or depth
  21.         Cull Off ZWrite Off ZTest Always
  22.  
  23.  
  24.         Pass
  25.         {
  26.             CGPROGRAM
  27.             #pragma vertex vert
  28.             #pragma fragment frag
  29.  
  30.             #include "UnityCG.cginc"
  31.  
  32.             struct appdata
  33.             {
  34.                 float4 vertex : POSITION;
  35.                 float2 uv : TEXCOORD0;
  36.             };
  37.  
  38.             struct v2f
  39.             {
  40.                 float2 uv : TEXCOORD0;
  41.                 float4 vertex : SV_POSITION;
  42.             };
  43.  
  44.             v2f vert(appdata v)
  45.             {
  46.                 v2f o;
  47.                 o.vertex = UnityObjectToClipPos(v.vertex);
  48.                 o.uv = v.uv;
  49.                 return o;
  50.             }
  51.  
  52.             sampler2D _MainTex, _RenderTexture, _Noise;
  53.             float4 _ShadowC;
  54.             float _OuterEdge, _InnerEdge;
  55.             float _LightMultiplier, _NScale, _DistortStrength;
  56.             float _SPeedX, _SPeedY;
  57.             float _ExtraLight;
  58.             fixed4 frag(v2f i) : SV_Target
  59.             {
  60.  
  61.             // scrolling speed
  62.             float scrollSpeedX = _Time.x * _SPeedX;
  63.             float scrollSpeedY = _Time.y * _SPeedY;
  64.             float2 scrolling = float2(scrollSpeedX, scrollSpeedY);
  65.  
  66.             // noise
  67.             fixed4 noise = tex2D(_Noise, i.uv * _NScale +  scrolling);
  68.             fixed4 noise2 = tex2D(_Noise, i.uv * (_NScale * 2) + scrolling);
  69.             float combNoise = (noise + noise2)* 0.5; // combine different scale noise
  70.  
  71.             fixed4 lights = (tex2D(_RenderTexture, i.uv) * combNoise * 5) * _LightMultiplier;// lighting layer with added noise
  72.             // make lights greyscale
  73.             float greyscaleLights = dot(lights, float3(0.3, 0.59, 0.11));
  74.             float distortionEdge = smoothstep(combNoise, combNoise + _OuterEdge, greyscaleLights) * (1 - smoothstep(combNoise, combNoise + _InnerEdge, greyscaleLights)); //multiply smoothstep with inversed smoothstep with different offset
  75.            
  76.             fixed4 col = tex2D(_MainTex, i.uv + (distortionEdge * _DistortStrength));// add distortion to main camera output
  77.             lights = saturate(lights);// saturate so it's not extra bright where the lights are
  78.             col = lerp(col * _ShadowC, col, lights * _ExtraLight);// lerp normal view multiplied by shadow color, with normal camera view over the noise lights layer
  79.             return col;
  80.         }
  81.         ENDCG
  82.     }
  83.     }
  84. }
RAW Paste Data