Mass Battle Frameworkv1.20.0

一个单位二三十个材质球,帧数是怎么被吃掉的 Thirty Material Slots per Unit, and Where the Frame Rate Went

RENDERING

资产侧的合并工具为什么非做不可 · 2026-11-21Why the asset-merging tools had to exist · 2026-11-21

系列这些文章写给人和他的 agent 一起看。这套文档怎么读 →SeriesThese posts are for you and your agent. How to read these docs →

从一个真实的资产包说起 Start With a Real Asset Pack

拿一套男女角色的资产包来烘。每个部件有四五个材质球,每个材质球还都是各自独立的母材质。单看一个部件没什么;烘成一个单位就不一样了:五六个身体部件,每个部件四五个槽,加起来就是二三十个材质球。

Take a men-and-women character pack and bake it. Every part carries four or five material slots, and every slot has its own parent material. One part on its own looks harmless; bake it into a unit and the total shows up: five or six body parts at four or five slots each, twenty to thirty material slots.

一个材质槽就是一次绘制。二三十个槽,同一个单位每帧就要画二三十次;每次的材质还不一样,批不起来。几百个单位的时候看不出来,到五千个,我的 5070 Ti 已经吃不消了。

One material slot is one draw. Twenty or thirty slots means the same unit is drawn twenty or thirty times a frame, and every one of those materials differs, so nothing batches. At a few hundred units you do not notice. At five thousand my 5070 Ti was already struggling.

这已经比骨骼网格好很多了。可这个框架瞄的是十万级,"比谁好"没意义,能到十万才有意义。所以这套合并工具是非做不可的。

That was already far better than skeletal meshes. But this framework aims at a hundred thousand units, and "better than the alternative" buys nothing there; reaching a hundred thousand is the only question. The merging tools therefore had to exist.

这些数字不用凭感觉量。扫描类命令先列出"会被改动的网格",应用完再看每个网格还剩几个槽。把前后的每单位槽数、网格数记下来,比"感觉快多了"可靠,下次再整理也有个对照。

You do not have to eyeball these numbers. The scan commands list which meshes would change; after applying, read how many slots each mesh kept. Write down the before and after — slots per unit, meshes per unit — and you have something far more reliable than "it feels much faster", plus a baseline for the next cleanup.

两件事要分开数:网格数、槽数 Two Counts, Not One

优化时最容易搞混的一点:网格数量和材质槽数量是两个独立的数。合网格只降前者,槽数一个不少,合并后的网格照样把那几个槽串在自己身上。决定绘制次数的是槽数。

The easiest mix-up while optimising: mesh count and material slot count are independent numbers. Merging meshes only lowers the first; the slot count does not move, because the merged mesh still carries all those slots. Draw count follows the slot count.

所以整理一个单位的资产分三步,一步对一个数:

So tidying a unit takes three moves, each aimed at one number:

动作Move降的是什么What it lowers工具Tool
多个部件合成一份网格Merge parts into one mesh 网格数量(槽数不变)Mesh count (slot count unchanged) Merge Meshes
把一份网格的多个槽烘成一张图集Bake a mesh's slots into one atlas 槽数:一份网格只剩一个槽Slot count: one slot per mesh Merge Mat Slots
把多份网格的材质指回同一个母材质Point every mesh's material at one parent 母材质数量,以及打包时的着色器组合Parent-material count, and the shader permutations at cook time MaterialMergeMaterialMerge

理想状态长什么样 What the Ideal Looks Like

三步都做完,最理想的样子是:一个母材质,几个网格,每个网格只有一个槽,槽里挂材质实例(MIC)。画的时候一份网格一次绘制,实例之间只差参数,引擎能把它们排在一起批掉。

With all three done, the ideal is one parent material, several meshes, one slot each, a material instance in every slot. Drawing is one draw per mesh, and instances differ only in parameters, so the renderer can sort them together and batch.

槽合成图集这一步值得单独讲。它把多个材质真的合成一个:原来的槽可能用着不同的母材质、不同的混合方式、不同的参数集,合并时这些差别都得统一进一张图集和一个材质。所以这个工具不能瞎合。动手之前它先扫一遍,把不能合的、缺参数的直接拒掉;不会给你一份看起来合了、进游戏却是空的资产。

