- Home /
Radial blur effect shader for textures to work with sprites?
I found some shader on the Internet that makes radial blur effect for spinning objects. It works and looks pretty cool but it only works with textures, how do I make it work with sprites? When I try to assign material with this shader to a sprite it gets black. I have none experience with shaders so it's magic for me. Any help?
Here's the code:
 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 Lambert 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"
 }
Answer by Glurth · Feb 01, 2019 at 06:57 PM
I copied this shader into a new project, then created a new material with it. When I applied this material to a sprite, it rotated and blurred it, exactly as one would expect. 
 So, I don't think this issue is with your shader, perhaps something else in your scene is messing it up. I would suggest you create a new project and scene and test it there 
Ok, It seems that there needs to be a light source because it acts like sprite/diffuse shader that needs to be lit to be seen. How can I make it work like normal sprite/default shader that doesn't need a light?
that's due the line that says
 #pragma surface surf Lambert alpha
Lambert is the shading function used to apply light. You can replace it with something like this- defining your own, do-nothing lighting function:
 #pragma surface surf NoLight alpha
 
         half4 LightingNoLight(SurfaceOutput s, half3 lightDir, half atten) {
         half4 c;
         c.rgb = s.Albedo;
         c.a = s.Alpha;
         return c;
     }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                