unity3d Shader:Ugui Text 穿透模型与背景显示

Shader代码

Shader "CustomUI/FirstText"
{
    Properties
    {
        _MainTex ("Font Texture", 2D) = "white" {}  
            //MASK SUPPORT ADD
    _StencilComp("Stencil Comparison", Float) = 8
        _Stencil("Stencil ID", Float) = 0
        _StencilOp("Stencil Operation", Float) = 0
        _StencilWriteMask("Stencil Write Mask", Float) = 255
        _StencilReadMask("Stencil Read Mask", Float) = 255
        _ColorMask("Color Mask", Float) = 15
        //MASK SUPPORT END
    }


    SubShader {  
        Tags { "Queue" = "Overlay"
        "IgnoreProjector" = "True"
        "RenderType" = "Transparent"
        "PreviewType" = "Plane" 
        "CanUseSpriteAtlas" = "True" }  
        //MASK SUPPORT ADD
        Stencil
    {
        Ref[_Stencil]
        Comp[_StencilComp]
        Pass[_StencilOp]
        ReadMask[_StencilReadMask]
        WriteMask[_StencilWriteMask]
    }
        ColorMask[_ColorMask]
        //MASK SUPPORT END
       Cull Off
        Lighting Off
        ZWrite Off
        ZTest Always
        Fog{ Mode Off }
        Blend SrcAlpha OneMinusSrcAlpha
        Pass {  
            SetTexture [_MainTex] {  
                combine primary, texture * primary  
            }  
        }  
    }  
}

最终效果
unity3d Shader:Ugui Text 穿透模型与背景显示_第1张图片
unity3d Shader:Ugui Text 穿透模型与背景显示_第2张图片
实现字卡在模型中能穿透显示

当字为模型的背景时:即世界坐标中,字在前,模型在后,但是模型能遮挡字

Shader "CustomUI/BgText"
{
    Properties
    {
        _MainTex("Font Texture", 2D) = "white" {}
    //MASK SUPPORT ADD
    _StencilComp("Stencil Comparison", Float) = 8
        _Stencil("Stencil ID", Float) = 0
        _StencilOp("Stencil Operation", Float) = 0
        _StencilWriteMask("Stencil Write Mask", Float) = 255
        _StencilReadMask("Stencil Read Mask", Float) = 255
        _ColorMask("Color Mask", Float) = 15
        //MASK SUPPORT END
    }


        SubShader{
        Tags{ "Queue" = "Background"
        "IgnoreProjector" = "True"
        "RenderType" = "Transparent"
        "PreviewType" = "Plane"
        "CanUseSpriteAtlas" = "True" }

        //MASK SUPPORT ADD
        Stencil
    {
        Ref[_Stencil]
        Comp[_StencilComp]
        Pass[_StencilOp]
        ReadMask[_StencilReadMask]
        WriteMask[_StencilWriteMask]
    }
        ColorMask[_ColorMask]
        //MASK SUPPORT END


        Cull Off
        Lighting Off
        ZWrite Off
        ZTest Always
        Fog{ Mode Off }
        Blend SrcAlpha OneMinusSrcAlpha
        Pass{
        //Color[_Color]
        SetTexture[_MainTex]{
        combine primary, texture * primary
    }
    }
    }
}

你可能感兴趣的:(Unity3D实用技术笔记,UGUI,Unity3d,Shader,Unity3d,Shader,UGUI)