Shaderlab片断剪切/裁剪定义:
Shader "WSP/FrameWork7"
{
Properties
{
_Tex("角色贴图",2D) = "White" {}
_Color("被击中颜色",Color) = (0,0,0,0)
_Dissolve("溶解遮罩",2D) = "White" {}
_Clip("裁剪数值",Range(0,1)) = 0
}
SubShader
{
pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _Tex;
fixed4 _Color;
sampler2D _Dissolve;
fixed _Clip;
struct appdata
{
float4 vertex :POSITION;
float4 uv :TEXCOORD;
};
struct v2f
{
float4 pos :POSITION;
float4 uv :TEXCOORD;
};
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag(v2f i):SV_TARGET
{
fixed4 c;
fixed4 tex = tex2D(_Tex,i.uv);
c = tex;
c += _Color;
fixed4 dissolveTex = tex2D(_Dissolve,i.uv);
clip(dissolveTex-_Clip);
return c;
}
ENDCG
}
}
}
因为Clip=(x), x<0时会进行裁剪剔除 那么通过 Clip = (遮罩贴图 - _Clip) 进行判断。通过控制_Clip的数值来决定最终遮罩裁剪值是否<0;
(x)
所以先定义Clip的值;
_Clip(“裁剪数值”,Range(0,1)) = 0
把值限定在一个合适的范围内并默认为0
然后定义一张溶解遮罩贴图;
_Dissolve(“溶解遮罩”,2D) = “White” {}
在CGPROGRAM进行声明
sampler2D _Dissolve;
fixed _Clip;
然后再片断着色器中进行纹理采样;
fixed4 dissolveTex = tex2D(_Dissolve,i.uv);
最终进行Clip值判断运算
Clip = (dissolveTex - _Clip);