Unity3D 透明物體Shader

zsdeus133發表於2018-05-07

透明物體的shader

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Unlit/NewUnlitShader"
{
    Properties{
        _AlphaScale("AlphaScale",Range(0,1)) = 0.2
    }

    SubShader
    {
        Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout" }
        Pass
        {
            Tags { "LightMode"="ForwardBase" }

            ZWrite Off                          // 關閉深度寫入
            Blend SrcAlpha OneMinusSrcAlpha     // 開啟混合模式。SrcAlpha:源顏色混合因子,OneMinusSrcAlpha:已存在顏色混合因子

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

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

            fixed _AlphaScale;

            v2f vert (
                float4 vertex : POSITION,
                float2 uv : TEXCOORD0
                )
            {
                v2f o;
                o.pos = UnityObjectToClipPos(vertex);
                o.uv = uv;
                return o;

            }

            fixed4 frag (v2f i) : SV_Target
            {
                return fixed4(i.uv, 0, _AlphaScale);
            }
            ENDCG
        }
    }
}

效果

這裡寫圖片描述

相關文章