• 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 Ali8x · Mar 14, 2012 at 08:44 PM · androidshaderios

Radial Blur for Android/iOS

Hello Everyone,

I recently tried a radial blur shader that someone posted at Unity Forums. It works great, except the problem that it does not work on OpenGL ES (Android/iOS) and xBox360.

When i included the file in my project, it gave me an error

Upgrade NOTE: excluded shader from Xbox360 and OpenGL ES 2.0 because it uses unsized arrays

#pragma exclude_renderers xbox360 gles

I guess there may be a problem with half

 // Upgrade NOTE: replaced 'samplerRECT' with 'sampler2D'
 // Upgrade NOTE: replaced 'texRECT' with 'tex2D'
 
     Shader "Hidden/radialBlur" {
     Properties {
         _MainTex ("Input", RECT) = "white" {}
         _BlurStrength ("", Float) = 0.5
         _BlurWidth ("", Float) = 0.5
     }
         SubShader {
             Pass {
                 ZTest Always Cull Off ZWrite Off
                 Fog { Mode off }
            
         CGPROGRAM
 // Upgrade NOTE: excluded shader from Xbox360 and OpenGL ES 2.0 because it uses unsized arrays
 #pragma exclude_renderers xbox360 gles
        
         #pragma vertex vert_img
         #pragma fragment frag
         #pragma fragmentoption ARB_precision_hint_fastest
      
         #include "UnityCG.cginc"
      
         uniform sampler2D _MainTex;
         uniform half _BlurStrength;
         uniform half _BlurWidth;
         uniform half _iWidth;
         uniform half _iHeight;
      
         half4 frag (v2f_img i) : COLOR {
             half4 color = tex2D(_MainTex, i.uv);
            
             // some sample positions
             half samples[10] = half[](-0.08,-0.05,-0.03,-0.02,-0.01,0.01,0.02,0.03,0.05,0.08);
            
             //vector to the middle of the screen
             half2 dir = 0.5 * half2(_iHeight,_iWidth) - i.uv;
            
             //distance to center
             half dist = sqrt(dir.x*dir.x + dir.y*dir.y);
            
             //normalize direction
             dir = dir/dist;
            
             //additional samples towards center of screen
             half4 sum = color;
             for(int n = 0; n < 10; n++)
             {
                 sum += tex2D(_MainTex, i.uv + dir * samples[n] * _BlurWidth * _iWidth);
             }
            
             //eleven samples...
             sum *= 1.0/11.0;
            
             //weighten blur depending on distance to screen center
             half t = dist * _BlurStrength / _iWidth;
             t = clamp(t, 0.0, 1.0);
            
             //blend original with blur
             return lerp(color, sum, t);
         }
         ENDCG
             }
         }
     }


Help would be appreciated :)

Link and credits: http://forum.unity3d.com/threads/31970-Radial-blur

Comment
Add comment · Show 1
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 teexit · Aug 13, 2013 at 05:37 AM 0
Share

I meet this problem, too. And, one solution is change samples array to size array. It means "half samples[10] = half[10](-0.08". Then, this shader can run on gles. but cannot run on dx11 or xbox360. If you want to let it run normally. use this "half[10] samples= {-0.08,-0.05,-0.03,-0.02,-0.01,0.01,0.02,0.03,0.05,0.08}; "

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity5 standard shader can be used on mobile devices? 1 Answer

Set default number/emails in a new text message/email sent via unity 0 Answers

Transparency working in the editor but not when I build 0 Answers

How to create a mirror reflection for mobile devices 1 Answer

Transparent Detail on mobile 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