Search Unity

One Batch: Combine hundreds of materials into one draw call

Discussion in 'Assets and Asset Store' started by jbooth, Sep 14, 2018.

  1. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    One Batch allows you to combine hundreds of materials and textures into a single draw call. The traditional way to do this is to combine multiple textures onto a single texture atlas, but this has a lot of issues- you cannot tile those textures, and you run out of texture space quickly. Instead, One Batch uses Texture Arrays to overcome these limitations, and can preserve all the properties of the Standard shader for each object it combines. This can greatly reduce draw calls and set pass calls, especially with kit-bashed assets and static scene data.

    One Batch is live on the asset store!

    Feel free to read the documentation.

    Here's a demo of the beta version in action:







     
    Last edited: Sep 26, 2018
    Invertex, punk, hippocoder and 7 others like this.
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Finding even more new way to exploit that feature, amazing!
     
  3. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Well, in truth MegaSplat users started doing this a while ago, this is really just making a nice workflow for it.
     
    recon0303, one_one and neoshaman like this.
  4. jaelove

    jaelove

    Joined:
    Jul 5, 2012
    Posts:
    302
    Please support unity 5.6
     
  5. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I can’t, unfortunately - Unity doesn’t allow you to save linear 16 bit textures to disk without some form of gamma being applied. So to work around this I created my own texture format using the new ScriptableImport pipeline.
     
  6. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    one_one, neoshaman and StevenPicard like this.
  7. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    336
    I've been using this tool for my mobile game (that uses the Standard shader) and it is incredible. Especially the packed mode, which packs your Metallic/Smooth, AO and Height textures into a single texture, like the HDRP detail maps. Reduces my memory usage and app disk size by quite a bit. If your game uses the Standard shader, this tool is so worth it.
     
    jbooth likes this.
  8. StevenPicard

    StevenPicard

    Joined:
    Mar 7, 2016
    Posts:
    859
    I just noticed you used the LOTR's "One Ring" in the assets name. Very cool! (Yes, I'm slow.)
     
  9. OnePlusOneNS

    OnePlusOneNS

    Joined:
    Nov 18, 2013
    Posts:
    7
    Looking really great! One question. The asset is now in beta, will the price increase once it will be released or is this already the final cost?
     
  10. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Not sure..
     
    OnePlusOneNS likes this.
  11. DNArt

    DNArt

    Joined:
    Jan 16, 2014
    Posts:
    21
    Did Unity get the texture array working in WebGl. Can we make builds for WebGL with this already?
     
  12. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I have not tested WebGL in a long time, I’ll have to try again soon.
     
  13. AndreasO

    AndreasO

    Joined:
    Sep 25, 2012
    Posts:
    90
    Do you plan to also add mesh optimisation features? The tool name "One Batch" sounds like it could be the one tool we will ever need for all the draw call optimisations ;-)
     
  14. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    In what form? Mesh combining? Because that's what the static batching system basically does- statically combine meshes which have the same material, and One Batch basically makes sure they can have the same material, improving static batching.
     
  15. AndreasO

    AndreasO

    Joined:
    Sep 25, 2012
    Posts:
    90
    Oh ok ... I'm sorry for my ignorance then. :-D
     
  16. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    when it is combining the meshes does culling still work? from my understanding not. and from the documentation LODs are breaking the batching as well? so those methods are very important for the performance as well. so if i loose those how does it compare with the gain from the texture arrays?
     
  17. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    It's entirely dependent on what is bottlenecking your scene- there is no blanket statement which can answer that question. For instance, on many games I've seen LOD models actually be more of an issue than actually helping. I've seen cases where static batching was slower than just drawing everything as instanced; or where pixel shader complexity is the bottleneck and reducing draw calls will make no difference. Or cases where draw calls are the primary thing killing frame rate. So it really just depends- the only way is to heavily profile your scene and understand where you are spending time, and them employ tactics which address those bottlenecks. For instance, if your game is physics bound, then speeding up rendering isn't going to help at all.
     
    StevenPicard likes this.
  18. DavidLieder

    DavidLieder

    Joined:
    Feb 14, 2016
    Posts:
    84
    Awesome tool.

    Since it's based on the new pipeline, will it be (or is it) compatible with LWRP?
     
  19. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Nope, that would require a completely different set of shaders because shaders have to be entirely re-written for each SRP, as unity got rid of surface shaders and only allows cross compatibility when using the new shader graph, which doesn't support the old pipeline and also can't create something like the standard shader (no shader_features, etc).

    If LWRP becomes more common I might consider it some day, but from my data selling the LWRP module for MicroSplat, hardly anyone is using SRPs. That said, if you can roll your own shaders the rest of the tooling would work fine..
     
  20. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    i do understand this and you stated it already. but assuming you are doing assets for a common interest/userbase, when does one batch shine at most. what bottleneck it does open. when you have a lot of static assets with different textures but the same (std) material and you do not want to suffer from lowres textures from atlassing - archvis for example!? i really like your videos /tutorials very much but even from those example scenes i can´t figure out when it totally makes sense to use OB. i´ll give it a try for a VR project - i guess it could help here because drawcalls is at least on bottleneck.

    and btw. i do use microsplat + blend module. does this break one batch or does it work together?
     
  21. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    It helps when you are bound on SetPass calls, specifically. So in the case of static batching, for instance, the batch has to be broken for a number of reasons, one of which is changing materials. If you look in the frame debugger and watch it draw, you can see how many times that happens by looking at the reason the batch was broken.
     
  22. DavidLieder

    DavidLieder

    Joined:
    Feb 14, 2016
    Posts:
    84
    Well, I only use LWRP now, and I just bought One Batch, so could you please give me a very brief explanation of "rolling" my own shaders? Are you referring to shaders associated with One Batch? Or are you saying I would have to edit the One Batch code? Because I only use LWRP-compatible shaders in my projects now anyway. I don't use standard shader at all. If One Batch is just combining textures, then it should work fine, since all my shaders are LWRP. Right?

    Thanks.
     
  23. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    There’s an example using ASE included which has custom functions to extract the property data for each source texture. There’s also information in the docs about how that data is stored. It should be fairly easy to use one batch to extract and combine textures, but you’d have to roll your own version of the shader for LWRP.
     
  24. DavidLieder

    DavidLieder

    Joined:
    Feb 14, 2016
    Posts:
    84
    Perhaps you should put that in the product description, but I suppose I should not just assume that products are going to be compatible. Most asset creators I've spoken to are preparing LWRP versions for November after 2018.3 comes out. The only reason I got involved with Microsplat is because there is an LWRP version, which I purchased.

    Can I use the shader graph to create the shader you're talking about? You're saying that One Batch uses a custom shader.
     
  25. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    It’s actually all over the description that it’s designed for the standard shader. But you can create a custom one using whatever system you want to use.
     
  26. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634
    Nice Jason didn't know you where making this. ( You need a discord, or a way for current users to find you user when you make new tools, just a suggestion. . I found this by accident, as I was looking at the Unity forums, something I cut back on these days. anyways, I hope to see a way you can, get your new tools out to your already fan base. :) Just a thought. anyways good luck on the release.


    Looks great, I make many atlas's and yes dealing with tiling can be a pain, due this. So its great you made a tool addressing some known issues.
    I have many kit-bashed assets , I use for static scenes. sounds like this tool could save hours of work around and work for this kind of work. wonderful.
     
  27. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634

    aye.
     
  28. DavidLieder

    DavidLieder

    Joined:
    Feb 14, 2016
    Posts:
    84
    Alternately, combining Microsplat and One Batch adds so much optimization that I feel confident doing a mobile project in the normal Unity 3D space, so maybe I'll skip LWRP at least for now. But I encourage you to port One Batch later after LWRP goes off preview, because it is the future of mobile gaming, IMO, and a lot of devs will be using it. A lot already are. People who have used Microsplat in the past did so in a normal (traditional) Unity workflow, so those people are probably not the ones adopting the newer features like LWRP. But a lot of devs will use LWRP after 2018.4 is released. People are waiting for the bugs to be worked out. If One Batch worked for LWRP in the future, I would love that.
     
  29. DavidLieder

    DavidLieder

    Joined:
    Feb 14, 2016
    Posts:
    84
    There is a Discord channel, for MicroSplat, that has been useful for learning about these products. It's here: https://discord.gg/BB4dkgQ
     
    recon0303 likes this.
  30. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    LWRP is basically the current pipeline with some stuff removed and cleaned up. Sales data from MicroSplat tells me that it’s just not that popular yet. The big win of SRP is customizing the pipeline, which is not something most people can do, and because Unity doesn’t provide an anstraction later for shader other than the shader graph, it’s not trivial to move shaders between pipelines.

    When/if LWRP settles down, I might consider doing a custom shader for it; however, without a surface shader like abstraction, it’s very likely that new versions would break things, and now that Unity has moved to packages there’s not an easy way to conditionally define code for multiple versions, which makes it a potential support nightmare. Basically, everything about SRPs work against asset store authors or the old Unity “it should just work” mentality, which I find very unfortunate.
     
  31. DavidLieder

    DavidLieder

    Joined:
    Feb 14, 2016
    Posts:
    84
    Okay, thanks for explaining it.

    By the way, I love your Unite 2015 and Unite 2017 talks! Amazing info, and helps me understand some of the bigger picture of this stuff.
     
  32. Wizard-Games

    Wizard-Games

    Joined:
    Jun 4, 2013
    Posts:
    34
    WIll this work with Mesh Baker?
     
  33. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    does this work with webgl
     
  34. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634
    ya I don't use microsplats, or have it, I have mega splats, and never seen Discord before.( possible I missed it) easy to do on Unity forums. ) are all the products there? or just Microsplats? Thanks. for the info David:)

    ( Never mind ) I see that it has them all.:) disregard suggestion. ) it was already added. :)
     
    Last edited: Oct 14, 2018
    DavidLieder likes this.
  35. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    As long as the tool combining meshes preserves vertex colors it should work fine.

    I don’t think texture arrays work with webgl in Unity right now. They are in the webgl 2.0 spec though.
     
  36. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    106
    Hello,

    yesterday I bought OB. Now I experience terribly slow scene saving times while using it together with Megasplat. Not sure if you're aware of this.
     
    Last edited: Oct 20, 2018
  37. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Can you profile it and tell me where your seeing most of the time spent? OB doesn’t save anything into the scene, so not sure why it would have any effect.
     
  38. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    106
    Not sure that's what you meant. Actually I'm also not sure whether it's OB fault, but problem is solved if I delete either OB or MS.
    About testing project: Project contained megasplat (1.71 or 1.72), vegetation studio (latest, prolly), OB (latest), and some MS/OB texture arrays copied from main project.
    Test scene was VS demo.

    Just MS, everything fine
    MS + OB, not fine
    MS + OB with more MS texture arrays (tested because windows resource monitor claimed system.exe was reading those while saving)

    "Real" project with almost empty scene

    "Real" project with "real" scene

    10s in testing project is not a huge deal, 1min in real environment in quite irritating as I have a habit to ctrl S every 30 seconds.
    Few other things:
    *bugs always happens when loading a new scene (or even reloading it)
    *after the long-save, the next one, done immediately after is a normal one, under 1s
     
  39. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Very strange- can you try this in a project with asset serialization set to binary instead of ascii? I have seen a case in the past where Unity serialized some things into YAML that it really shouldn't, so I'd be interested if that made a difference.

    Oh, just found something in the OneBatch code which may cause an issue (might not be it, but definitely a bug). In OneBatchPreProcessor, change line 43 from:

    var cfgs = AssetDatabase.FindAssets("t:TextureArrayConfig");

    to:

    var cfgs = AssetDatabase.FindAssets("t:OneBatchConfig");

    and let me know if that makes a difference..
     
  40. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    106
    That's it, problem solved.
     
  41. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    106
    Some more bugs:

    1) objects look (smoothness) after using OB differs
    2) objects look different while changing smoothness source although neither albedo nor specular texture contains alpha
    3) tinting is not recoloring whole object and it's recoloring other objects
    4) 3rd mesh normals are inverted
    5) wrong smoothness value for human head (was .1; is .5)
     
    Last edited: Oct 22, 2018
    jbooth likes this.
  42. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Ok, I'll take a look at this stuff. Pretty sure the mesh normals are not inverted- it just copies the data. Do you mean that the normals are inverted? It might be possible that the channels are swapped in the normal pack/unpack step..
     
  43. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    336
    On a side note:

    mat.SetTexture("_MetalGlossMap", metalSmoothArray);

    should be

    mat.SetTexture("_MetallicGlossMap", metalSmoothArray);

    in Editor/OneBatchConfigEditor_Compiler.cs, line# 728.
     
    jbooth likes this.
  44. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    106
    Maybe it's as you're saying. I haven't checked the mesh data or anything. Although they even look flipped in inspector view
     
  45. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    So, comparing the data in the deferred gbuffer:





    With the exception of some very small quality loss due to the packed format compression, they look identical.
     
  46. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    106
    OK, I found it. It was coping part indeed, and was caused by negative scale. (4) is somehow solved.
     
  47. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    336
    OneBatch is working great for me on iOS, but on Android it is causing shader compile errors like:

    Code (CSharp):
    1. Shader error in 'OneBatchStandard': 'OneMinusReflectivityFromMetallic': no matching 1 parameter function at Assets/OneBatch/OneBatchStandardShader/OneBatchStandardCoreForwardSimple.cginc(46) (on gles3)
    2.  
    3. Compiling Vertex program with UNITY_PASS_FORWARDBASE DIRECTIONAL
    4. Platform defines: UNITY_NO_DXT5nm UNITY_NO_RGBM UNITY_ENABLE_REFLECTION_BUFFERS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_NO_CUBEMAP_ARRAY UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF3 UNITY_NO_FULL_STANDARD_SHADER SHADER_API_MOBILE UNITY_HARDWARE_TIER1 UNITY_LIGHTMAP_DLDR_ENCODING
    5.  
    6. Shader error in 'OneBatchStandard': undeclared identifier '_Metallic' at Assets/OneBatch/OneBatchStandardShader/OneBatchStandardCoreForwardSimple.cginc(46) (on gles3)
    7.  
    8. Compiling Vertex program with UNITY_PASS_FORWARDBASE DIRECTIONAL
    9. Platform defines: UNITY_NO_DXT5nm UNITY_NO_RGBM UNITY_ENABLE_REFLECTION_BUFFERS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_NO_CUBEMAP_ARRAY UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF3 UNITY_NO_FULL_STANDARD_SHADER SHADER_API_MOBILE UNITY_HARDWARE_TIER1 UNITY_LIGHTMAP_DLDR_ENCODING
    10.  
    Is this due to some sort of missing define? I'm targeting OpenGLES3.0 with Require OpenGLES3.1.

    Or does it have to do something with: UNITY_PBS_USE_BRDF3 UNITY_NO_FULL_STANDARD_SHADER?

    Though both iOS and Android are targeting Low Standard shader, yet iOS compiles fine...

    *EDIT*

    Fixed. Looks like on Android I have to target Medium for the Standard shader, but on iOS I can use Low.
     
    Last edited: Oct 22, 2018
  48. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    106
    Some feedback after testing newest version

    NOT FIXED 1) objects look (smoothness) after using OB differs
    NOT FIXED 2) objects look different while changing smoothness source although neither albedo nor specular texture contains alpha
    FIXED 3) tinting is not recoloring whole object and it's recoloring other objects
    FIXED 4) 3rd mesh normals are inverted
    NOT FIXED 5) wrong smoothness value for human head (was .1; is .5)
    Also: smoothness value is not working unless source is set to "albedo alpha"

    Another 'also': cutout version is not working and acting like opaque. Was broken in previous version too.

    EDIT: I think you forgot to clean up shotgun debuging :p onbatchconfigeditor_ui line161
     
  49. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I have not been able to repro your issue with Cutout; here's a screenshot from the example scene using the cutout shader:

     
  50. DrInternet

    DrInternet

    Joined:
    Apr 6, 2014
    Posts:
    106


    stick_derbis_00 from Book of dead. Only this one prefab in texture array with diffuse and normal map. Transparent and fade look like expected, cutout looks like diffuse.