Shader looks different on iPhone and Editor

I wrote a simple combiner shader that blends two transparent textures. It's actually very similar to the first one Jessy wrote in this thread: http://forum.unity3d.com/viewtopic.php?t=33727

My problem is that the shader works perfectly in the Unity iPhone editor (with gfx emulation on) but it doesn't work right on the iPhone.

Here is the shader:

Shader "My Shaders/Mix Textures" {

Properties {
    _Mix ("Mix", Range(0,1)) = 0
    _Tex1 ("Texture 1", 2D) = "white" {}
    _Tex2 ("Texture 2", 2D) = "black" {}
}

SubShader {
    Pass {
        Lighting Off
        Cull Off 
        Fog {Mode Off} 

        Blend SrcAlpha OneMinusSrcAlpha

        SetTexture[_Tex1] {
            ConstantColor (1,1,1,1)
            Combine texture * constant
        }

        SetTexture[_Tex2] {
            ConstantColor (1,1,1,[_Mix])
            Combine texture lerp(constant) previous
        }
    }
}
FallBack "Transparent/Diffuse"

}

As you can see, the first SetTexture result is overwritten by the second SetTexture at a ratio determined by _Mix. On the iPhone, when _Mix is 0, all I get is pure black whereas the first texture is what should be showing. When _Mix is 1, the second texture shows correctly.

Another thing I noticed is the Range value of _Mix seems to be quantized severely on the iPhone. Hard-setting the value to 0.1 gives me pure black (same as setting it to 0.) I remember from the dot3 normalmap test on the iPhone that the range of 0..1 might only have 8 levels. I'd appreciate it if someone could confirm this.

My biggest concern of course is the shader not working properly when _Mix is 0.

Any ideas? Thanks.

First question I would ask, are the issues still there when you turn off blending?

The MBXLite GPU (pre-3GS) only supports one Constant Color. The last Constant Color defined is the one used any time you use the command. So, as it is, you're multiplying the alpha channel of Texture 1 by zero when Mix is zero. So you won't see any contribution of it. You mentioned that it was black; the only reason it would be black is that whatever was rendered before it was black. If this happened to get rendered before all your other scene geometry, and your camera cleared to a solid color of black, this could happen.

Fortunately, the multiplication in your first texture stage is useless anyway, so we can throw that out. We can also ensure that we won't be blending to the background by putting the shader in a later queue (I think ZWrite off is a safer bet too, but there's no foolproof way to do alpha blending - see what is preferable to you). Using a later queue for blended meshes can make the game run better, also, because it allows tile-based deferred rendering to work its magic better in the Geometry queue. There's not a point in using a fallback because the iPhone hardware won't get worse than it was when it first came out. Fog and lighting are off by default so you don't need those lines. I don't know which texture is "more important" to you, but I always make one of the textures _MainTex to allow for easier scripting. Undo that if you find it confusing, or switch the variables around if Texture 1 is the "more important".

There is no quantization error apparent to my eyes on my iPod touch 2G.

Shader "My Shaders/Mix Transparent Textures" {

Properties 
{
    _Mix ("Mix", Range(0,1)) = 0
    _Tex1 ("Texture 1", 2D) = "white"
    _MainTex ("Texture 2", 2D) = "black"
}

SubShader 
{
    Tags {Queue = Transparent}
    Cull Off
    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha

    Pass 
    {
        SetTexture[_Tex1]
        SetTexture[_MainTex] 
        {
            ConstantColor (1,1,1,[_Mix])
            Combine texture Lerp(constant) previous
        }
    }
}

}