Shaderlab片断剪切/裁剪定义:image.png

    1. Shader "WSP/FrameWork7"
    2. {
    3. Properties
    4. {
    5. _Tex("角色贴图",2D) = "White" {}
    6. _Color("被击中颜色",Color) = (0,0,0,0)
    7. _Dissolve("溶解遮罩",2D) = "White" {}
    8. _Clip("裁剪数值",Range(0,1)) = 0
    9. }
    10. SubShader
    11. {
    12. pass
    13. {
    14. CGPROGRAM
    15. #pragma vertex vert
    16. #pragma fragment frag
    17. #include "UnityCG.cginc"
    18. sampler2D _Tex;
    19. fixed4 _Color;
    20. sampler2D _Dissolve;
    21. fixed _Clip;
    22. struct appdata
    23. {
    24. float4 vertex :POSITION;
    25. float4 uv :TEXCOORD;
    26. };
    27. struct v2f
    28. {
    29. float4 pos :POSITION;
    30. float4 uv :TEXCOORD;
    31. };
    32. v2f vert(appdata v)
    33. {
    34. v2f o;
    35. o.pos = UnityObjectToClipPos(v.vertex);
    36. o.uv = v.uv;
    37. return o;
    38. }
    39. fixed4 frag(v2f i):SV_TARGET
    40. {
    41. fixed4 c;
    42. fixed4 tex = tex2D(_Tex,i.uv);
    43. c = tex;
    44. c += _Color;
    45. fixed4 dissolveTex = tex2D(_Dissolve,i.uv);
    46. clip(dissolveTex-_Clip);
    47. return c;
    48. }
    49. ENDCG
    50. }
    51. }
    52. }

    因为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);