Shader贴图混合

A图片的颜色值,B图片的透明度

Shader "DragonPeng/Blend"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _AlphaTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
	        Blend SrcAlpha OneMinusSrcAlpha
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                float2 uv1 : TEXCOORD1;
            };
            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;		//主图片的贴图
            float4 _MainTex_ST;		//主图片的Tiling和Offset参数

            sampler2D _AlphaTex; 	//辅图片的贴图
            float4 _AlphaTex_ST;	//辅图片的Tiling和Offset参数

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                //设置主贴图的uv数据
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                //设置辅贴图的uv数据
                o.uv1 = TRANSFORM_TEX(v.uv, _AlphaTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }
            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col0 = tex2D(_MainTex, uv);
                fixed4 col1 = tex2D(_AlphaTex, i.uv1);

                fixed4 col;
                col.rbg = col0.rbg;		//设置主贴图的颜色值
                col.a = col1.a;			//设置辅贴图的透明度

                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
            ENDCG
        }
    }
}

贴图属性的混合(相乘)

Shader "DragonPeng/Blend"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _AlphaTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
	        Blend SrcAlpha OneMinusSrcAlpha
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                float2 uv1 : TEXCOORD1;
            };
            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;		//主图片的贴图
            float4 _MainTex_ST;		//主图片的Tiling和Offset参数

            sampler2D _AlphaTex; 	//辅图片的贴图
            float4 _AlphaTex_ST;	//辅图片的Tiling和Offset参数

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                //设置主贴图的uv数据
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                //设置辅贴图的uv数据
                o.uv1 = TRANSFORM_TEX(v.uv, _AlphaTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }
            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col0 = tex2D(_MainTex, uv);
                fixed4 col1 = tex2D(_AlphaTex, i.uv1);

                fixed4 col;
                col.rbg = col0.rbg * col1.rbg;		//贴图的颜色混合
                col.a = col0.a * col1.a;			//贴图的透明度混合
                /*
                //与上述的分开相乘的效果一致
                col = col0 * col1;					//贴图属性的混合(相乘)
                */

                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
            ENDCG
        }
    }
}

混合类型

Shader "DragonPeng/Blend"
{
    Properties
    {
    }
    SubShader
    {
        Pass
        {
        	//正常的混合效果(透明度混合)
	        Blend SrcAlpha OneMinusSrcAlpha
	        //颜色值添加柔和效果,透明度反差(即:透明度为1是显示的效果为0)
	        Blend OneMinusSrcAlpha One
	        //颜色值相乘,忽略透明度的变化
	        Blend DstColor Zero
	        Blend DstColor SrcColor
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值