Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

One Batch: Combine hundreds of materials into one draw call

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

  1. Air_In

    Air_In

    Joined:
    Jun 5, 2020
    Posts:
    2
    I found a major issue with OneBatch. I organized a chart explaining what the issue is in the image below. Please help.
     

    Attached Files:

  2. nyobu

    nyobu

    Joined:
    Mar 9, 2017
    Posts:
    14
    Hi.
    I have three questions.
    1. What is Packed Settings?

    2. Why are the same items lined up under Diffuse is Linear? Albedo Settings,Normal Settings.....etc.
    If I change the settings below, so will the top. Even if I change the upper setting, the lower setting also changes.

    3. This is main problem. I want to use Compression Force Crunch.But Error.And texture is like noise.
    Error is
    Format Mismatch: DXT1Crunched!=DXT1
    UnityEngine.Debug:LogError(Object)
    JBooth.OneBatch.OneBatchConfigEditor:CopyToArray(Texture2D, Texture2DArray, Int32, Int32) (at Assets/OneBatch/Editor/OneBatchConfigEditor_TextureUtil.cs:107)
    JBooth.OneBatch.OneBatchConfigEditor:CompileConfig(OneBatchConfig, List`1, String, Boolean) (at Assets/OneBatch/Editor/OneBatchConfigEditor_Compiler.cs:557)
    JBooth.OneBatch.OneBatchConfigEditor:CompileConfig(OneBatchConfig) (at Assets/OneBatch/Editor/OneBatchConfigEditor_Compiler.cs:955)
    JBooth.OneBatch.OneBatchConfigEditor:DelayedCompileConfig() (at Assets/OneBatch/Editor/OneBatchConfigEditor_Compiler.cs:299)
    UnityEditor.EditorApplication:Internal_CallDelayFunctions()

    unity version is 2019.4.11f
    One batch version is 0.95
     
  3. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    I just recently updated to Unity 2018.4.32f1.

    Since then, I'm seeing the "Packing Textures" progress bar come up any time I make a change to any scene and save it. I haven't made any changes to any OneBatch texture arrays.

    Below is an error that I'm seeing in the console.

    NullReferenceException: Object reference not set to an instance of an object
    JBooth.OneBatch.OneBatchConfigEditor.CompileConfig (JBooth.OneBatch.OneBatchConfig cfg, System.Collections.Generic.List`1[T] src, System.String ext, System.Boolean texturesOnly) (at Assets/OneBatch/Editor/OneBatchConfigEditor_Compiler.cs:880)
    JBooth.OneBatch.OneBatchConfigEditor.CompileConfig (JBooth.OneBatch.OneBatchConfig cfg) (at Assets/OneBatch/Editor/OneBatchConfigEditor_Compiler.cs:955)
    JBooth.OneBatch.OneBatchPreProcessor.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Assets/OneBatch/Editor/OneBatchPreProcessor.cs:54)
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <c8d0d7b9135640958bff528a1e374758>:0)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <c8d0d7b9135640958bff528a1e374758>:0)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <c8d0d7b9135640958bff528a1e374758>:0)
    UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:141)
     
  4. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510

    Ok, so it looks like the meshes for the OneBatch objects have 0 tris and 0 verts.

    I've tried replacing it with meshes with a valid one from version control, but Unity doesn't seem to allow it to be replaced. It still reverts back to the 0 tris version.

    Is there a recommended way to get refresh it?
     
  5. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Close unity, then do the revert from version control. I'm betting it's not reloading it properly when you revert..
     
  6. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Thanks, yea I tried that and for some reason Unity still didn't refresh it.

    I ended up doing the revert and making sure the prefabs have the original materials (some didn't for some reason), then combining once again. Thanks.
     
    Last edited: Mar 9, 2021
  7. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    I seem to have a problem with baking lightmaps in the scene that has two One Batch texture arrays in it.

    I'm getting the below error by just selecting the MeshRenderer with the OneBatch material in the scene view.

    Error assigning texarray texture to 2D texture property '_MainTex': Dimensions must match


    and I'm getting the below two error messages during the lightmap bake....which is preventing it from complete


    1
    Error assigning texarray texture to 2D texture property '_MainTex': Dimensions must match


    2
    'Export Bake Texture' job failed with error code: 2 ('Texture input is missing.').


    One Note:
    I just noticed for this texture array, I have 18 materials in the array mostly at 1024x1024. but I do have one that is 512x512
    and two that are 1024x2048.

    Would this be the problem?

    Or would OneBatch just expand the 512 texture to 1k (wasting texture memory) and the 1024x2048 get squeezed and loosing quality?

    I have the every texture set to be 1024 once baked.

    I would rather not rebake them, as there was a lot of work involved...if this is the issue, would it possible to do anything to get around this issue?
     
    Last edited: Apr 5, 2021
  8. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    It would make them all whatever size you have set in the Config.

    The errors seems to be that something is trying to assign a texture array to a shader that has a property called _MainTex but is not actually a texture array, but a traditional texture 2D. Why is the question..
     
  9. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    It looks like I found the issue.

    Not sure why this is an issue, but it seems to be related to the transparent version of the OneBatch material that was generated. Whenever I have an renderer active in a scene with the one batch transparent material on it, it gives that error. If I disable it, or remove it from the scene I no longer get that error message.
     
    Last edited: Apr 7, 2021
  10. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Did you ever look into why the generated Transparent shader might be causing that issue?
     
  11. DonCornholio

    DonCornholio

    Joined:
    Feb 27, 2017
    Posts:
    92
    Hi there @jbooth ! I couldnt find anything about this in the documentation so i guess i'd ask here :
    Can One Batch respect Material Feature switches (#pragma feature / #pragma multicompile) and only combine the materials with the same features active? So as to balance batch count and per pixel shader cost.
    I saw that you have this separation for different blend modes. If you don't have this feature yet, would you think it's feasible to add it myself building upon what you already do for blend modes?
     
  12. whitewidowmaker

    whitewidowmaker

    Joined:
    Aug 17, 2017
    Posts:
    7
    hey people,

    Is it possible to make this work with cutout or any change I can make in the code to make this work? This would be very helpful cos' my scenes are full of decals so I need them in cutout mode, but when I batch them planes, I only get the classic opaque mode(with the black background instead of the transparency) in all of them, even when I choose cutout in the Onebatchstandard shader. I also tried using a custom OneBatchShader (OneBatchCS.shader made from a guy in amplify) found in the first page of this topic, the cutout works alright there but the individual tints from the OneBatch configuration do not work with this shader...
     
  13. buc

    buc

    Joined:
    Apr 22, 2015
    Posts:
    123
    There are 2 related questions, which I couldn't find by a quick search in the 5 forum-pages and docs:

    1) Does this work with LODs, or will the LOD models produce another texture array?
    2) Is it possible to "prepare" the models in order to share the same texture array and then afterwards combine them in different combinations (different meshes get combined, all using the same texture arrays)?
    Example: you have different modules of a house, prepare them and then you can combine the modules to different houses and all houses can be combined later in a different granularity depending on the distance.
     
  14. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    1. Yes, as long as the meshes are all included in the config.
    2. The texture array and mesh modification all happens as part of the same process, from standard shaders -> One Batch. Once converted, you can't recombine them again- but you can revert, adjust your configs, and re-convert them with new models or whatever.
     
  15. Fira-Soft

    Fira-Soft

    Joined:
    Sep 9, 2014
    Posts:
    26
    Any follow up on the URP support? Are they stable and ready to be supported by One Batch?
     
    PutridEx likes this.
  16. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    no, SRPs are fundamentally unstable because unity has designed them poorly.
     
    april_4_short and hippocoder like this.
  17. AlainBirchmeier

    AlainBirchmeier

    Joined:
    May 8, 2019
    Posts:
    6
    Hi,

    We currently have a model with several submeshes and with several texture on it. We work on oculus quest and we want to reduce the number of drawcalls. We have several cameras to simulate mirrors in our games, that makes drawcalls a bottleneck for our project.
    From the documentation it sounds like it's using dynamic batching to merge meshes together. Is that correct ? If so I guess this plugin can't help us because :
    - our submeshes contains more than 900 vertices so they won't get dynamically batched together
    - From the documentation I'm not sure if your plugin support meshes with submeshes

    Can you confirm or tell me how I should setup my object to use your plugin ?
     
  18. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461

    No, it relies on static batching for combining meshes, not dynamic. (Note, dynamic is limited to 900 attributes, not vertices - which, depending on how many attributes are used, means the cap is really a few hundred vertices at most).
     
  19. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    for a Quest game you shouldn't be using cameras for mirrors at all, just use cleverly placed Reflection probes to fake it! :)
     
  20. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    I actually have made some shadergraph functions to help with this. I'm not using anything except the Albedo and color Tint, so I haven't implemented the rest, but you can complete it simply if you'd like. Just replace the shader on the generated material and it works!
     

    Attached Files:

  21. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    Reverting appears to be broken for me in 2020.x LTS, empty project, fresh import. After pressing the button nothing happens(by nothing I mean no loading bars like 2020 loves to pop up when you press anything), a few seemingly random assets do get reverted, most do not, no errors, no warnings.

    ** Edit for above: As per another user review I read on the store listing, there is a bug which needs a restart to update the changes from the revert. Because of this, you can get into a real mess if you combine again before restarting the editor, since the prefabs aren't updated OneBatch grabs the reference to its own data instead of the source data, you will lose all your revert data since it stores a new revert data based on the wrong sources and prefabs will be broken.

    Also having memory crashing on 16gb ram with around 100 prefabs at 1024x1024 per texture.

    Was able to work around the crashing for by closing everything else on my computer, being in a blank scene, etc.

    The reverting issues make it unusable for me for the time being, would be great if anyone has a fix. **Edit for anyone running into this, it seems one work around without needing to restart the project is to just hit update textures after reverting. Though I am not sure it seems to be much faster than restarting with 100 prefabs.
    upload_2021-9-14_0-43-8.png

    All the best
     
    Last edited: Sep 14, 2021
  22. SgtLame

    SgtLame

    Joined:
    Nov 26, 2015
    Posts:
    129
    Hi,
    Sorry for the probably dumb question, but whenever I send a message to VerifyInvoiceBot#2762 on the Discord server with my invoice number, I get an answer that my message coundn't be sent.
    I'm considering buying One Batch, and my (probably stupid too) question was regarding One Batch's workflow: I read the documentation and watched the Youtube tutorial, and it seems that one batch only supports prefabs.
    In the project I'm working on, scenes are procedurally generated, without the use of prefabs. So I need to use One Batch with game objects from the scene hierarchy. Is it possible?
     
  23. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    No, it only works in editor with prefabs..
     
  24. SgtLame

    SgtLame

    Joined:
    Nov 26, 2015
    Posts:
    129
    Thank you for your answer. Then I guess I could create dummy prefabs containing sets of materials I want to combine. It would then need some work with UVs though. Do you think this could work out?
     
  25. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Hard to say as I don't really know what data your working with.
     
  26. SgtLame

    SgtLame

    Joined:
    Nov 26, 2015
    Posts:
    129
    Not sure what you mean, I'm working on simple meshes representing buildings.
     
  27. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    247
    Hi is there features that account for color tints when batching, sometimes I use standard shader without textures and wondered if there is a good way to batch those into a single draw call as well as textured materials?

    EDIT: Mesh Baker helped with this... So all good!

    I was reading the manual and noticed lightmaps mentioned in Breaking Batches section as follows:

    Ideally, lightmap textures and light/reflection probe would be combined into texture arrays so that Unity would not need to break batching for these reasons, but currently Unity needs to run on platforms without texture array support

    Does this mean lightmaps can be baked into the arrays for certain platforms and does the OneBatch shader cater for it or is this not possible without extra customisation? Thanks
     
    Last edited: Jan 12, 2022
  28. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    247
    Does generate lightmap UV set take previous UV settings into account, does it copy the previous lightmaps on UV2 to the combined meshes?

    Thanks
     
    Last edited: Feb 16, 2022
  29. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    All the UV's are copied directly to the new meshes.
     
  30. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    247
    Thanks, I believe there is an issue with Unity itself that is hindering the generate UV2 lightmaps function which lead me to enquire. I can't find the bug report link I came across right now but there is one for versions near 2019.4.17 relating to the Unity function used in OneBatch code. Whatever the case I am getting a crash when generate UV2 is enabled on the latest 2019 LTS. If the generate lightmap UV mode is disabled, should my previous lightmaps still be present regardless?
     
  31. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    If your original meshes had lightmap UVs, they should be on the new meshes if you don't set it to generate them.
     
  32. x4000

    x4000

    Joined:
    Mar 17, 2010
    Posts:
    353
    Hey Jason,

    Big fan of your many works, you're one of the true unity shader wizards. I tend to learn a lot just from reading your shader code.

    In this particular instance, however, I find myself stumped. I have OneBatch, and the combination of objects and materials works just fine. The workflow is straightforward. The example in the documentation for the ASE is also straightforward.

    On my current project, I've found that I want to use a different shader system, Omnishade (in the past, I've done mostly shaders in ASE). Omnishade has very hard-to-read shader code because of all the conditional compiler if statements that come from shader properties, but it has very small amounts of resultant code with a really great visual look in-game. Specifically, their matcap blending logic is just really giving an incredible result, but I can't duplicate that result in ASE.

    I've tried to look at your OneBatch shader logic to figure out how to essentially just pull in the MainTex and NormalMap as 2DArray texture arrays, and then just blend that into the complex logic that is in Omnishade. I am guessing that the proper application of this would be to include a cginc from your code, but I can't tell for sure, and then after that to call the unity sampler scripts that are for texture arrays.

    You mentioned having to multiply the result by 255, which out of context I didn't understand. In the unity example code for shader arrays, they are passing in a uv that is a float3, with the "z" of that being an indexer to the 2DArray.

    TLDR: the actual creation of the texture arrays is going great, and using the shaders you provide also goes great. Trying to modify a complex third party shader by hand leaves me with question marks, because that isn't really documented in the same way you did for the ASE nodes. Any help is greatly appreciated!
     
  33. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    The UV.z is the index into the array, which is an int value. The vertex data is stored as 8 bit value (0-1), so index/255, such that index 7 is a value of 7/255, and needs to be multiplied by 255 to be converted back into the proper int value for the texture array lookup.

    You could also replace OneBatch's lighting functions with a matcap, if that's the main feature you need, I suggest bgolus's implementation here:

    https://gist.github.com/bgolus/02e37cd76568520e20219dc51653ceaa
     
    StevenPicard likes this.
  34. Sap_32

    Sap_32

    Joined:
    Jun 4, 2020
    Posts:
    1
    This is a very good asset. However, I am currently facing one problem.
    I want to use the prefabs that I have combined and lightened with OneBatch in other Unity projects, but when I try to package them with "ExportPackage" and import them into another project, the proptex is corrupted and does not reproduce the look and feel of the original project.
    Is there any way to convert the generated proptex to png data, etc. and take it out of the project?