EDIT: Turns out this is actually rendering fine on the Google Pixel devices mentioned (when on a material assigned to a mesh surface). The problem seems to be that when I use it as the material in a UI image component, it fails to render on the Pixel devices. Still not sure why though. :[
Edit #2: FIXED - Turns out the fix was setting the render mode from screen space ‘overlay’ to ‘camera’ in the canvas. For some reason this allows it to work on Pixel devices.
I’m using a shader to create a transparent overlay image from a RenderTexture material. This is then stretched over the UI to create a soft masking effect. The problem is that, although this works in the editor, my Samsung Chromebook and Huawei tablet, it doesn’t work on any of our Google Pixel devices (2XL and 4A). In the latter, it simply doesn’t render the image at all, making the scene look flat.
The shader code is below. The image shows the actual outcome in the editor along with the overlay UI image that should be produced (on the aforementioned devices). Any ideas why this wouldn’t be working on Google Pixel smartphones?
As seen in the editor and Chromebook/Huawei Media tablet
Shader Code:
Shader "Custom/AlphaMaskIII" {
Properties{
_Color("Color", Color) = (1,1,1,1)//
_AlphaVal("AlphaVal", Range(0,1)) = 1.0
_MainTex("MainTex (Sprite)", 2D) = "white" {}
_AlphaTex("AlphaTex (R)", 2D) = "white" {}
}
SubShader{
Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent"}
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
float2 texcoordA : TEXCOORD1; // alpha uv
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
half2 texcoordA : TEXCOORD1; // alpha uv
};
sampler2D _MainTex;
sampler2D _AlphaTex;
float _AlphaVal;
float4 _MainTex_ST;
float4 _AlphaTex_ST; // alpha uv
fixed4 _Color;//
v2f vert(appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
o.texcoordA = TRANSFORM_TEX(v.texcoordA, _AlphaTex); // alpha uv
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 main = tex2D(_MainTex, i.texcoord) * _Color;
fixed4 alph = tex2D(_AlphaTex, i.texcoordA); // alpha uv
return fixed4(main.r, main.g, main.b, (main.a*alph.r*_AlphaVal));
}
ENDCG
}
}
}