1.颜色叠加
Blend SrcAlpha One
混合结果 = 源颜色的 alpha 通道 * 目标颜色的 alpha 通道 + 源颜色的颜色通道
2.shader代码
Shader "Custom/Blend2"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Alpha("Alpha",range(0,1)) = 1
}
SubShader
{
Tags { "RenderType"="Transparent" }
LOD 100
Pass
{
Blend SrcAlpha One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
fixed4 vcol : COLOR;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
fixed4 fcol : COLOR;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _Alpha;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.fcol = v.vcol;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = fixed4(1,0,0,_Alpha);
return col;
}
ENDCG
}
}
}
3.效果