美文网首页
Unity UI图片蒙版shader

Unity UI图片蒙版shader

作者: 独步江雪 | 来源:发表于2020-12-12 20:00 被阅读0次
image.png
image.png image.png
Shader "Hidden/NewImageEffectShader"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Mask ("Mask", 2D) = "white" {}
    }
    SubShader
    {      
        Tags
        {
            "RenderType"="Transparent" "Queue"="Transparent" 
        }
        Blend SrcAlpha OneMinusSrcAlpha
        // No culling or depth
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

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

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }

            sampler2D _MainTex;
            sampler2D _Mask;
            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                fixed4 mask = tex2D(_Mask, i.uv);
                // just invert the colors
              
                col.a *=  mask.r;
                return col;
            }
            ENDCG
        }
    }
}

相关文章

网友评论

      本文标题:Unity UI图片蒙版shader

      本文链接:https://www.haomeiwen.com/subject/nmsygktx.html