Unity ||如何使两个图像相交的区域透明?

问题描述 投票:0回答:1

我正在开发游戏,该游戏的主要目的是两个黑色形状重叠时重叠的部分是透明的。我在互联网上找到了一个着色器,并正在使用它。该着色器使我们能够为两个形状的交点分配颜色,但是我不能使其透明。

“

Shader "Unlit/Stencil"
{
    Properties
    {
        _MainTex("Texture", 2D) = "white" {}
    }
        SubShader
    {
        Tags {"Queue" = "Transparent" "RenderType" = "Opaque"}
        LOD 100

        Pass
        {
            Stencil {
                Ref 0
                Comp Equal
                Pass IncrSat
                Fail IncrSat
            }

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
            };

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

            fixed4 frag(v2f i) : SV_Target
            {
                fixed4 col = fixed4(0.0, 0.0, 0.0, 0.0);
                return col;
            }
            ENDCG
        }

        Pass
        {
            Stencil {
                Ref 1
                Comp Less
            }

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
            };

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

            fixed4 frag(v2f i) : SV_Target
            {
                fixed4 col = fixed4(1.0, 1.0, 1.0, 0.0);

                return col;
            }
            ENDCG
        }

        Pass
        {
            Stencil {
                Ref 2
                Comp Less
            }

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
            };

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

            fixed4 frag(v2f i) : SV_Target
            {
                fixed4 col = fixed4(0.0, 0.0, 0.0, 0.0);
                return col;
            }
            ENDCG
        }
    }
}
unity3d shader intersection
1个回答
0
投票

[走吧,请记住,这是我第一次使用模板,所以我做的事情可能不是最佳的。但它可以根据您的要求使用精灵。

https://gist.github.com/ronrejwan/f5b42ae2e1033aa24e4ba0174deed014

© www.soinside.com 2019 - 2024. All rights reserved.