Problem with UI Mask on Android 5 since Unity 2018.3.x

Hi
Since Unity 2018.3.x UI Mask doesn’t work on Android 5.0.1.It doesn’t draw itself and its children.
Tested on Samsung Galaxy S4 GT-I9500 Android 5.0.1
On Unity 2018.2.x and older everything’s ok with mask. It has the issue only on Unity 2018.3.x and with Android 5

How can reproduce the issue.

  1. Just create a new project in Unity 2018.3.x (we used 2018.3.6 and 2018.3.7)
  2. Switch target on Android
  3. In the new empty scene create Canvas, then create UI Mask into the Canvas.
  4. Create UI Image as a child object of Mask. Any combinations.
  5. Build the project for Android and test on Android version 5

2018.3.8 has this issue too

Hi. I’ve replaced clip function in all shaders and it seems working.
From:

clip(%value%);

To:

bool clip = (%value%) < 0.0f;
clip = (int(clip) * int(0xffff))==0;
if(!clip)
   discard;

It looks like a bug in unity.

1 Like

Hmm, I’ll try it!
Thanks a lot Rom4ikq

Could you please submit a bug-report as described in this document:

It’s important that you report these issues together with a reproduction project if you want them to get fixed. If you don’t do it, it might be a long time until someone else reports them or until Unity Technologies find them.

After you submitted the bug-report, you receive a confirmation email with a bug-report Case number. You can post this Case number here (in this forum thread) for Unity staff to pick up, in case they see it.

I already done it: https://fogbugz.unity3d.com/default.asp?1134858_u5l2qgp9bepgsap3
Is it needed to Rom4ikq done the same?

1 Like

Same issue here since upgrading a project from 2018.2 to 2018.3. We experience a few Android devices not drawing scrollview content and other Mask clipped content anymore. OS version 4.4.2 - 5.x (not sure about newer versions). Looks like OpenGLES2 affected only, x86 and arm.

Removing the mask component makes the scrollview render correctly on this affected devices

I got same issue. Did they tell anything on fixing it ?

What was the version of 2018.2 that this didn’t occur on? I reproduced the issue with your project on 2018.2.0

With which devices did you experience this issue? (Please note the GPU’s of the devices)

Just reproduced on this devices:

  • Unity 2018.3.10f1, LENOVO Lenovo A3000-H, PowerVR SGX 544MP, Android 4.4.2
  • Unity 2018.3.9f1, ASUS ASUS_T00J, PowerVR SGX 544MP2, Android 4.4.1

any many more PowerVR 544 MP devices…

Just to note:

  • There was no problem with 2018.2.20f1
  • Everything renders correctly again with 2018.3.9 / 2018.3.10 as soon as we disable the Mask components

We got 3 devices reported. All of them are using PowerVR 544

2018.2.21 is ok on my tested device (Samsung Galaxy S4 GT-I9500 Android 5.0.1)

Guys please vote this issue here https://issuetracker.unity3d.com/issues/android-gles2-image-inside-a-ui-mask-is-not-visible-on-some-android-devices

That’s a major bug, and very hard to find the causing issue, or a term to search (simply my whole UI wouldnt draw with no log messages, I didnt know where to look, found this by luck), that’s why this thread is not flooded with complains.

Please Unity team prioritize this issue, it seems it is being ignored by you guys (20+ days since this thread started and it’s a major bug!). I cant update my game in production due to this bug. If I knew about this bug last week I would annoy you guys at GDC to get this fixed.

Yes, also rather major for us. We restructure our project to make use of nested prefabs, so can’t go back to 2018.2 and have a lot of users complaining with no chance to fix this by ourself…

I just noticed the issue is from DECEMBER… holy ****, we’re screwed

@Rom4ikq can you explain a bit more how to do the solution? Im not familiar with shaders

@Riddik have you tested the solution? Did it work?

Not yet.

Need to create material with this shader. Add material to the image component, the nearest mask component.

// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)

Shader "Custom/UI/Default"
{
    Properties
    {
        [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
        _Color ("Tint", Color) = (1,1,1,1)

        _StencilComp ("Stencil Comparison", Float) = 8
        _Stencil ("Stencil ID", Float) = 0
        _StencilOp ("Stencil Operation", Float) = 0
        _StencilWriteMask ("Stencil Write Mask", Float) = 255
        _StencilReadMask ("Stencil Read Mask", Float) = 255

        _ColorMask ("Color Mask", Float) = 15

        [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
    }

    SubShader
    {
        Tags
        {
            "Queue"="Transparent"
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
            "PreviewType"="Plane"
            "CanUseSpriteAtlas"="True"
        }

        Stencil
        {
            Ref [_Stencil]
            Comp [_StencilComp]
            Pass [_StencilOp]
            ReadMask [_StencilReadMask]
            WriteMask [_StencilWriteMask]
        }

        Cull Off
        Lighting Off
        ZWrite Off
        ZTest [unity_GUIZTestMode]
        Blend SrcAlpha OneMinusSrcAlpha
        ColorMask [_ColorMask]

        Pass
        {
            Name "Default"
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 2.0

            #include "UnityCG.cginc"
            #include "UnityUI.cginc"

            #pragma multi_compile __ UNITY_UI_CLIP_RECT
            #pragma multi_compile __ UNITY_UI_ALPHACLIP

            struct appdata_t
            {
                float4 vertex   : POSITION;
                float4 color    : COLOR;
                float2 texcoord : TEXCOORD0;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct v2f
            {
                float4 vertex   : SV_POSITION;
                fixed4 color    : COLOR;
                float2 texcoord  : TEXCOORD0;
                float4 worldPosition : TEXCOORD1;
                UNITY_VERTEX_OUTPUT_STEREO
            };

            sampler2D _MainTex;
            fixed4 _Color;
            fixed4 _TextureSampleAdd;
            float4 _ClipRect;
            float4 _MainTex_ST;

            v2f vert(appdata_t v)
            {
                v2f OUT;
                UNITY_SETUP_INSTANCE_ID(v);
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
                OUT.worldPosition = v.vertex;
                OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);

                OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);

                OUT.color = v.color * _Color;
                return OUT;
            }

            fixed4 frag(v2f IN) : SV_Target
            {
                half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;

                #ifdef UNITY_UI_CLIP_RECT
                color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
                #endif

                #ifdef UNITY_UI_ALPHACLIP
               
                bool a = color.a - 0.001 < 0.0f;
                a = (int(a) * int(0xffff))==0;
                if(!a)
                    discard;
             
                #endif

                return color;
            }
        ENDCG
        }
    }
}