UI,image直接使用unity提供的outline,发现边缘是这样的
看代码,outline就是把shadow上下左右多画了4遍
所以说,如果我继承shadow,按照一个圆来画,感觉就outline的边缘就会圆滑一些
for (int i = 0; i < outlineTime; i++)
{
if (i != 0)
{
start = end;
end = verts.Count;
}
float percent = (float)i / (float)outlineTime;
x = radius * Mathf.Sin(percent * Mathf.PI * 2f);
y = radius * Mathf.Cos(percent * Mathf.PI * 2f);
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, x, y);
}
左边是重复了32遍,右边是unity的outline,可以看到左边的三角形数量也蹭蹭涨。
感觉这么着肯定不行,但是先记录一下
同时为了外描边颜色可以覆盖而不是使用图片颜色,重写ApplyShadowZeroAlloc方法,把外描边新增的网格的uv1记录一下,我这随便设了一下。
vt.uv1 = Vector4.one;
需要把canvas的这个属性修改一下。
然后新建ui的shader和材质,复制的这个UI-Default.shader
在shader里增加_OutlineColor属性,不用outline也可以用顶点颜色吧,这块没弄
在frag return color之前
if(IN.uv1.x==1){
color = fixed4(_OutlineColor.r,_OutlineColor.g,_OutlineColor.b,_OutlineColor.a*color.a);
}
实际项目不建议这么搞
3d的outline 网上找到的例子https://github.com/rickomax/globaloutline