Overlay Effect Shader - Very slow in mobile device

Hey I have written a CG shader for photoshop overlay effect for 3 textures(one base and other two are overlayed on it), it works fine on desktop but in ipad1 and iphone4 the fps is going down to 9-10 fps… Is there a workaround…
Here is the code-

Shader "Custom/Overlay" {
	Properties {
		_TexA ("TexA", 2D) = "white" {}
		_TexB ("TexB", 2D) = "white" {}
		_TexC ("TexC", 2D) = "white" {}
	}
	
	SubShader {
		Tags { "RenderType"="Opaque" }
		Pass {
		Lighting Off Fog { Mode Off }
		CGPROGRAM
		
		#include "UnityCG.cginc"
		#pragma vertex vert_img
		#pragma fragment frag
		#pragma glsl_no_auto_normalization
		#pragma fragmentoption ARB_precision_hint_fastest
		sampler2D _TexA, _TexB,_TexC;

			fixed4 frag( v2f_img i ) : COLOR {
				fixed4 a = tex2D(_TexA, i.uv);
				fixed4 b = tex2D(_TexB, i.uv);
				fixed4 c = tex2D(_TexC, i.uv);

				fixed4 r = fixed4(0,0,0,1);
				if (a.r > 0.5) { r.r = 1-(1-2*(a.r-0.5))*(1-b.r); }
				else { r.r = (2*a.r)*b.r; }
				if (a.g > 0.5) { r.g = 1-(1-2*(a.g-0.5))*(1-b.g); }
				else { r.g = (2*a.g)*b.g; }
				if (a.b > 0.5) { r.b = 1-(1-2*(a.b-0.5))*(1-b.b); }
				else { r.b = (2*a.b)*b.b; }
				r = lerp(a,r,b.a);
				r = lerp(b,r,a.a);
				fixed4 x = fixed4(0,0,0,1);
				if (r.r > 0.5) { x.r = 1-(1-2*(r.r-0.5))*(1-c.r); }
				else { x.r = (2*r.r)*c.r; }
				if (r.g > 0.5) { x.g = 1-(1-2*(r.g-0.5))*(1-c.g); }
				else { x.g = (2*r.g)*c.g; }
				if (x.b > 0.5) { x.b = 1-(1-2*(r.b-0.5))*(1-c.b); }
				else { x.b = (2*r.b)*c.b; }
				x = lerp(r,x,c.a);
				x = lerp(c,x,r.a);
				return x;
			}
			ENDCG
		}
	}
}

Your answers are very much appreciated…
Thanx

maybe try to use something like this: (a.r > 0.5) ? r.r=1 : r.r=2; instead of ifs intructions that are not effective in shaders.

Thanks for shader sources :slight_smile: