这是一个神坑
前不久在U3D里写了一个Alpha Test的非Unity Surface Shader材质。
Shadow Caster Pass也是自己提供的,实时阴影的情况下,渲染是正确的。
一旦烘焙了Lightmap, 影子Pass中的clip指令就失效了。
检查了很久,没发现代码有任何问题。
直到我在Unity Forum上发现了这个帖子
Alpha Cutout + Lightmap + Shadowsforum.unity.comWow this is an old post. I actually asked a Unity dev at Unite 2014 that year and was told the same thing, that there was a magic word search for "Transparent" that was used in the lightmapper to bake shadows.
哇,这是一个老贴。我在2014年Unite大会问了一个Unity的开发人员,得到了一样的说法。
Lightmap烘焙影子的时候会搜索一个神奇关键词 "Transparent"。
结论就是,代码并没有任何问题。Unity在烘Lightmap的时候,只有Shader名中有Transparent关键字时,Alpha Test才会生效。
我在Shader的名字(并非文件名)中加了一级Transparent