- Home /
Why is shader behavior different between Android and iOS?
I am developing a game for iOS and Android. I had to write my own shaders which are basically just transparent diffuse shader with a specific queue value so that I can control what gets drawn over/under other things. The shaders work perfectly on iOS, but I get some strange behavior on Android. The issue is particularly with my fake shadows, which consist of a plane with a shadow texture. On Android the shadows appear to be higher up on the object than on iOS. I've attached some screenshots to compare.
Any idea what would cause this?
Here is my shader code:
Shader "Custom/shadow" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
Zwrite Off
Tags {"Queue" = "Transparent+9" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
BindChannels
{
Bind "vertex", vertex
Bind "color", color
Bind "texcoord1", texcoord
}
Pass
{
SetTexture[_MainTex] // Combine texture alpha
}
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}
iOS:
Android:
Another strange thing on Android, when I draw a line the shadows change even more:
Also note that transparent cutout shaders seem to work fine, but I get an error in the android build about incompatibility with qualcomm chips.
Answer by zmeinaz · Jun 17, 2013 at 05:02 AM
I think I've figured it out. I was using "Queue" = "Transparent+X" to control the draw order of my transparent 'layers'. Instead of going in the positive direction, I switched it to use "Queue" = "Transparent-X" and reordered everything, it seems to work better now, but it still has some quirks. It looks like the "Queue" field affects the height at which the texture is drawn in Android, I noticed the same effect on the emulator and on my test device (Nexus 4).