[DEPRECATED] Batch Few | Mesh Combiner and Material Merger

"BATCHFEW HAS BEEN DEPRECATED FROM THE ASSET STORE AND WILL NO LONGER BE SOLD AS A SEPARATE PRODUCT. BATCHFEW WILL NOW ONLY EXIST AS AN INTEGRATED PART OF POLYFEW. IF YOU WANT TO USE BATCHFEW PLEASE PURCHASE POLYFEW. PLEASE NOTE THAT THIS THREAD MIGHT AS WELL BE DELETED IN THE NEAR FUTURE. "

One of the elements that negatively effects the performance of a 3d application is frequent communication between the GPU and the CPU. To keep your games running smooth you need to keep this communication less frequent. There are two main factors that increase this communication.

Draw Calls: A draw call is a call to the GPU to draw objects. A lot of meshes that use different materials, all cannot be sent to the GPU in a single draw call to be rendered. Thus they cause a lot of draw calls. One way around this problem is to combine several meshes together, ultimately lowering their count.

SetPass Calls: Draw call sets up a mesh and submits it for rendering, whereas a SetPass call is when all the data from a material for rendering a mesh is setup. Each time a material is changed, it results in a new SetPass call. So to lower this number you can combine/merge materials to keep their count low.

In short If you have a complex scene containing a lot of 3d models with a lot of meshes that use a lot of different materials, the overall performance of your game will suffer. Batch few is a Mesh combining and Material merging solution for unity that aims to solve this problem by allowing you to optimize high quality complex 3d scenes by lowering DrawCalls and SetPass calls with a few clicks and, without the need of writing even a single line of code. Mesh and material combining are especially useful when developing for resource constrained platforms like mobile phones or other low end devices. This can also help eliminate your expenses for artists.

If you’re looking for a complete optimization package that does this and much more, check out Poly Few

Read the API Docs

Supported features:

▓ Mesh combining and Material combining in one package.

▓ Supports combining both Static and Skinned meshes. Even supports combining rigged Skinned meshes and or Skinned meshes with blendshape/morph animations.

▓ Combine materials using Texture Arrays. Only supports the Standard Shader (Specular and Non Specular setup).

▓ Texture Array based material combiner doesn’t suffer with the common problems of texture atlases like texture bleeding, resolution limitation and no tiled texture support.

▓ Allows adjusting individual material properties even after combining materials together.

▓ Packs everything in a convenient inspector window that pops up right under the components hierarchy.

▓ No coding knowledge is required. Use the full features of the tool in editor mode without writing even a single line of code.

▓ All the source code is included without encapsulation using dll files or any other means.

▓ Includes editor tooltips for every control to ease understanding and usage of the tool.
Check out the video:
_https://www.youtube.com/watch?v=wjSYpydThsw**_
Screenshots:
__





**__

2 Likes

Hi there!
Batch few seems really great and I think texture arrays is the way to go instead of atlases :slight_smile:
I have some doubts though:
When using texture compression, texture arrays must be generated per build target.
In example, when you switch a project from iOS to Android, consoles or desktop, you have to use different compression formats for each one of them.
Since Unity doesn’t have any editor texture importer dialog for texture arrays, the recompression must be done by script.
Does Batch Few have any way to rebuild the texture array assets when changing the build target?

