zoukankan      html  css  js  c++  java
  • To get Dynamic Batching to work

    Look at this forum thread: How to get Dynamic Batching to work?

    Offical doc:Draw Call Batching

    Unity can automatically batch moving objects into the same draw call if they share the same material.

    Dynamic batching is done automatically and does not require any additional effort on your side.

     

    When Static Batching is not an option, Dynamic Batching can save the day. As a matter of fact, it is always active on objects that are not static. To use it you just have to use as little objects as possible with as little vertices as possible.

     

    Batching dynamic objects has certain overhead per vertex, so batching is applied only to meshes containing less than 900 vertex attributes in total.
    Our shader is using Vertex Position, UV and Colors. So we can have upto 300 verts per object.

     

    Some useful tips from the Unity manual:

     

    • 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 and if your shader is using Vertex Position, Normal, UV0, UV1 and Tangent, then only 180 verts.
    • Don’t use scale. Objects with scale (1,1,1) and (2,2,2) won’t batch.
    • Uniformly scaled objects won’t be batched with non-uniformly scaled ones.
      • Objects with scale (1,1,1) and (1,2,1) won’t be batched. On the other hand (1,2,1) and (1,3,1) will be.
    • Using different material instances will cause batching to fail.
    • Objects with lightmaps have additional (hidden) material parameter: offset/scale in lightmap, so lightmapped objects won’t be batched (unless they point to same portions of lightmap)
    • Multi-pass shaders will break batching. E.g. Almost all unity shaders supports several lights in forward rendering, effectively doing additional pass for them
    • Using instances of a prefab automatically are using the same mesh and material.

     

    And a little tip on top of that: If an object has an animation but there are parts that never move, you can mark that part as static and it will not interfere with the animation.

     

    Dynamic Batching is very useful for star pickups and other small objects that are animated but are otherwise the same in the scene.

     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 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 effecient culling and results in much higher amount of geometry being rendered.

    A.First ensure that you have enabled Dynamic Batching in settings.

    B.Here is a short summary of what can go wrong (answers by @Dreamora and @Cameron):

      1.you use lightmaps.Objects with lightmaps have additional (hidden) material parameter: offset/scale in lightmap, so lightmapped objects won’t be batched (unless they point to same portions of lightmap).

      2.you don't use uniform scaling (try with no scaling at all aside of the default 1 1 1)

      3.the material is transparent which has impacts on batching

      4.they are not meshes but skinned meshes and have skinned mesh renderers which will not batch at all

        Solution: a.Use Mesh Baker 2 (a plugin for Unity) or other batch scripts.

              b.Bake the animation to the model and remove the skeleton and controller.May use parent constrain instead of parent (P).

        For simple rigid skin,method b may be better.

      5.same goes for softbody stuff.

      6.same option regarding shadows in all renderers (or no shadow at all is even better)

      7."cast shadows" looks like to be breaking the dynamic batching, while "receive shadows" should work (don't ask me why, and I didn't test it)

    For runtime combine:How to batch draw calls for instantiated Prefabs

  • 相关阅读:
    一般表的一般方法
    asp.net采集函数(采集、分析、替换、入库一体)
    在 Access 里使用查询建立 存储过程/视图, 并使用 ASP 执行
    制作Access代码生成器 研发中【资料整理】
    Asp.net中打造通用数据访问类(c#)[转]
    Ajax.Net程序教程.彭彭编写
    C# 类中 属性和方法写在一个类里 和 属性和方法 分开的区别感受!!
    自己在vs2003下写的findLabel[应用程序]
    [转]Response.Write后css失效问题的解决
    javascript结构图
  • 原文地址:https://www.cnblogs.com/qiengo/p/2922042.html
Copyright © 2011-2022 走看看