Slot-atlas merging deserves its own paragraph. It really merges several materials into one: the slots may have used different parents, different blend modes, different parameter sets, and all of that has to be reconciled into one atlas and one material. Hence the tool refuses where it cannot help. It scans first and rejects what it cannot honour or what is missing parameters; it will not hand you an asset that looks merged and renders empty in game.

统一母材质:不提性能,但打包快很多 One Parent: No Speed-Up, Much Faster Cooking

这一步常被误解。说清楚:把多个网格的材质指向同一个母材质,不会提高运行时性能。绘制次数还是那些,实例还是那些。它影响的是另一头,打包。

This step gets misread, so let me be exact: pointing several meshes at one parent material does not improve run time. The draw count stays, the instances stay. What it changes sits at the other end, in cooking.

母材质越多,打包时编译器就要为越多的材质图各编一套着色器组合。收成一个母材质,这些组合塌缩成一套,cook 时间明显短、包体更小。一个工程有几十种单位,这个差别每天都在。

Every extra parent material means another material graph the cooker compiles a permutation set for. Collapse them into one and the sets collapse with them: noticeably shorter cooks and smaller packages. On a project with dozens of unit types you feel that every day.

但这条不是无条件的,有个例外:母材质是一份着色器参数与功能的契约。把需要溶解的单位和根本不用溶解的单位并到同一个母材质上,母材质就得带上溶解的开关和采样,这笔代价落在所有用到它的像素上。同一族单位统一没问题;跨族合并之前,先看功能是不是超集。如果为了省 cook 时间把功能并成超集,付出去的是每帧。

The rule has one exception worth spelling out: a parent material is a contract over shader parameters and features. Fold a unit that needs dissolve in with one that never will, and the parent has to carry dissolve's switches and samples; every pixel that uses it pays. Unifying inside one family of units is safe. Before merging across families, check whether the feature set is a superset, because the cook time you save can come out of your frame time.

工具是人用的,也是 AI 用的 Tools for Hands and for Agents

三个动作面板里都有,命令层里也都有。批量处理不用点:SkelMerge.Scan 看会合哪些,SkelMerge.Apply 带 dryRun 预演;接着 SlotMerge.Scan → SlotMerge.BakeAtlas 把槽合成图集;最后 MaterialMerge.Analyze(只读计划)→ MaterialMerge.Apply 统一母材质。每一步都返回改了哪些资产、哪些被拒、为什么。

All three live in panels and in the command layer. Bulk work needs no clicks: SkelMerge.Scan lists what would merge, SkelMerge.Apply with dryRun rehearses it; then SlotMerge.Scan → SlotMerge.BakeAtlas folds slots into an atlas; last, MaterialMerge.Analyze (a read-only plan) → MaterialMerge.Apply unifies the parent. Every step reports which assets changed, which were refused, and why.

用法和拒绝条件在工具教程里逐条写了。这里只提醒一件事:先扫描、再应用。合并会改写资产引用,有些工具还会覆盖源资产。范围扫错一次,几百份资产就得重做。

The usage details and refusal conditions are written out in the tooling tutorial. One warning here: scan first, apply second. Merging rewrites asset references, and some tools overwrite the source asset outright; get the scope wrong once and hundreds of assets have to be redone.

为什么这件事值得写出来 Why This Belongs in a Design Note

因为"一个单位有多重",既要看引擎画得多快,也要看你的资产里有多少多余的东西。二三十个材质球来自资产的组织方式,跟引擎无关;把这层收干净,同样的硬件能装下几倍的单位。

Because how many units fit depends on two things: how fast the engine draws, and how much redundancy your assets carry. Twenty or thirty slots are a product of how the assets were organised, and the engine has nothing to do with them. Clean that layer up and the same hardware holds several times the units.

这层工作最烦的地方是它手工、重复、容易出错。所以它该做成工具,不能靠人的耐心。

The worst part of this work is that it is manual, repetitive and easy to get wrong. That is why it should be a tool, not a test of patience.

Leroy Works · Mass Battle Framework 作者
联系:Discord · QQ 群 916358710 · Fab · 全部联系方式

Leroy Works — author of Mass Battle Framework
Contact: Discord · QQ group 916358710 · Fab · all channels