感谢您的附加信息! EnableKeyword
的使用解释了为什么要创建 Material 实例。
不幸的是,无法将 MaterialPropertyBlock
与自定义的 EnableKeyword
着色器关键字一起使用,因为在幕后着色器关键字有效地切换到不同的着色器。 每个变体(关键字的组合)都是单独编译的,并且需要单独的材质(绘制调用)。 如果不清楚,这个 Unity 论坛主题 用不同的语言解释它。
您要设置什么材料关键字? 一般来说,最好的解决方案是在骨架材质中预先设置相应的关键字,如果它在多个实例之间共享的话。
Thanks for the additional information! The use of EnableKeyword
explains why a Material instance is created.
Unfortunately there is no way to use a MaterialPropertyBlock
with a custom EnableKeyword
shader keyword, since behind the scene shader keywords effectively switch to a different shader. Each variant (combination of keywords) is compiled separately and requires a separate Material (draw call). In case this was unclear, this Unity forum thread explains it in different words.
What material keyword are you trying to set? In general the best solution would be to set the respective keywords at the skeleton Material up front if it is shared across multiple instances anyway.