动态合并材质相同的mesh
kevinypcao opened this issue · comments
材质相同的mesh在渲染时需要做动态合并,减少DrawCall。
具体做法可以参考Unity,Unity中有静态批处理与动态批处理,目前我们可以考虑先实现静态批处理。
Unity静态批处理与动态批处理介绍如下:
https://www.jianshu.com/p/46c9b6296f9c
我们可以考虑在CBaseObject中添加一个状态,设置了这个状态的对象在渲染之前推到一个特殊的队列,然后这个特殊队列中的对象在渲染时会根据其使用的材质球(也就是贴图)对pass进行分类,同一个分类下的pass使用一个DrawCall去绘制(可以考虑将pass数据复制到一个新的顶点缓存)。
search CGlobals::GetScene()->IsInstancingEnabled(),
enable it, currently only supported in DirectX. But it will not increase FPS very much.
this is why I disabled it by default, but you can enable it from script. Only works with static mesh.
再者,我们需要在移动端也能使用。
BMaxObject add a property "SortByTexture". Add all triangle lists to a buffer and render together in a post rendering process.
- support two buffers: one for transparent, one for opaque
- precalculate all ParaXmodel by matrix to memory vector3d in tile coordinate.
- post buffer can be just reference to the instance's vector array.