tonynogo

Demo 49 - Spotlight

Jul 6th, 2017
4,396
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Spotlight"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _CenterX ("Center X", Range(0.0, 0.5)) = 0.25
  7.         _CenterY ("Center Y", Range(0.0, 0.5)) = 0.25
  8.         _Radius ("Radius", Range(0.01, 0.5)) = 0.1
  9.         _Sharpness ("Sharpness", Range(1, 20)) = 1
  10.     }
  11.     SubShader
  12.     {
  13.         Pass
  14.         {
  15.             CGPROGRAM
  16.             #pragma vertex vert_img
  17.             #pragma fragment frag
  18.             #include "UnityCG.cginc"
  19.            
  20.             sampler2D _MainTex;
  21.             float _CenterX, _CenterY;
  22.             float _Radius;
  23.             float _Sharpness;
  24.  
  25.             fixed4 frag (v2f_img i) : SV_Target
  26.             {
  27.                 float dist = distance(float2(_CenterX, _CenterY), ComputeScreenPos(i.pos).xy / _ScreenParams.x);
  28.                 fixed4 col = tex2D(_MainTex, i.uv);
  29.                 return col * (1 - pow(dist / _Radius, _Sharpness));
  30.             }
  31.  
  32.             ENDCG
  33.         }
  34.     }
  35. }
RAW Paste Data