AC是指Alpha Cutout(又叫Alpha Test)即透明裁剪。通过clip函数直接移除<某个值的像素点。AC轮廓清晰,如果物体有排序问题通常使用AC,缺点是性能差。用于这种模型边缘复杂,仅通过贴图来做边缘的物体,可以看到树叶的前后关系都是正确的:
![](https://i-blog.csdnimg.cn/blog_migrate/cc1ae20ff4ea67dda9d3c195a4df216a.png)
image.png
![](https://i-blog.csdnimg.cn/blog_migrate/6ec62f764af3a83ae7d9271bf3640dac.png)
image.png
AB是指Alpha Blend即透明混合,边缘更柔和,但物体前后顺序错误,一般特效打底用。
![](https://i-blog.csdnimg.cn/blog_migrate/fb7df350997d56568e3a9618a53bf245.png)
image.png
AD是指Addtive 与AB类似,起到提亮作用,大多数特效使用此方法。
![](https://i-blog.csdnimg.cn/blog_migrate/085f032dbf0cabc7c0ad679ac3cc9858.png)
image.png
AC代码:
Shader "Unlit/AC"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Cutoff("透切阈值",Range(0.0,1.0))=0.5
}
SubShader
{
Tags{
"RenderType"="TransparentCutout"
"ForceNoShadowCasting"="True"
"IgnoreProjector"="True"
}
Cull Off
Pass
{
Tags{
"LightMode"="ForwardBase"
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma muti_compile_fwdbase_fullshadows
#pragma target 3.0
#include "UnityCG.cginc"
sampler2D _MainTex;float4 _MainTex_ST;
half _Cutoff;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv,_MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
half opacity=col.a;
clip(opacity-_Cutoff);
return float4(col.rgb,1.0);
}
ENDCG
}
}
}
AB代码:
Shader "Unlit/AB"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags{
"Queue"="Transparent"
"RenderType"="TransparentCutout"
"ForceNoShadowCasting"="True"
"IgnoreProjector"="True"
}
// Cull Off
Pass
{
Tags{
"LightMode"="ForwardBase"
}
//Src表示源,OneMinus表示1-,OneMinusSrcAlpha表示1-源的alpha
//混合模式
//源:One 或者 SrcAlpha
//目标:OneMinusSrcAlpha
Blend One OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma muti_compile_fwdbase_fullshadows
#pragma target 3.0
#include "UnityCG.cginc"
sampler2D _MainTex;float4 _MainTex_ST;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv,_MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
}
AD代码:
Shader "Unlit/AD"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags{
"Queue"="Transparent"
"RenderType"="TransparentCutout"
"ForceNoShadowCasting"="True"
"IgnoreProjector"="True"
}
// Cull Off
Pass
{
Tags{
"LightMode"="ForwardBase"
}
//Src表示源,OneMinus表示1-,OneMinusSrcAlpha表示1-源的alpha
//混合模式
//源:One
//目标:One
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma muti_compile_fwdbase_fullshadows
#pragma target 3.0
#include "UnityCG.cginc"
sampler2D _MainTex;float4 _MainTex_ST;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv,_MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
}