当前位置:网站首页>Dynamic batch processing and static batch processing of unity
Dynamic batch processing and static batch processing of unity
2022-04-23 02:02:00 【Want to be the front end of the back end】
One 、 Drawing principle
To draw objects on the screen , The engine must send the image API( for example OpenGL、Direct3D) Send a DrawCall Instructions , Every time you send DrawCall The procedure of the instruction is a render batch (Batch), This process is divided into two parts : Set render state (setPass) And call DrawCall(Batches), Setting the rendering state is a heavy division of labor , For resources and objects loaded into the game ,CPU We need to compute the matrix of its vertices , The texture used for rendering , The materials and shader, Lights used in rendering, etc , If the material and texture of each object are different , here CPU The base note is to set the render state of these objects. DrawCall, As a result CPU Performance overhead , In short, that is CPU towards GPU Send instructions and receive them from GPU Drawing , namely CPU And GPU A data exchange is a DrawCall.
Two 、 The batch
Because every time you send DrawCall Instructions will cause CPU Performance overhead , and CPU The processing speed is faster than GPU It's much slower , So you can transfer the pressure of drawing to GPU
Unity Some objects can be merged , So you can use it once DrawCall To render them . This operation , It's called batch processing , Batch processing can get better rendering performance
For example, render a thousand triangles , If you render them as a thousand separate meshes, you need to request 1000 Time DrawCall, If you directly render a mesh containing a thousand triangles, you only need to request 1 Time DrawCall, This reduces CPU The overhead will greatly improve the performance
Unity There are two batch processing methods in : One is dynamic batch processing , One is static batch processing . For dynamic batch processing , The good news is that all processing is automatic , We don't need to do anything by ourselves , And objects can move , But the bad news is , Many restrictions , Maybe if we are not careful, we will destroy this mechanism , Lead to Unity Cannot batch some objects with the same material . For static batch processing , The good news is that freedom is high , There are few restrictions , The bad news is that it may take up more memory , And after static batch processing, all objects can no longer move .
3、 ... and 、 Render statistics window

- Batches: amount to DrawCall frequency
- Saved by batching: Save through batch processing DrawCall frequency
- SetPass calls: Set the number of times to render the state
Four 、 Dynamic batch processing
Dynamic batch processing is off by default , Manual opening required :Project Setting—Player— On the hook Dynamic Batching

- Dynamic batch only supports vertices less than 900 Mesh objects .
- If Shader Vertex position is used 、 normal 、UV Value three properties , Only dynamic batch processing 300 An object below a vertex . If Shader Vertex position is used 、 normal 、UV0、UV1 And tangent vectors , Then only dynamic batch processing 180 An object below a vertex .
- Do not use zoom , There are zoom (1,1,1) and (2,2,2) The two objects will not be batched . Uniformly scaled objects will not be batched with non uniformly scaled objects . Use zoom (1,1,1) and (1,2,1) The two objects will not be batched , But use the scaling scale (1,2,1) and (1,3,1) Two objects can be batch processed .
- Instanced objects with different materials will result in batch failure .
- Have lightmap Objects will not be batched , Unless they point to lightmap The same part of .
- Multichannel Shader Will hinder batch processing . Because it's almost Unity All shaders in support of multiple light sources in forward rendering , And effectively open up multiple channels .
- The instantiation of the preform will automatically use the same mesh model and material
5、 ... and 、 Static batch processing
Static batch processing needs to be done in Inspector Check... On the panel Static

- Just check Static And possess Same material Objects can be statically batched at runtime
- But static batch will create a merged... For each object Combined Mesh, Additional memory space is required to store the merged Combined Mesh, So be careful when using ( For example, a thick grassland , If you use static batch processing, it will cause serious memory overhead )
6、 ... and 、 summary
- Both static and Dynamic Batching can reduce DrawCall, The main premise is that objects use the same material
- Static batch processing is applicable to objects in the scene whose position will not change and there can not be too many single objects , Like a forest , This kind of grassland is more suitable for
- There are many restrictions on dynamic batch processing , Number of vertices required , Material requirements, etc . Static batch processing has fewer restrictions , Is the method of exchanging memory for performance , Specific case specific analysis
- Although batch processing is a good way , But it's easy to break its rules . for example , All objects in the scene use Diffuse texture of material , But they may use different textures . therefore , Combine as many small textures as possible into one large texture (Atlas) Is a good idea .
版权声明
本文为[Want to be the front end of the back end]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220844007877.html
边栏推荐
- 批处理多个文件合成一个HEX
- Use of j-link RTT
- 2022.4.22-----leetcode. three hundred and ninety-six
- Communication summary between MCU and 4G module (EC20)
- Shardingsphere broadcast table and binding table
- Shardingsphere introduction and sub table usage
- [tutorial] how to use GCC "zero assembly" for white whoring MDK
- Easyswool environment configuration
- EBS:PO_EMPLOYEE_HIERARCHIES_ALL
- [hands on learning] network depth v2.1 Sequence model
猜你喜欢

MySQL basic record

揭秘被Arm编译器所隐藏的浮点运算

What business scenarios will the BGP server be used in?
![leetcode:27. Remove element [count remove]](/img/af/e5cd9ef8dc43aab4ddf016600ffc4a.png)
leetcode:27. Remove element [count remove]

Shardingsphere introduction and sub table usage

简洁开源的一款导航网站源码

Error in face detection and signature of Tencent cloud interface

Leetcode 112 Total path (2022.04.22)

W801 / w800 WiFi socket development (II) - UDP Bluetooth control WiFi connection

Server 2019 the available memory of the server is half of the actual memory
随机推荐
MySQL active / standby configuration binary log problem
浅析静态代理ip的三大作用。
Communication summary between MCU and 4G module (EC20)
BGP服务器在什么业务场景会被用到?
What are the test steps of dynamic proxy IP?
单片机和4G模块通信总结(EC20)
npm——配置淘宝镜像
Under the pressure of sales, domestic mobile phones began to reduce prices, but they haven't put down their final face
W801 / w800 WiFi socket development (I) - UDP
World Book Day 𞓜 a good book that technicians should not miss (it cutting-edge technology)
Quel est le fichier makefile?
Sqlserver data transfer to MySQL
English abbreviation of role personal attribute
【汇编语言】从最底层的角度理解“堆栈”
What business scenarios will the BGP server be used in?
如何对代理IP进行分类?
FL studio20. 8 the latest Chinese version installation and download graphic tutorial
Encrypted compressed backup bat script
easyswoole环境配置
浅析一下隧道代理IP的优缺点。