将 Sprite alpha 颜色分量设置为 < 1 的值是否会对性能产生影响?

Does setting Sprite alpha color component to a value < 1 have a performance impact?

我一直认为使用透明精灵会对性能产生影响,但是在Unity中使用透支场景模式,我发现如果我使用不透明精灵,或者alpha < 1的精灵,也会有同样的透支。

我错了吗?

Unity.2D 和 Unity.UI 的默认着色器将所有内容(包括不透明精灵)绘制为透明几何体,除非您使用 material 和不透明着色器。

更新 1:

这是我为最小化透支而编写的不透明着色器,但不要指望它适用于所有情况。不透明几何体将首先渲染,透明几何体在顶部。

Shader "Custom/Opaque UI"
 {  
    Properties
    {
        _Color("Color", Color) = (1,1,1,1)
        _MainTex ("Texture", 2D) = "white" {}
    }

    SubShader
    {
        Tags 
        { 
            "RenderType" = "Opaque" 
        }

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            sampler2D _MainTex;
            half3 _Color;

            struct v2f {
                float4 pos : SV_POSITION;
                float2 uv : TEXCOORD0;
                float4 color : COLOR;
            };

            float4 _MainTex_ST;

            v2f vert (appdata_full v)
            {
                v2f o;
                o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
                o.color = v.color;
                return o;
            }

            half4 frag (v2f i) : COLOR
            {
                half4 color_MainTex = tex2D (_MainTex, i.uv);
                return color_MainTex * i.color;
            }
            ENDCG
        }
    }
    FallBack "UI/Default"
 }