What's the problem with this shader on iPad Air (works on an iPad2)

My general question is “how can I know what shaders will work on what platforms (especially different iOS platform targets)?”
My specific question is “why doesn’t this custom shader work on iPad Air?”
See bottom of post for the shader code.

I’m using this shader on a material for a line renderer (aim assist on a weapon, color toggles between green and red).
The renderer works fine on my iPad 2, but shows up as black on the iPad Air. When I switch to the builtin shader “mobile/vertex colored” and redploy, the line renderer then works fine on the iPad Air.

I can’t remember where exactly I got it from, I think a shader tutorial somewhere - certainly didn’t write it myself, since I don’t know anything about shaders yet.

I guess I started using it because it has a “no lighting” lighting model and it has simple color properties (I’m setting the color from a script, don’t need a texture).

Shader "Custom/SimpleTransparentSelfIllum" {
	Properties {
		_MainColor ("Main Color", Color) = (1,1,1,1)
		_EmissionColor ("Emission Color", Color) = (1,1,1,1)
		_AlphaValue ("Alpha Value", Range(0, 1)) = 1
	}
	SubShader {
		Tags { 
      "Queue"="Transparent" 
      "IgnoreProjector"="True" 
      "RenderType"="Transparent" 
    }
		LOD 200
		ZWrite Off
                Blend SrcAlpha OneMinusSrcAlpha 

		CGPROGRAM
		#pragma surface surf Lambert

		float4 _MainColor;
		float4 _EmissionColor;
                float _AlphaValue;

		struct Input {
      float4 color : COLOR;
		};

		void surf (Input IN, inout SurfaceOutput o) {
      o.Albedo = _MainColor;
      o.Emission = _EmissionColor; 
      o.Alpha = _AlphaValue;
		}

    // This function defines the lighting model. 
    // This specific implementation strips all lighting information
    // to make all rendered pixels full-bright (useful for in-game pickups/glows 
    // and the like). This function operates at pixel level.
    // @param s The SurfaceOutput information from the 'surf' function.
    // @param lightDir The light's direction we can use to calculate 
    //   light-surface interaction with.
    // @param atten The light's attenuation factors (attenuation is complex, 
    // outside the scope of this shader. Lots of information on the webs).
    fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) {
      // Declare the variable that will store the final pixel color,
      fixed4 c;
      // Copy the diffuse color component from the SurfaceOutput 
      // to the final pixel.
      c.rgb = s.Albedo; 
      // Copy the alpha component from the SurfaceOutput to the final pixel.
      c.a = s.Alpha;
      return c;
    }



		ENDCG
	} 


	FallBack "Diffuse"
}

No idea why it isn’t working. Maybe you want to try this simple “Unlit Transparent with Color” shader.

Shader "Custom/Unlit Transparent with Color" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
}

SubShader {
	Tags {"Queue"="AlphaTest" "Queue"="Transparent" "IgnoreProjector"="True"}
	ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha
	
	Pass {
		Lighting Off
		SetTexture [_MainTex] {  ConstantColor [_Color] Combine Texture * constant } 
	}
}
}
1 Like

Hi Trilusion,

Thanks for that - works great! Looks good everywhere I’ve tested it - Nexus 1, Nexus 7, PC, OS X, iPad 2 and iPad Air.
I had a shader I got from somewhere else that looked really similar to yours which worked on iPad air, but then didn’t work on the Nexus 7 - yours works everywhere! (that I’ve tested so far).

Interestingly, when I went to pull out the SimpleTransparentSelfIllum that I posted - it turns out I’m using it in a number of other places on normal 3d models where it works fine (on all platforms tested)- it’s only when used in the line renderer on iPad Air where it didn’t work right.

I guess I’m really going to have to stop being lazy and start learning this shader stuff or I’ll just keep getting stuck.

Thanks again.