Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Bizio · Feb 01, 2019 at 06:02 PM · 2dshaderspritematerial

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"
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bizio · Feb 01, 2019 at 07:38 PM 0
Share

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?

avatar image Glurth Bizio · Feb 02, 2019 at 03:24 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

273 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sprite Renderer Missing Material after running 1 Answer

2D Sprite Always Visible - Shader / Material not working (ZTest, ZWrite, Culling) 1 Answer

SpriteManager 1 : Custom Material 1 Answer

Sprite Material help 0 Answers

How to fix this kind of shader error? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges