码迷,mamicode.com
首页 > 移动开发 > 详细

unity shader在小米2s上的问题

时间:2016-07-05 14:14:05      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:

一个很简单的用mask裁剪图片的效果:

mask:

技术分享 

被裁剪图片:

技术分享

正确的效果:

技术分享

在小米2s上测,其中有一台小米2s出现花屏:

技术分享

手机型号:

技术分享

shader如下:

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
        }
    }
}

以下两种修改方法可以使显示恢复正常:


改法1:改用float精度

将frag改为:

 fixed4 frag (v2f IN) : COLOR
            {
            
                float4 col = tex2D(_MainTex, IN.texcoord) * IN.color;
                col.a=tex2D(_Mask, IN.texcoord1).r;
                return col;
            }

改法2:仍使用fixed精度

将frag改为:

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

补充:

改成:

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

也不行。

unity shader在小米2s上的问题

标签:

原文地址:http://www.cnblogs.com/wantnon/p/5643270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!