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
#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;
sampler2D _AlphaTex;
float4 _AlphaTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
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
#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;
sampler2D _AlphaTex;
float4 _AlphaTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
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;
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
混合类型
Shader "DragonPeng/Blend"
{
Properties
{
}
SubShader
{
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
Blend OneMinusSrcAlpha One
Blend DstColor Zero
Blend DstColor SrcColor
}
}
}