树叶边缘渲染一般的做法就是使用alpha test,但这样做在边缘上会出现一些很“碎”的效果,特别是离摄像机远的时候。
如果要边缘效果好,就要采用alpha blend的方式,但这种方法有排序的问题,会造成前后错乱。
之前看斗战神的草,发现边缘是用blend的效果,但没有排序问题。当时有美术同事问如何做到的,一时我也答不出来。
后来翻译unity3d官方文档的时候,发现有个例子提供了解决方案:只在边缘进行alpha blend,其它部位仍然使用alpha test来渲染。这样既保证了边缘的柔和,也没有渲染顺序的问题,因为边缘只是很小的部分,边缘本身的排序问题几乎不会被发现。
以下是原文:
When rendering plants and trees, many games have the hard edges typical of alpha testing. A way around that is to render the object twice. In the first pass, we use alpha testing to only render pixels that are more than 50% opaque. In the second pass, we alpha-blend the graphic in the parts that were cut away, without recording the depth of