Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Possible Bug UI.RawImage Android

Discussion in 'UGUI & TextMesh Pro' started by Idual, Feb 27, 2024.

  1. Idual

    Idual

    Joined:
    Mar 11, 2015
    Posts:
    14
    Morning,

    I'm trying to show a damage bar in my game using UI.RawImage with a RenderTexture and a custom shader.
    It works perfectly in the editor but fails on an android build.

    Here's a video of in on android:



    It's the blue box that's broken.

    It also works on Android if I remove the shader. Here's the shader:

    Shader "Unlit/ReverseAlpha"
    {
    Properties
    {
    _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    LOD 100

    Blend SrcAlpha OneMinusSrcAlpha

    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag

    #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;

    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
    {
    // sample the texture
    fixed4 col = tex2D(_MainTex, i.uv);
    //reverse alpha

    col.b=col.a = 1 - col.r;
    col.r=col.g = 0.3;

    return col;
    }
    ENDCG
    }
    }
    }


    Not exactly complicated.

    Can anyone see anything wrong?

    Given the fact that it works perfectly in the editor should I file a bug report?
     
  2. TeorikDeli

    TeorikDeli

    Joined:
    Apr 6, 2014
    Posts:
    152
  3. Idual

    Idual

    Joined:
    Mar 11, 2015
    Posts:
    14
    Last edited: Feb 27, 2024
  4. TeorikDeli

    TeorikDeli

    Joined:
    Apr 6, 2014
    Posts:
    152
    It's the Unity UI & TextMesh Pro forums. Thread was in UI Toolkit forums, which is different.
     
  5. Idual

    Idual

    Joined:
    Mar 11, 2015
    Posts:
    14
    Ok. Thanks. I see it's already been moved so thanks for that as well.
     
    TeorikDeli likes this.