LiXizhi / NPLRuntime

NPL - Neural Parallel Language

Home Page:https://paracraft.cn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

动态合并材质相同的mesh

kevinypcao opened this issue · comments

材质相同的mesh在渲染时需要做动态合并,减少DrawCall。

具体做法可以参考Unity,Unity中有静态批处理与动态批处理,目前我们可以考虑先实现静态批处理。
Unity静态批处理与动态批处理介绍如下:
https://www.jianshu.com/p/46c9b6296f9c
我们可以考虑在CBaseObject中添加一个状态,设置了这个状态的对象在渲染之前推到一个特殊的队列,然后这个特殊队列中的对象在渲染时会根据其使用的材质球(也就是贴图)对pass进行分类,同一个分类下的pass使用一个DrawCall去绘制(可以考虑将pass数据复制到一个新的顶点缓存)。

Unity中使用静态批处理与不使用静态批处理DrawCall对比如下:
不使用静态批处理
qq 20190218163353
使用静态批处理
qq 20190218163412

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.

qq 20190221105104
我们这边使用的是ParaXEntity和BMaxObject,只是创建了对象和设置了位置,而且也并不能保证引擎在经过一系列处理之后需要批处理的对象在渲染队列中是相邻的。

再者,我们需要在移动端也能使用。

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.