Hi guys,
I have made 2 different blur shaders for my project. They work in the editor, but are not visible when I try to run the project on iOS. And when I switch to Android, I get a black rectangle instead of the first shader.
Does anyone know how to remedy the situation? I can’t actually upgrade to Unity 5 with this project as too many things get broken. So for now I’m running Unity 4.6.3f1. I tried to select Automatic & Metal in iOS graphic settings with no positive effect. Selecting OpenGL ES 3.0 produces black screen on iPhone - iOS 8.3, xCode 6.3.
GaussianBlur shader (works on RenderTexture as it purpose is to blur everything behind it)
Shader "Custom/BlurGauss" {
Properties {
_MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
_blurSizeXY("BlurSizeXY", Range(0,10)) = 0
}
SubShader {
// Draw ourselves after all opaque geometry
Tags { "Queue" = "Transparent" }
// Grab the screen behind the object into _GrabTexture
GrabPass { }
// Render the object with the texture generated above
Pass {
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _GrabTexture : register(s0);
float _blurSizeXY;
struct data {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f {
float4 position : POSITION;
float4 screenPos : TEXCOORD0;
};
v2f vert(data i){
v2f o;
o.position = mul(UNITY_MATRIX_MVP, i.vertex);
o.screenPos = o.position;
return o;
}
half4 frag( v2f i ) : COLOR
{
float2 screenPos = i.screenPos.xy / i.screenPos.w;
float depth= _blurSizeXY*0.0005;
screenPos.x = (screenPos.x + 1) * 0.5;
screenPos.y = (screenPos.y + 1) * 0.5; //was 1-
half4 sum = half4(0.0h,0.0h,0.0h,0.0h);
sum += tex2D( _GrabTexture, float2(screenPos.x-5.0 * depth, screenPos.y+5.0 * depth)) * 0.025;
sum += tex2D( _GrabTexture, float2(screenPos.x+5.0 * depth, screenPos.y-5.0 * depth)) * 0.025;
sum += tex2D( _GrabTexture, float2(screenPos.x-4.0 * depth, screenPos.y+4.0 * depth)) * 0.05;
sum += tex2D( _GrabTexture, float2(screenPos.x+4.0 * depth, screenPos.y-4.0 * depth)) * 0.05;
sum += tex2D( _GrabTexture, float2(screenPos.x-3.0 * depth, screenPos.y+3.0 * depth)) * 0.09;
sum += tex2D( _GrabTexture, float2(screenPos.x+3.0 * depth, screenPos.y-3.0 * depth)) * 0.09;
sum += tex2D( _GrabTexture, float2(screenPos.x-2.0 * depth, screenPos.y+2.0 * depth)) * 0.12;
sum += tex2D( _GrabTexture, float2(screenPos.x+2.0 * depth, screenPos.y-2.0 * depth)) * 0.12;
sum += tex2D( _GrabTexture, float2(screenPos.x-1.0 * depth, screenPos.y+1.0 * depth)) * 0.15;
sum += tex2D( _GrabTexture, float2(screenPos.x+1.0 * depth, screenPos.y-1.0 * depth)) * 0.15;
sum += tex2D( _GrabTexture, screenPos-5.0 * depth) * 0.025;
sum += tex2D( _GrabTexture, screenPos-4.0 * depth) * 0.05;
sum += tex2D( _GrabTexture, screenPos-3.0 * depth) * 0.09;
sum += tex2D( _GrabTexture, screenPos-2.0 * depth) * 0.12;
sum += tex2D( _GrabTexture, screenPos-1.0 * depth) * 0.15;
sum += tex2D( _GrabTexture, screenPos) * 0.16;
sum += tex2D( _GrabTexture, screenPos+5.0 * depth) * 0.15;
sum += tex2D( _GrabTexture, screenPos+4.0 * depth) * 0.12;
sum += tex2D( _GrabTexture, screenPos+3.0 * depth) * 0.09;
sum += tex2D( _GrabTexture, screenPos+2.0 * depth) * 0.05;
sum += tex2D( _GrabTexture, screenPos+1.0 * depth) * 0.025;
return sum/1.8;
}
ENDCG
}
}
Fallback Off
}
Texture Directional Blur (works on a texture - supposed to blur a selected sprite vertically)
Shader"Unlit/TransparentColoredBlurred"
{
Properties {
_MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
_blurSizeXY("BlurSizeXY", Range(0,10)) = 0
}
SubShader
{
LOD 100
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
}
Cull Off
Lighting Off
ZWrite Off
Fog { Mode Off }
Offset -1, -1
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vertexProgram
#pragma fragment fragmentProgram
#pragma target 3.0
#include "UnityCG.cginc"
float _blurSizeXY;
struct appdata_t
{
float4 vertex : POSITION;
float2 textureCoordinate : TEXCOORD0;
fixed4 color : COLOR;
};
struct vertexToFragment
{
float4 vertex : SV_POSITION;
half2 textureCoordinate : TEXCOORD0;
fixed4 color : COLOR;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _Distance;
vertexToFragment vertexProgram (appdata_t vertexData)
{
vertexToFragment output;
output.vertex = mul(UNITY_MATRIX_MVP, vertexData.vertex);
output.textureCoordinate = TRANSFORM_TEX(vertexData.textureCoordinate, _MainTex);
output.color = vertexData.color;
return output;
}
fixed4 fragmentProgram (vertexToFragment input) : COLOR
{
float distance = _blurSizeXY * 0.00032;
float depth= _blurSizeXY*0.0009;
fixed4 computedColor = tex2D(_MainTex, input.textureCoordinate) * 0.3;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y + distance * 2)) * 0.15;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y - distance * 2)) * 0.15;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y + distance * 1.5)) * 0.35;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y - distance * 1.5)) * 0.35;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y + 5.0 * depth)) * 0.025;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y - 5.0 * depth)) * 0.025;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y + 4.0 * depth)) * 0.05;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y - 4.0 * depth)) * 0.05;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y + 3.0 * depth)) * 0.09;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y - 3.0 * depth)) * 0.09;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y + 2.0 * depth)) * 0.12;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y - 2.0 * depth)) * 0.12;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y + 1.0 * depth)) * 0.15;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x, input.textureCoordinate.y - 1.0 * depth)) * 0.15;
return computedColor*(0.50+(depth*10));
}
ENDCG
}
}
}