Search Unity

2 Prefabs, 2 materials, 205 tris: 18 Draw Calls?

Discussion in 'iOS and tvOS' started by lakehaze, Dec 30, 2011.

  1. lakehaze

    lakehaze

    Joined:
    Mar 7, 2011
    Posts:
    24
    I think I'm following all the rules required for batching draw calls:
    1 Less than 300 triangles (combined even)
    2 Share Materials (1 per prefab, 3.3megs combined)
    3 No scale transform mixing (all scale transforms in scene are at 1,1,1)

    With 2 materials, I expect 2 draw calls. If I display one prefab, I get one draw call (batched:54). If I display the other prefab, I get one draw call(batched: 45). If I draw them together, I get 18 draw calls (batched: 97).

    If ever there was a villain in my work life, it would be Mr. Draw Call.

    Why is it that these two unrelated prefabs destroy the batching effect for each other?
     
  2. Skyrise

    Skyrise

    Joined:
    Nov 3, 2005
    Posts:
    158
    Your budget is 300 vertices, not 300 tris per mesh.
    And there are other things that can break the dynamic batching, such as using skinned mesh and so on...
     
  3. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    Well there is a max count batching objects. That isn't infinite process.
    Also batching isn't low cost memory process. That is important to balance...
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Dynamic batching seems off on 3.5 - flickering etc - anyone else getting it? your object have to rotate / have blending/transparency for it to happen.
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    There are elemental informations missing:

    1. is the material using transparent / cutout? That makes a major difference as it will not globally batch alpha materials

    2. Though this is not the case here as you get anything batched, keep in mind that skinned renderers will not batch at all.
     
  6. CoatlGames

    CoatlGames

    Joined:
    Apr 25, 2008
    Posts:
    773
    also how many lights are in the scene, lights can also multiply the draw calls aggressively
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    To be more precise: each pixel light that hits an object will cause it to redraw for this light and this redraw will be an own object rendering. it will always be distinct objects that are redrawn not whole batches as it is a transparent redraw hence fillrate and overdraw impacting.
     
  8. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    1. materials are mobile/particles/additive etc (mobile shaders)
    2. I'm not interested in if it batches or not, I'm interested in why it is showing massive screen corruption from dynamic batching in 3.5. It does not occur with dynamic batching disabled, or in 3.4. Therefore it is 100% broken.

    I will be submitting the latest 3.4 project to unity after I ship an appstore update. Then, they can test it for 3.4 and 3.5 and see the comparison.

    print/debug log is 100% broken in 3.5 as well for me. I cannot print to the xcode console, again this works perfectly in 3.4.

    3.5 is also far slower with my main Physynth project.

    Finally, I'm having dynamic batching actually CRASH my project in 3.5. Disabling dynamic batching solves the crash. I use a large number of materials and post effect shaders. I will be submitting this in a couple of days.
     
  9. lakehaze

    lakehaze

    Joined:
    Mar 7, 2011
    Posts:
    24
    I will check my version of Unity when I get to the office, but I'm sure it is not v3.5. Probably 3.4.

    Oops, my bad. I don't have the scene in front of me today (Sunday), but it must be less than 615 vertices. That still shouldn't cause 18 draw calls by itself.
    There are no skinned meshes in this example.

    Max count batching objects? Any idea what that max count is? I can't imagine I'm hitting that limit with 205 triangles (less than 100 objects). Right now, frame-rate is the bottle neck. Today, we would gladly trade memory for batched draw calls.

    We are using the unlit/transparent material. If that is causing the batches to fail with 2 materials in the scene, then it will truly hurt our project.

    There are zero lights in the scene.

    Thank you all for your many replies :)
     
    Last edited: Jan 1, 2012
  10. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    http://unity3d.com/support/documentation/Manual/iphone-DrawCall-Batching.html

    For each combined batch unity duplicate mesh data to create a new mesh. then if you combine 100 objects that will theoretically increase your memory by 100.

    Then yes rendering process is faster.
    But no, saying memory use is less or same.

    batching 100 object could kill your device.

    - 615 vertices. >>> well depend.... max is 300 vertice per object into unity (not a modeling software)
    now if an object has 2 materials, draw call grow up faster! o_<

    You also need to stick the Static checkbox on each static objects to allow and help for it.

    Transparency > separate alpha triangle from their main object. That should save memory.
     
  11. lakehaze

    lakehaze

    Joined:
    Mar 7, 2011
    Posts:
    24
    Thank you for your reply.
    My understanding is that memory use only goes up when batching 'Static' objects. Right now, none of our objects are 'static'.
    From your link:
    "Using static batching will require additional memory to store combined geometry."
    Regardless, right now, memory is not the problem. We can employ other tricks to save memory, if needed. Right now, the problem is frame-rate.

    Each object has only 1 material.

    I'm not sure what you mean by "Transparency > separate alpha triangle from their main object."
     
  12. lakehaze

    lakehaze

    Joined:
    Mar 7, 2011
    Posts:
    24
    Yes, the problem is the Unlit>Transparent shader.
    It seems we can work around it by using a single Unlit>Transparent shader (for the object group that requires the prettiest alpha blending), and Unlit>Transparent Cutout for all our other materials.
    Using this combonation of shaders results in the expected 2 draw calls.
    Thanks again everybody :)

    EDIT:
    Yes, the problem is the Unlit>Transparent shader, and setting some materials to Unlit>Transparent_Cutout fixes the issue, although it isn't as simple as just using all Cutout shaders. It seems I can use some transparent shaders in certain special combinations.
    Now I just need to figure out what causes some prefabs/textures to hate Unlit>Transparent.

    A new experiment:
    -Prefab A (50 larger animated objects): Must be Transparent, cutout looks horrible with this texture.
    -Prefab B (55 small animated objects): Works with C or D, but not C and D together, and never with A.
    -Prefab C (160 children of 10 animated joints): Works with A, if B and D use Cutout.
    -Prefab D (50 children of 10 animated joints): Works with A, if B and C use Cutout.
    *'Works' = Generates predictably low draw calls.
    All textures are 1024x1024 png24
    728 Tris, 1.4k Vertices total.
    This current example generates 6 draw calls (360 batched), if A and D are Unlit>Transparent, and B and C are Unlit>Tranparent_Cutout (chosen by best display results and trial and error).

    I'm trying to figure out why Prefab B will never work with Prefab A. It has far fewer objects than C. Maybe it's all the animations (55 vs 10)?
    All the prefabs/textures are basically the same: textured animated planes, just with different art content. We could put them all on a single texture atlas in a single FBX file except that some devices limit the texture file size to 1024x1024.

    I'll keep experiementing and find the best balance, but if anybody has an insight as to why the material types don't like certain teams, I'd love to know.
    Thanks again everybody :)
     
    Last edited: Jan 3, 2012
  13. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    Ask your 3D artist to separate all triangle using transparency from the main model and to export 2 models!
     
  14. lakehaze

    lakehaze

    Joined:
    Mar 7, 2011
    Posts:
    24
    Sorry, I haven't been clear; this is a 2D planar project. 95% of the objects are made of only 2 triangles. All triangles are using transparency.
    Thanks again, though :)