"매 여러 mesh 를 매 단일 vertex/index buffer 로 합쳐 매 draw call 수를 매 줄이는 기법". CPU-GPU command overhead 의 매 frame budget 의 매 dominant share 였던 시대의 매 staple optimization. 매 modern era — GPU instancing, indirect draw, mesh shader 가 매 알 수 있게 대체했지만 매 static scene, mobile, low-end 에서 매 still relevant.
매 핵심
매 종류
Static batching: build-time 에 같은 material 의 static mesh 합침.
Dynamic batching: runtime 에 small mesh 를 transform & merge (CPU cost ↑).
GPU instancing: 같은 mesh 여러 transform — merging 의 modern 대체.
Mesh atlas (texture array): material 통합으로 merge 가능 범위 확장.
매 trade-off
↑ Throughput (fewer draw call).
↓ Culling 정확도 (merged AABB 가 매 커짐).
↑ Memory (per-vertex data 의 매 duplication).
↓ Animation flexibility (static 한정).
매 응용
Mobile 게임 — draw call 의 매 hard limit (~100-200).
Architectural visualization — 매 thousands of small props.
// Mark objects as static in Inspector → Unity merges at build time.// Or runtime:StaticBatchingUtility.Combine(rootGameObject);// Caveat: combined mesh 64k vertex 한도 (16-bit index).
# Bake separate textures into one atlas → assign UV remap.importnumpyasnpatlas=np.zeros((2048,2048,4),np.uint8)uv_remap={}fori,texinenumerate(textures):x,y=(i%8)*256,(i//8)*256atlas[y:y+256,x:x+256]=texuv_remap[i]=(x/2048,y/2048,256/2048,256/2048)# Then rewrite mesh UVs per material id.
Multi-draw indirect (modern alt)
// Instead of merging, keep mesh separate but submit via single indirect call.
structDrawCmd{uint32_tindexCount,instanceCount,firstIndex,vertexOffset,firstInstance;};std::vector<DrawCmd>cmds;// one per visible mesh
glMultiDrawElementsIndirect(GL_TRIANGLES,GL_UNSIGNED_INT,cmds.data(),cmds.size(),0);
Hierarchical merge (octree)
defmerge_octree(node):ifnode.is_leafandlen(node.meshes)>1:node.merged=merge(node.meshes)else:forcinnode.children:merge_octree(c)# Coarse cull on octree node, fine draw merged buffer.