Guest User

NoiseSpriteOverlay.shader

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