【转】使用UGUI中的Mask的时候,如何正确裁减非默认材质的UI对象
转自:http://blog.csdn.net/ykmzy/article/details/51366396
mask组件通过对StencilMaterial.Add方法得查看我们知道该方法在对目标材质得_StencilOp,_StencilComp等等属性进行操作,这样操作后才可以实现它得模板裁剪。我们自定义的Shader一般没有这几个属性,所以我们在自己的shader中添加如下代码便可以实现自定义材质得正确Mask了
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
............................................................................
Stencil {
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
然后在shader面板调一调_StencilComp属性就可以实现遮罩了