unity批次渲染设计
2014-07-26 12:00
183 查看
Unity can combine a number of objects at runtime and draws them together with a single draw call. This operation is called “batching”. The more objects Unity can batch together, the better rendering performance (on the CPU side) you can get.
Built-in batching support in Unity has significant benefit over simply combining geometry in the modeling tool (or using the
CombineChildren script from the Standard Assets package). Batching in Unity happens
after the visibility determination step. The engine does culling on each object individually, and the amount of rendered geometry is going to be the same as without batching. Combining geometry in the modeling tool, on the other hand, prevents
efficient culling and results in a much greater amount of geometry being rendered.
If you have two identical materials which differ only in textures, you can combine those textures into a single big texture - a process often called
texture atlasing. Once textures are in the same atlas, you can use a single material instead.
If you need to access shared material properties from the scripts, then it is important to note that modifying
Renderer.material will create a copy of the material. Instead, you should use
Renderer.sharedMaterial to keep material shared.
Tips:
Batching dynamic objects has certain overhead per vertex, so batching is applied only to meshes containing less than
900 vertex attributes in total.
If your shader is using Vertex Position, Normal and single UV, then you can batch up to 300 verts; whereas if your shader is using Vertex Position, Normal, UV0, UV1 and Tangent, then only 180 verts.
Please note: attribute count limit might be changed in future
Generally, objects should be using the same transform scale.
The exception is non-uniform scaled objects; if several objects all have different non-uniform scale then they can still be batched.
Using different material instances - even if they are essentially the same - will make objects not batched together.
Objects with lightmaps have additional renderer parameter: lightmap index and offset/scale into the lightmap. So generally dynamic lightmapped objects should point to exactly the same lightmap location to be batched.
Multi-pass shaders will break batching. Almost all unity shaders supports several lights in forward rendering, effectively doing additional pass for them. The draw calls for “additional per-pixel lights” will not be batched.
Objects that receive real-time shadows will not be batched.
batching as it will require less CPU power.
In order to take advantage of static batching, you need explicitly specify that certain objects are static and will
not move, rotate or scale in the game. To do so, you can mark objects as static using the Static checkbox in the Inspector:
Using static batching will require additional memory for storing the combined geometry. If several objects shared the same geometry before static batching, then a copy of geometry will be created for each object, either in the Editor or at runtime. This
might not always be a good idea - sometimes you will have to sacrifice rendering performance by avoiding static batching for some objects to keep a smaller memory footprint. For example, marking trees as static in a dense forest level can have serious memory
impact.
Static batching is only available in Unity Pro for each platform.
Mesh Renderers and
Particle Systems are batched. This means that skinned meshes, cloth, trail renderers and other types of rendering components are
not batched.
Semitransparent shaders most often require objects to be rendered in back-to-front order for transparency to work. Unity first orders objects 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 objects.
Some parts of Unity’s rendering do not have batching implemented yet; for example rendering shadow casters, camera’s depth textures or GUI will not do batching.
http://docs.unity3d.com/Manual/DrawCallBatching.html
Draw Call Batching
To draw an object on the screen, the engine has to issue a draw call to the graphics API (e.g. OpenGL or Direct3D). The graphics API does significant work for every draw call, causing performance overhead on the CPU side.Unity can combine a number of objects at runtime and draws them together with a single draw call. This operation is called “batching”. The more objects Unity can batch together, the better rendering performance (on the CPU side) you can get.
Built-in batching support in Unity has significant benefit over simply combining geometry in the modeling tool (or using the
CombineChildren script from the Standard Assets package). Batching in Unity happens
after the visibility determination step. The engine does culling on each object individually, and the amount of rendered geometry is going to be the same as without batching. Combining geometry in the modeling tool, on the other hand, prevents
efficient culling and results in a much greater amount of geometry being rendered.
Materials
Only objects sharing the same material can be batched together. Therefore, if you want to achieve good batching, you need to share as many materials among different objects as possible.If you have two identical materials which differ only in textures, you can combine those textures into a single big texture - a process often called
texture atlasing. Once textures are in the same atlas, you can use a single material instead.
If you need to access shared material properties from the scripts, then it is important to note that modifying
Renderer.material will create a copy of the material. Instead, you should use
Renderer.sharedMaterial to keep material shared.
Dynamic Batching
Unity can automatically batch moving objects into the same draw call if they share the same material and fulfill other criteria. Dynamic batching is done automatically and does not require any additional effort on your side.Tips:
Batching dynamic objects has certain overhead per vertex, so batching is applied only to meshes containing less than
900 vertex attributes in total.
If your shader is using Vertex Position, Normal and single UV, then you can batch up to 300 verts; whereas if your shader is using Vertex Position, Normal, UV0, UV1 and Tangent, then only 180 verts.
Please note: attribute count limit might be changed in future
Generally, objects should be using the same transform scale.
The exception is non-uniform scaled objects; if several objects all have different non-uniform scale then they can still be batched.
Using different material instances - even if they are essentially the same - will make objects not batched together.
Objects with lightmaps have additional renderer parameter: lightmap index and offset/scale into the lightmap. So generally dynamic lightmapped objects should point to exactly the same lightmap location to be batched.
Multi-pass shaders will break batching. Almost all unity shaders supports several lights in forward rendering, effectively doing additional pass for them. The draw calls for “additional per-pixel lights” will not be batched.
Objects that receive real-time shadows will not be batched.
Static Batching
Static batching, on the other hand, allows the engine to reduce draw calls for geometry of any size (provided it does not move and shares the same material). Static batching is significantly more efficient than dynamic batching. You should choose staticbatching as it will require less CPU power.
In order to take advantage of static batching, you need explicitly specify that certain objects are static and will
not move, rotate or scale in the game. To do so, you can mark objects as static using the Static checkbox in the Inspector:
Using static batching will require additional memory for storing the combined geometry. If several objects shared the same geometry before static batching, then a copy of geometry will be created for each object, either in the Editor or at runtime. This
might not always be a good idea - sometimes you will have to sacrifice rendering performance by avoiding static batching for some objects to keep a smaller memory footprint. For example, marking trees as static in a dense forest level can have serious memory
impact.
Static batching is only available in Unity Pro for each platform.
Other batching tips
Currently, onlyMesh Renderers and
Particle Systems are batched. This means that skinned meshes, cloth, trail renderers and other types of rendering components are
not batched.
Semitransparent shaders most often require objects to be rendered in back-to-front order for transparency to work. Unity first orders objects 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 objects.
Some parts of Unity’s rendering do not have batching implemented yet; for example rendering shadow casters, camera’s depth textures or GUI will not do batching.
相关文章推荐
- 批次渲染
- 关于.Net框架下3D游戏的设计与实现——2.1,渲染引擎Axiom简介
- GIS三维地景仿真设计之(三)建模及场景渲染
- 分享一个Unity 应用于”室内设计”的案例
- Unity 3D 动态创建对象,并渲染贴图,动态添加删除脚本
- Unity的状态机设计
- 想象渲染:3优秀的D室内设计模型的设计案例
- GacUI与设计模式(二)——渲染系统
- 基于Unity行为树设计与实现的尝试
- Ogre中的批次渲染技术(Batching)
- Ogre的渲染优化心得(二) -- Renderable和渲染批次, MovableObject和摄像机裁剪, SimpleRenderable和地形
- 批次渲染
- Ogre中的批次渲染技术(Batching)
- Ogre的渲染优化心得(二) -- Renderable和渲染批次, MovableObject和摄像机裁剪, SimpleRenderable和地形
- Ogre中的批次渲染技术(Batching)
- Ogre中的批次渲染技术(Batching)
- Ogre中的批次渲染技术(Batching)
- 基于Unity的AOP的符合基于角色的访问控制(RBAC)模型的通用权限设计
- Unity 简单游戏编程(1) 开始界面设计
- 【cocos2d-x入门实战】微信飞机大战之五:批次渲染