I made a relatively simple shader, it works fine on my pc and on my android phone,
but on some phones it looks incorrect (and for some reason it doesn’t use it’s fallback).
And what’s even stranger is the fact that I made an other shader that is exactly the same, but slightly more complex, and that one works on all devices.
Does anyone have any idea why?
here’s the shader:
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Unlit/Snake"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Solid ("Solid (R,L,U,D)", Vector) = (0,0,0,0)
_Offset ("Shadow Offset", Vector) = (0,0,0,0)
//_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader
{
Tags { "RenderType"="TransparentCutout" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Solid;
float3 _Offset;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float3 offset = mul( (float3x3)unity_WorldToObject, _Offset) ;
fixed4 col = tex2D(_MainTex, i.uv);
clip(col.a-0.5);
fixed4 shadowcolor = col;
shadowcolor.rgb *= 0.85;
i.uv += offset;
if (i.uv.x>1 && _Solid.x<0.5)
{
return shadowcolor;
}
if (i.uv.x<0 && _Solid.y<0.5)
{
return shadowcolor;
}
if (i.uv.y>1 && _Solid.z<0.5)
{
return shadowcolor;
}
if (i.uv.y<0 && _Solid.w<0.5)
{
return shadowcolor;
}
if ((i.uv.x>1 || i.uv.x<0) && (i.uv.y>1 || i.uv.y<0))
{
return shadowcolor;
}
float2 uv2 = i.uv - offset*0.5;
if (tex2D(_MainTex, i.uv).a<0.5 || tex2D(_MainTex, uv2).a<0.5)
{
return shadowcolor;
}
return col;
}
ENDCG
}
}
Fallback "Unlit/Transparent Cutout"
}
and here’s the more complex shader that does work:
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Unlit/SnakeHead"
{
Properties
{
_MainTex ("Texture1", 2D) = "white" {}
_MainTex2 ("Texture2", 2D) = "white" {}
_Solid ("Solid (R,L,U,D)", Vector) = (0,0,0,0)
_Offset ("Shadow Offset", Vector) = (0,0,0,0)
_State1Time ("State 1 Time", float) = 2
_State2Time ("State 2 Time", float) = 0.1
}
SubShader
{
Tags { "RenderType"="TransparentCutout" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _MainTex2;
float4 _Solid;
float3 _Offset;
float _State1Time;
float _State2Time;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float3 offset = mul( (float3x3)unity_WorldToObject, _Offset) ;
fixed4 col = tex2D(_MainTex, i.uv);
if ((_Time.y)%(_State1Time+_State2Time)>_State1Time)
{
col = tex2D(_MainTex2, i.uv);
}
clip(col.a-0.5);
fixed4 shadowcolor = col;
shadowcolor.rgb *= 0.85;
i.uv += offset;
if (i.uv.x>1 && _Solid.x<0.5)
{
return shadowcolor;
}
if (i.uv.x<0 && _Solid.y<0.5)
{
return shadowcolor;
}
if (i.uv.y>1 && _Solid.z<0.5)
{
return shadowcolor;
}
if (i.uv.y<0 && _Solid.w<0.5)
{
return shadowcolor;
}
if ((i.uv.x>1 || i.uv.x<0) && (i.uv.y>1 || i.uv.y<0))
{
return shadowcolor;
}
float2 uv2 = i.uv - offset*0.5;
if (tex2D(_MainTex, i.uv).a<0.5 || tex2D(_MainTex, uv2).a<0.5)
{
return shadowcolor;
}
return col;
}
ENDCG
}
}
Fallback "Unlit/Snake"
}

