Unity shader problem on Xiaomi 2s

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.