A very simple effect of clipping a picture with mask:
mark[
The picture is cropped:
The correct effect:
On the millet 2s test, one of the millet 2s appeared flower screen:
Phone Model:
Shader as follows:
Shader "Ui/transparent Masked"
{
Properties
{
_maintex ("Base (RGB)", 2D) = "Black" {}
_mask ("Base (RGB Mask)", 2D) = "White" {}
}
Subshader
{
LOD 200
Tags
{
"Queue" = "Transparent"
"Ignoreprojector" = "True"
"Rendertype" = "Transparent"
}
Pass
{
Cull OFF
Lighting OFF
Zwrite OFF
Fog {Mode Off}
Offset-1,-1
Blend Srcalpha Oneminussrcalpha
Cgprogram
#pragma vertex vert
#pragma fragment Frag
#include "Unitycg.cginc"
Sampler2d _maintex;
Sampler2d _mask;
FLOAT4 _maintex_st;
struct appdata_t
{
FLOAT4 vertex:position;
FLOAT2 texcoord:texcoord0;
FLOAT2 Texcoord1:texcoord1;
Fixed4 Color:color;
};
struct V2F
{
FLOAT4 vertex:sv_position;
FLOAT2 texcoord:texcoord0;
FLOAT2 Texcoord1:texcoord1;
Fixed4 Color:color;
};
v2f o;
v2f Vert (appdata_t v)
{
O.vertex = Mul (UNITY_MATRIX_MVP, V.vertex);
O.texcoord = V.texcoord;
O.texcoord1 = V.texcoord1;
O.color = V.color;
return o;
}
Fixed4 Frag (v2f in): COLOR
{
Fixed4 col = tex2d (_maintex, In.texcoord) * IN.COLOR;
Col.a=tex2d (_mask, in.texcoord1). R;
return col;
}
Endcg
}
}
}
The following two methods of modification can make the display return to normal:
Change Method 1: Use float precision
Change Frag to:
Fixed4 Frag (v2f in): COLOR
{
Float4 col = tex2d (_maintex, In.texcoord) * IN.COLOR;
Col.a=tex2d (_mask, in.texcoord1). R;
return col;
}
Method 2: Fixed accuracy is still used
Change Frag to:
Fixed4 Frag (v2f in): COLOR
{
Fixed4 col = tex2d (_maintex, In.texcoord) * IN.COLOR;
Fixed alpha=tex2d (_mask, in.texcoord1). R;
Fixed4 finalcol=col*fixed4 (1,1,1,alpha);
return finalcol;
}
Add:
Change to:
Fixed4 Frag (v2f in): COLOR
{
Fixed4 col = tex2d (_maintex, In.texcoord) * IN.COLOR;
Fixed alpha=tex2d (_mask, In.texcoord1). G;
Fixed4 finalcol=fixed4 (Col.rgb,alpha);
return finalcol;
}
Or not.
Unity shader problem on Xiaomi 2s