半透明粒子特效 Prefab,内含多个 ParticleSystem,复制多个后 DrawCall 增加明显,在 FrameDebugger 里发现粒子特效无法动态合批,说是材质球不同,但其实材质球明明是相同的,令人疑惑。

查阅官方文档 https://docs.unity3d.com/Manual/DrawCallBatching.html,发现下边这一段话:
Semi-transparent Shaders usually require GameObjects to be rendered in back-to-front order for transparency to work. Unity first orders GameObjects in this order, and then tries to batch them, but because the order must be strictly satisfied, this often means less batching can be achieved than with opaque GameObjects.
表述有些模糊,但判断和 RenderQueue 有关。
之后将相同材质球单独设置不同的 RenderQueue。
Prefab里有四个东西,都是ParticleSystem组件:
1、最靠前的硬币 设为 3004
2、其次的背光 设为3003
3、星星闪光 设为3002
4、最后一条竖光 设为 3001
设好后,发现合批成了4个 DrawCall ,非常舒服。

博客内容探讨了Unity中半透明粒子特效DrawCall增加的问题,发现尽管粒子特效的材质球看似相同,但在FrameDebugger中并未进行动态合批。通过研究Unity官方文档,了解到半透明Shader需要按后向前的顺序渲染,这限制了合批的可能性。解决方案是通过调整ParticleSystem的RenderQueue,将四个粒子效果分别设置为3004、3003、3002和3001,成功将合批数量减至4个DrawCall,有效优化了性能。
最低0.47元/天 解锁文章
1985





