Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/SpinBlur"
  2. {
  3.     Properties
  4.     {
  5.         _Color("Main Color", Color) = (1,1,1,1)
  6.         _Samples("Samples", Range(0,360)) = 100
  7.         _Angle("Angle", Range(0,360)) = 10
  8.         _MainTex("Color (RGB) Alpha (A)", 2D) = "white"
  9.     }
  10.  
  11.     SubShader
  12.     {
  13.         Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
  14.  
  15.         LOD 200
  16.         Cull Off
  17.  
  18.         CGPROGRAM
  19.         #pragma target 3.0
  20.         #pragma surface surf MyLight alpha
  21.  
  22.         half4 LightingMyLight(SurfaceOutput s, UnityGI gi)
  23.         {      
  24.             return half4(s.Albedo, s.Alpha);
  25.         }
  26.        
  27.         half4 LightingMyLight_GI(SurfaceOutput s, UnityGIInput data, inout UnityGI gi)
  28.         {
  29.             return half4(s.Albedo, s.Alpha);
  30.         }
  31.  
  32.         sampler2D _MainTex;
  33.         int _Angle;
  34.         int _Samples;
  35.         float4 _Color;
  36.  
  37.         struct Input {
  38.             float2 uv_MainTex;
  39.             float4 screenPos;
  40.         };
  41.  
  42.         float2 rotateUV(float2 uv, float degrees) {
  43.             const float Deg2Rad = (UNITY_PI * 2.0) / 360.0;
  44.             float rotationRadians = degrees * Deg2Rad;
  45.             float s = sin(rotationRadians);
  46.             float c = cos(rotationRadians);
  47.             float2x2 rotationMatrix = float2x2(c, -s, s, c);
  48.             uv -= 0.5;
  49.             uv = mul(rotationMatrix, uv);
  50.             uv += 0.5;
  51.             return uv;
  52.         }
  53.  
  54.         void surf(Input IN, inout SurfaceOutput o) {
  55.             const float Deg2Rad = (UNITY_PI * 2.0) / 360.0;
  56.             const float Rad2Deg = 180.0 / UNITY_PI;
  57.             float2 vUv = IN.uv_MainTex;
  58.             float2 coord = vUv;
  59.             float4 FragColor = float4(0.0, 0.0, 0.0, 0.0);
  60.             int samp = _Samples;
  61.             if (samp <= 0) samp = 1;
  62.             for (float i = 0; i < samp; i++) {
  63.                 float a = (float)_Angle / (float)samp;
  64.                 coord = rotateUV(coord, a);
  65.                 float4 texel = tex2D(_MainTex, coord);
  66.                 texel *= 1.0 / samp;
  67.                 FragColor += texel;
  68.             }
  69.             float4 c = FragColor * _Color;
  70.             o.Albedo = c.rgb;
  71.             o.Alpha = c.a;
  72.         }
  73.         ENDCG
  74.     }
  75.     FallBack "Diffuse"
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement