Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/SpinBlur"
- {
- Properties
- {
- _Color("Main Color", Color) = (1,1,1,1)
- _Samples("Samples", Range(0,360)) = 100
- _Angle("Angle", Range(0,360)) = 10
- _MainTex("Color (RGB) Alpha (A)", 2D) = "white"
- }
- SubShader
- {
- Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
- LOD 200
- Cull Off
- CGPROGRAM
- #pragma target 3.0
- #pragma surface surf MyLight alpha
- half4 LightingMyLight(SurfaceOutput s, UnityGI gi)
- {
- return half4(s.Albedo, s.Alpha);
- }
- half4 LightingMyLight_GI(SurfaceOutput s, UnityGIInput data, inout UnityGI gi)
- {
- return half4(s.Albedo, s.Alpha);
- }
- sampler2D _MainTex;
- int _Angle;
- int _Samples;
- float4 _Color;
- struct Input {
- float2 uv_MainTex;
- float4 screenPos;
- };
- float2 rotateUV(float2 uv, float degrees) {
- const float Deg2Rad = (UNITY_PI * 2.0) / 360.0;
- float rotationRadians = degrees * Deg2Rad;
- float s = sin(rotationRadians);
- float c = cos(rotationRadians);
- float2x2 rotationMatrix = float2x2(c, -s, s, c);
- uv -= 0.5;
- uv = mul(rotationMatrix, uv);
- uv += 0.5;
- return uv;
- }
- void surf(Input IN, inout SurfaceOutput o) {
- const float Deg2Rad = (UNITY_PI * 2.0) / 360.0;
- const float Rad2Deg = 180.0 / UNITY_PI;
- float2 vUv = IN.uv_MainTex;
- float2 coord = vUv;
- float4 FragColor = float4(0.0, 0.0, 0.0, 0.0);
- int samp = _Samples;
- if (samp <= 0) samp = 1;
- for (float i = 0; i < samp; i++) {
- float a = (float)_Angle / (float)samp;
- coord = rotateUV(coord, a);
- float4 texel = tex2D(_MainTex, coord);
- texel *= 1.0 / samp;
- FragColor += texel;
- }
- float4 c = FragColor * _Color;
- o.Albedo = c.rgb;
- o.Alpha = c.a;
- }
- ENDCG
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement