unity游戏优化(第2版) 第三章 批处理的优势

主要参考:https://zhuanlan.zhihu.com/p/390456989  

  https://forum.unity.com/threads/confused-on-batching.1115887/    链接中 bgolus 的评论

 

 

几个概念1.DrawCall  2.Batch   3.Static Batch   4.Dynamic Batch

    

    单渲染线程。    

    drawcall:cpu发送指令给gpu的过程

    batch: Batch一般指经过打包之后的 Draw call 。 带有渲染状态的drawcall

    渲染状态:各种渲染模式。。各种test Mode、 shader、 light  ( ID3D11DepthStencilState   ID3D11RasterizerState  FillMode CullMode FrontCounterClockwise DepthClipEnable 。。。。。) 

    更改渲染状态是耗时的过程

注意点: 1.侧重点,static:消耗内存   Dynamic:cpu计算压力

      static是将多个同material的mesh合并成一个大的vertex buff和 indexbuff , 加载并上传这个大的buff 给GPU

           dynamic是cpu把多个同material的mesh 转化成 worldcoord 传给GPU

      

     2. Dynamic 在Cpu传输到GPU前 需要把多个同material的mesh 的顶点数据全部转化到WorldCoord下。 (原因:如果不在一个worldcoord下,每个mesh中shader内的unity_ObjectToWorld是不同的,则在vertexShader内无法单一指令进行转化。 )

 There's only one unity_ObjectToWorld  matrix used on a batched mesh, any batched mesh, and it's an identity matrix: no scale, no rotation, no translation. It assumes the mesh is being rendered placed at the center of the world, because it is.

  

 

posted @ 2022-02-14 21:41  sun_dust_shadow  阅读(91)  评论(0编辑  收藏  举报