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;float4 _Dissolve_ST;
    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.xy = v.uv.xy;
    37. //o.uv.zw = v.uv *_Dissolve_ST.xy+_Dissolve_ST.zw;
    38. o.uv.zw = TRANSFORM_TEX(v.uv,_Dissolve);
    39. return o;
    40. }
    41. fixed4 frag(v2f i):SV_TARGET
    42. {
    43. fixed4 c;
    44. fixed4 tex = tex2D(_Tex,i.uv.xy);
    45. c = tex;
    46. c += _Color;
    47. fixed4 dissolveTex = tex2D(_Dissolve,i.uv.zw);
    48. clip(dissolveTex-_Clip);
    49. return c;
    50. }
    51. ENDCG
    52. }
    53. }
    54. }*

    image.png
    Tiling x y
    Offset x y

    sampler2D _Dissolve; float4 _Dissolve_ST;

    _ST红色标注后,我们就可以在代码中去使用和控制Tiling和Offset;

    Tiling: 瓷砖式显示,并列式窗口;也就是贴图的重复度;xy分别代表他u、v的重复次数;
    Offset:偏移;xy分别代表u、v的偏移数值;

    UV本身是二维向量,所以通过声明 float4 _Dissolve_ST 来代表Tiling和Offset
    其中xy代表TIling的xy,zw代表offset的xy
    在贴图采样时使用以下方法:
    TRANSFORM_TEX(uv,_Name) = v.uv *_Dissolve_ST.xy+_Dissolve_ST.zw;

    用来实现贴图UV的Tiling与Offset在暴露属性面板上的实时控制
    image.pngimage.png
    xr=1 , r=1 xr=2x , r=2