Hi, Batch Few doesn’t have a way to this through the standard UI at the moment. You’ll have to recompress using custom scripts. It seems quite silly to not have included this feature :(. Give me a few days and I’ll add this as a standard feature in the BatchFew UI.

EDIT: The requested feature has been added in v2.2

Awesome! Thanks!
You have a new customer :slight_smile:
Also, a button to batch-recompress lots of texture arrays at once would be needed. Otherwise the user would have to manually find each BatchFew script in each scene to manually recompress each one.

Thank you for being my customer :slight_smile: and thanks a lot for the useful suggestion. The user would be able to select multiple texture arrays and recompress them to the format of their choice.

1 Like

Hi @atomicjoe , I have pushed a new update to add the requested feature. You’ll have the ability to add multiple texture arrays that have already been generated and change various properties for them. I’ll make a small video to demonstrate the same soon.

1 Like

Yeah cool!! Thank you! :slight_smile:

I just downloaded Batch Few and was trying it out with the demo scene.
Overall it’s great! But I have some issues and some constructive criticism:

1- it would be nice to be able to set all texture properties at once instead of one by one. A button to apply the current settings to ALL textures would fix that easily. Like the reset button but applying the currently selected texture settings to all other textures at once. (to apply the texture size, compression, aniso level and quality to all other textures at once)

2- Even though Colors alpha is baked and can be modified after the bake, the BatchFewStandard shader just ignores it to calculate the transparency of the pixels.

3- (EDIT: I was wrong)

4- The Batch Few editable material properties after baking are easily confused when using several materials per renderer and several children objects with shared materials. Making some materials editable and others not, and showing more materials to edit than the materials in the renderer, duplicating entries. (I’ll send you a repro project for that)

5- ASTC compression is set to ASTC_RGBA_4x4, which weirdly isn’t compatible with Android builds. Setting it to ASTC_4x4 instead fixes the errors and stores RGBA channels anyway.

Even though there are some issues here and there, I really think Batch Few is set to be the best material and mesh combiner of the Asset Store and I’m really happy I bought it :slight_smile:

Oh, actually Batch Few DOES generate different materials for each opacity Rendering Mode!
The issue is that the materials are not correctly rendered until you select them in the editor.
Seems like the custom material editor script needs to be executed to set some keywords or flags in the shader.
If you just press “Combine Materials”, the transparent materials are not correctly set, even on builds. You have to manually select the materials in the editor for them to be corrected.

I see in the MaterialCombiner.cs code that you tried to fix this by selecting each generated material one after the other, but it’s not working.
Selecting all of them at once do works perfectly though :wink:

                // Bug in some newer versions of Unity doesn't load generated materials unless they are selected
                // This can cause objects to look different
                generatedMaterials = new Material[usedMaterials.Count];
                usedMaterials.CopyTo(generatedMaterials);
                Selection.objects = generatedMaterials;
1 Like

Another little thing:
You hard-coded the default texture property values all over the code, making it hard to change them globally.
I modified the source to use constant variables for this to change the defaults easily:

    public class MaterialCombiner : MonoBehaviour
    {
        public const int DEFAULTWIDTH = 6;
        public const int DEFAULTHEIGHT = 6;
        public const int DEFAULTFILTERING = 2;
        public const int DEFAULTCOMPQUALITY = 1;
        public const int DEFAULTCOMPTYPE = 0;
        public const int DEFAULTANISO = 8;

I can send you the modified code if you want.

Thanks for corrections. You can send me the modified scripts @ kbawar555@gmail.com

Hi I’m getting learning batch few and poly few for now.
kitbash3d model combine materials and meshes but error happen at console .

Nothing combined in GameObject "KB3D_NEC_BldgMD_C_AntennaA". Not enough feasible static meshes to combine. Consider selecting the option of combining both skinned and static meshes.
UnityEngine.Debug:LogWarning(Object)
BrainFailProductions.PolyFew.<>c__DisplayClass117_1:<DrawBatchFewUI>b__2(String, String) (at Assets/PolyFew/Scripts/Editor/InspectorDrawer.cs:4038)
BrainFailProductions.PolyFew.UtilityServices:CombineMeshes(GameObject, String, String, Action`2, MeshCombineTarget, Boolean) (at Assets/PolyFew/Scripts/NonEditor-Scripts/UtilityServices.cs:2137)
BrainFailProductions.PolyFew.InspectorDrawer:smile:rawBatchFewUI(Boolean) (at Assets/PolyFew/Scripts/Editor/InspectorDrawer.cs:4035)
BrainFailProductions.PolyFew.InspectorDrawer:OnInspectorGUI() (at Assets/PolyFew/Scripts/Editor/InspectorDrawer.cs:3613)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Mesh Filter on GameObject KB3D_NEC_BldgMD_CCombined_Meshes does not have a mesh and was skipped
UnityEngine.Debug:LogWarning(Object)
BrainFailProductions.PolyFew.MaterialCombiner:InitializeFromGameObjects(List`1, TextureArrayGroup, DiffuseColorSpace, Boolean, Action`1) (at Assets/PolyFew/Scripts/NonEditor-Scripts/MaterialCombiner.cs:683)
BrainFailProductions.PolyFew.MaterialCombiner:CombineMaterials(GameObject[], String, TextureArrayGroup, DiffuseColorSpace, Boolean, Boolean, Action`1) (at Assets/PolyFew/Scripts/NonEditor-Scripts/MaterialCombiner.cs:1048)
BrainFailProductions.PolyFew.InspectorDrawer:smile:rawBatchFewUI(Boolean) (at Assets/PolyFew/Scripts/Editor/InspectorDrawer.cs:3789)
BrainFailProductions.PolyFew.InspectorDrawer:OnInspectorGUI() (at Assets/PolyFew/Scripts/Editor/InspectorDrawer.cs:2827)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Pack Margin was set too high: it was scaled down automatically. (mesh ‘KB3D_NEC_BldgMD_B_Main’)

I’m change batch few parameter but could’nt fix it.
I’m not sure how do i solve such problem.
thanks in advance.

In order to combine meshes you must have more than 1 mesh. The error is telling you the same thing. The total static meshes (Meshes attached on mesh filter component) in gameobject “KB3D_NEC_BldgMD_C_AntennaA” (including the static meshes in all the children) are one or less.

If you don’t understand this just try this.
Create a cube GameObject and click on it and then click “Combine meshes” in batchfew. It would give you the same error, because you only have one mesh. You must have multiple meshes to be combined. Now create another cube and make it a child of the first cube. Now select the first cube and click “combine meshes” and this time the meshes will be successfully combined because you now have 2 static meshes from 2 cubes to be combined.

Reach out to me @kbawar555@gmail.com for further assistance.

Hi, I’m greatly interested in your plugin for a project I’m currently working on, but I would ask you if it supports Unity URP-HDRP (and their materials/shaders) or if it’s limited to the Built-in render pipeline (Standard shader).

Hi, No HDRP or URP is supported for the material combining operation (Only Unity Standard Shader). The mesh combiner would work fine though.

How do you save and access the material properties ? I am trying to figure out, if i should buy One Batch or Batch Few.

Is it possible to adapt the material combination to new shaders (especially on URP!) and how much work would you estimate would that be for someone who breathes shaders and writes scripts every other day?

Also how does this Asset compare to One Batch ? I am particularly interested about where you store the data in the mesh to access the material properties and array indexes. One Batch stores this in Vertex Color R and Alpha channel and then uses multiple samples of the property texture with different UVs. That makes me wary that it will have an performance impact on Oculus Questm due to the many Texture Sampling Operations. Do you have a different strategy for retrieving the values?

Also how do you save the individual meshes after materials have been combined and the mesh properties for index and texture property sampling have been applied? Is it as easily reversable as One Batch’s system?

Thanky you :slight_smile:

Hello, I’m sorry for the late response. For some reason, I didn’t get the alert in my email inbox when you posted.

First, most of the material combiner (the shader part) was based on an open-source MIT licensed project which has long been removed from Gitlab for some reason. The way how texture arrays work is that it has to rewrite the shader to make them compatible with the texture arrays. So for example, combining unity standard shader materials require the rewrite of UnityStandardShader. This is the reason why BatchFew uses a custom shader which is a modded version of the UnityStandardShader to support texture arrays (This shader comes from the open-source project).

Now you can’t change the same “BatchFewStandardShader” to make it a “URPShader” that supports texture arrays. You’ll have to get the source code to unity’s URPShaders and then rewrite it to support texture arrays and that isn’t a good idea at the moment. Unity’s URP and HDRP pipeline is still not mature and they are changing shader codes at the moment. So you’ll also have to keep up to date with their changes as well which makes it more tedious.

I don’t know how OneBatch works but what you just stated is essentially the principle behind BatchFew as well.
It stores the indexing info in the mesh vertex colors in r and alphas and then uses a customized asset “AttributesImage” that basically stores material properties from the combined materials.
Unfortunately, multiple texture sampling does occur, but it isn’t so impactful on performance as much as a large number of uncombined materials and meshes are. So at the end of the day in most cases, you gain far better performance than raw uncombined stuff.

Heyho ! Thanks for taking the time to write such a long answer, that clears a bunch of stuff up.
What i still would like to know, is how much work from the c# side of things it would be to adapt this to an other shader. I am working on mobile VR projects, so i am always deep into shaders and usually modify everything anyways to get best performance. I am not worried about the shader side, rather about the c# code and wether it’s well readable / built to be adapted to other shaders at least to some degree.
Also does your system recognize when multiple materials share the same textures and reuse them in the array instead of just adding another instance to it?

Hello I am interested in BatchFew but I had a couple questions.

-Is there a way to combine skinned meshes at runtime programmatically(if the objects use the same material)?

-Does BatchFew use it’s own shader(after combining) instead of using the original shader for the object?