代码之家  ›  专栏  ›  技术社区  ›  Sergio Viudes

将“精灵alpha color component”设置为小于1的值是否会影响性能?

  •  1
  • Sergio Viudes  · 技术社区  · 8 年前

    我一直认为使用透明精灵会对性能产生影响,但在Unity中使用overdraw场景模式时,我发现如果使用不透明精灵,或使用alpha<1.

    1 回复  |  直到 8 年前
        1
  •  1
  •   JeanLuc    8 年前

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

    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"
     }
    
    推荐文章