- Home /
 
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
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}; "
Your answer