Search Unity

Question Custom UI shader not work in Android build.

Discussion in 'Shaders' started by IEdge, Nov 20, 2020.

  1. IEdge

    IEdge

    Joined:
    Mar 25, 2017
    Posts:
    51
    Hello.

    Recently my shader was stopped working for Android build but it does properly on Editor and Windows, previously it worked correctly.

    Here is the shader:

    Code (CSharp):
    1. Shader "Hidden/Pokémon/UI/PokemonSpritesheet"
    2. {
    3.     Properties
    4.     {
    5.         [HideInInspector] _MainTex("", 2D) = "white" {}
    6.         [HideInInspector] _Color("", Color) = (1, 1, 1, 1)
    7.         [HideInInspector] _ColorMask("", Float) = 15
    8.     }
    9.  
    10.     SubShader
    11.     {
    12.         Tags
    13.         {
    14.             "Queue"="Transparent"
    15.             "IgnoreProjector"="True"
    16.             "RenderType"="Transparent"
    17.             "PreviewType"="Plane"
    18.         }
    19.      
    20.         Cull Off
    21.         Lighting Off
    22.         ZWrite Off
    23.         ZTest [unity_GUIZTestMode]
    24.         Blend SrcAlpha OneMinusSrcAlpha
    25.         ColorMask [_ColorMask]
    26.  
    27.         Pass
    28.         {
    29.             CGPROGRAM
    30.             #pragma vertex vert
    31.             #pragma fragment frag
    32.             #include "UnityCG.cginc"
    33.  
    34.             struct appdata
    35.             {
    36.                 float4 vertex : POSITION;
    37.                 float4 color : COLOR;
    38.                 float2 uv : TEXCOORD0;
    39.             };
    40.  
    41.             struct v2f
    42.             {
    43.                 float2 uv : TEXCOORD0;
    44.                 fixed4 color : COLOR;
    45.                 float4 vertex : SV_POSITION;
    46.             };
    47.  
    48.             sampler2D _MainTex;
    49.             float _Fps;
    50.             float2 _Scale;
    51.             float2 _Frames[512];
    52.             float4 _Color;
    53.             uint _FrameCount;
    54.  
    55.             v2f vert(appdata v)
    56.             {
    57.                 v2f o;
    58.                 o.vertex = UnityObjectToClipPos(v.vertex);
    59.  
    60.                 // Calculate the frame index over time
    61.                 uint index = _FrameCount > 0 ? ((int)(_Time.y / (1 / _Fps)) % _FrameCount) : 0;
    62.  
    63.                 // Set the frame
    64.                 o.uv = v.uv * _Scale + _Frames[index];
    65.              
    66.                 o.color = v.color * _Color;
    67.  
    68.                 return o;
    69.             }
    70.  
    71.             fixed4 frag(v2f i) : SV_Target
    72.             {
    73.                 return tex2D(_MainTex, i.uv) * i.color;
    74.             }
    75.             ENDCG
    76.         }
    77.     }
    78. }
    79.  
    What's wrong with the shader?
     
  2. unityuserunity85496

    unityuserunity85496

    Joined:
    Jan 9, 2019
    Posts:
    89
    you might have to setup logcat to see if it gives errors. this part unity_GUIZTestMode might be a hack that nly worked in previous builds. you might be out of memory in teh frames[n]

    Android updates ALWAYS break something.