Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Shader not working correctly on iOS after 2018->2020 upgrade

Discussion in 'iOS and tvOS' started by arom1989, Nov 26, 2021.

  1. arom1989

    arom1989

    Joined:
    Jun 1, 2021
    Posts:
    5
    After upgrading to Unity 2020.22.3f1 some of our shaders have stopped working on iOS builds. Most notably some colors will tend to white and some degree of transparency is lost.

    This is an example of a shader that used to work fine for basic shadow decals and now turns whitish:

    Code (CSharp):
    1. Shader "Custom/Shadow Decal" {
    2.     Properties
    3.     {
    4.         _MainTex ("Texture", 2D) = "white" {}
    5.         _Fade ("Fade", Float) =  1.0
    6.     }
    7.     SubShader
    8.     {
    9.         Tags { "RenderType"="Transparent" }
    10.         ZTest Always
    11.         ZWrite Off
    12.         LOD 100
    13.        
    14.         ZTest Always
    15.         ZWrite Off
    16.  
    17.         Blend SrcAlpha OneMinusSrcAlpha
    18.        
    19.         Pass
    20.         {
    21.             CGPROGRAM
    22.             #pragma vertex vert
    23.             #pragma fragment frag
    24.             // make fog work
    25.             #pragma multi_compile_fog
    26.            
    27.             #include "UnityCG.cginc"
    28.  
    29.             struct appdata
    30.             {
    31.                 float4 vertex : POSITION;
    32.                 float2 uv : TEXCOORD0;
    33.             };
    34.  
    35.             struct v2f
    36.             {
    37.                 float2 uv : TEXCOORD0;
    38.                 UNITY_FOG_COORDS(1)
    39.                 float4 vertex : SV_POSITION;
    40.  
    41.             };
    42.  
    43.             sampler2D _MainTex;
    44.             float4 _MainTex_ST;
    45.             fixed _Fade;
    46.  
    47.            
    48.             v2f vert (appdata v)
    49.             {
    50.                 v2f o;
    51.                 o.vertex = UnityObjectToClipPos(v.vertex);
    52.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    53.                 UNITY_TRANSFER_FOG(o,o.vertex);
    54.                 return o;
    55.             }
    56.            
    57.             fixed4 frag (v2f i) : SV_Target
    58.             {
    59.                 // sample the texture
    60.                 fixed4 col = tex2D(_MainTex, i.uv);
    61.  
    62.                 col.a = (1.0 - col.r) * _Fade;
    63.                 col.rgb = fixed3(0.0, 0.0, 0.0);
    64.                
    65.                 UNITY_APPLY_FOG(i.fogCoord, col);
    66.                
    67.                 return col;
    68.             }
    69.             ENDCG
    70.         }
    71.     }
    72. }
    73.  
    Any ideas what this could depend upon?
     
    epernigo likes this.
  2. mvaz_p

    mvaz_p

    Joined:
    Aug 22, 2018
    Posts:
    80
  3. xyome

    xyome

    Joined:
    Jul 4, 2014
    Posts:
    9
    Try to put your device in Dark Mode and see if it helps.
     
  4. arom1989

    arom1989

    Joined:
    Jun 1, 2021
    Posts:
    5
    Hi, thank you @xyome. Strangely that actually works but in the end, since we were pressed for time and could not downgrade anymore, we ended up resorting to a replacement of the fragment shaders that wouldn't work with some basic surface shaders that did roughly the same things. That's how we "solved" the issue, at least for now.