[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,99 +2,149 @@
|
||||
id: wiki-2026-0508-geometry-merging
|
||||
title: Geometry Merging
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-4349BD]
|
||||
aliases: [Mesh Merging, Static Batching, Geometry Batching]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
verification_status: applied
|
||||
tags: [graphics, optimization, rendering, gpu]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - Geometry Merging"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: C++/HLSL
|
||||
framework: Unity/Unreal/Three.js
|
||||
---
|
||||
|
||||
# [[Geometry Merging|Geometry Merging]]
|
||||
# Geometry Merging
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> **Geometry Merging(지오메트리 병합)**은 Three.js 등의 3D 렌더링 환경에서 정적(static)인 여러 개의 기하학적 데이터를 단일 `[[BufferGeometry|BufferGeometry]]`로 합치는 최적화 기법입니다. 이는 여러 개의 메쉬를 개별적으로 그릴 때 발생하는 **드로우 콜([[Draw Call|Draw Call]])을 단 1회로 줄여주어** CPU 오버헤드를 크게 감소시킵니다. 하지만 개별 객체의 독립적인 이동이나 실시간 상호작용이 제한되며, 객체가 반복될 경우 메모리 사용량이 극심하게 증가한다는 뚜렷한 한계를 가집니다.
|
||||
## 매 한 줄
|
||||
> **"매 여러 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.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
* **원리 및 렌더링 최적화 효과:**
|
||||
`BufferGeometryUtils.mergeGeometries`와 같은 유틸리티를 사용하여 로드 타임에 여러 메쉬를 하나로 병합하는 방식입니다 [1, 2]. 이 방식은 독립적인 수많은 드로우 콜을 단 하나의 드로우 콜로 결합하므로, **드로우 콜 병목 현상을 완화하는 궁극적인 해결책**을 제공합니다 [3, 4]. 움직임이 필요 없는 정적 씬이나 다수의 부품이 조립된 CAD 렌더링 모델 등에서 높은 프레임 레이트를 유지하는 데 탁월한 효과를 발휘합니다 [4].
|
||||
## 매 핵심
|
||||
|
||||
* **메모리 소모 및 상호작용의 한계:**
|
||||
병합된 지오메트리는 병합 전 개별 객체의 기하학적 데이터를 모두 고스란히 복제하여 메모리에 저장합니다. 따라서 수천 개의 동일한 객체(예: 의자)를 렌더링할 때 단일 기하 데이터만 참조하는 인스턴싱([[Instancing|Instancing]])과 달리, **메모리(RAM 및 VRAM) 소모가 기하급수적으로 증가**하는 치명적인 단점이 있습니다 [3, 5, 6]. 또한 모든 데이터가 하나로 합쳐져 있으므로, **개별 객체의 위치, 회전, 색상을 실시간으로 변경하거나 개별적인 피킹(Picking) 등 상호작용을 구현하기가 매우 까다롭습니다** [6-8].
|
||||
### 매 종류
|
||||
- **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 가능 범위 확장.
|
||||
|
||||
* **시야 절두체 컬링([[Frustum Culling|Frustum Culling]]) 비효율성:**
|
||||
모든 객체가 하나의 거대한 메쉬로 병합되면 전체가 **단일 바운딩 볼륨(Bounding volume)으로 취급**됩니다. 이로 인해 합쳐진 덩어리의 극히 일부만 카메라 시야(Frustum)에 들어오더라도 화면에 보이지 않는 나머지 전체 영역까지 모두 렌더링 연산을 수행하게 되어, 결과적으로 GPU 성능의 비효율을 초래할 수 있습니다 [4].
|
||||
### 매 trade-off
|
||||
- ↑ Throughput (fewer draw call).
|
||||
- ↓ Culling 정확도 (merged AABB 가 매 커짐).
|
||||
- ↑ Memory (per-vertex data 의 매 duplication).
|
||||
- ↓ Animation flexibility (static 한정).
|
||||
|
||||
* **실무적 대안 및 하이브리드 전략:**
|
||||
절두체 컬링의 문제를 완화하기 위해 공간적 인접성에 따라 메쉬를 나누어 병합하는 **'타일형 병합(Tiled merging)'** 전략이 권장됩니다 [4]. 또한, 메모리와 유연성 문제를 해결하기 위해 동적인 장면이 아니고 모델 크기가 작을 때(< 1GB)에만 병합을 적용하거나 [9], 정적인 저폴리곤 객체는 병합(Merging)하고 동적이거나 고폴리곤인 객체는 `[[InstancedMesh|InstancedMesh]]` 혹은 `BatchedMesh`를 사용하는 **하이브리드 시스템**이 대안으로 활용되기도 합니다 [10, 11].
|
||||
### 매 응용
|
||||
1. Mobile 게임 — draw call 의 매 hard limit (~100-200).
|
||||
2. Architectural visualization — 매 thousands of small props.
|
||||
3. Tile-based world streaming.
|
||||
4. UI batching (text glyph atlas).
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** Graphics & Performance 분야의 자동 자산화 수행.
|
||||
## 💻 패턴
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[Draw Call|Draw Call]], InstancedMesh, BatchedMesh, Frustum Culling, [[BufferGeometry|BufferGeometry]]
|
||||
- **Projects/Contexts:** IFC.js Fragment, CAD Rendering [[Optimization|Optimization]]
|
||||
- **Contradictions/Notes:** 지오메트리 병합은 드로우 콜을 크게 줄여 렌더링 속도를 높이는 장점이 있지만, 단일 바운딩 박스로 묶이게 되어 시야 절두체 컬링 효율성이 떨어지고 메모리 사용량이 극도로 높아져 하드웨어 자원을 쉽게 고갈시킬 수 있다는 트레이드오프(Trade-off)가 존재합니다 [3, 4].
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-19*
|
||||
|
||||
---
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
### Manual merge (Three.js)
|
||||
```javascript
|
||||
import { mergeGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
||||
const geos = props.map(p => p.geometry.clone().applyMatrix4(p.matrixWorld));
|
||||
const merged = mergeGeometries(geos, false);
|
||||
const mesh = new THREE.Mesh(merged, sharedMaterial);
|
||||
scene.add(mesh);
|
||||
// 1000 draw calls → 1
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Unity static batching
|
||||
```csharp
|
||||
// Mark objects as static in Inspector → Unity merges at build time.
|
||||
// Or runtime:
|
||||
StaticBatchingUtility.Combine(rootGameObject);
|
||||
// Caveat: combined mesh 64k vertex 한도 (16-bit index).
|
||||
```
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### GPU instancing (preferred over merge)
|
||||
```glsl
|
||||
// vertex shader (Unity URP)
|
||||
struct Attributes {
|
||||
float3 positionOS : POSITION;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
UNITY_INSTANCING_BUFFER_START(Props)
|
||||
UNITY_DEFINE_INSTANCED_PROP(float4, _Color)
|
||||
UNITY_INSTANCING_BUFFER_END(Props)
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
Varyings vert(Attributes IN) {
|
||||
UNITY_SETUP_INSTANCE_ID(IN);
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### Texture atlas (enable merging across materials)
|
||||
```python
|
||||
# Bake separate textures into one atlas → assign UV remap.
|
||||
import numpy as np
|
||||
atlas = np.zeros((2048, 2048, 4), np.uint8)
|
||||
uv_remap = {}
|
||||
for i, tex in enumerate(textures):
|
||||
x, y = (i % 8) * 256, (i // 8) * 256
|
||||
atlas[y:y+256, x:x+256] = tex
|
||||
uv_remap[i] = (x/2048, y/2048, 256/2048, 256/2048)
|
||||
# Then rewrite mesh UVs per material id.
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Multi-draw indirect (modern alt)
|
||||
```cpp
|
||||
// Instead of merging, keep mesh separate but submit via single indirect call.
|
||||
struct DrawCmd { uint32_t indexCount, instanceCount, firstIndex, vertexOffset, firstInstance; };
|
||||
std::vector<DrawCmd> cmds; // one per visible mesh
|
||||
glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, cmds.data(), cmds.size(), 0);
|
||||
```
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
### Hierarchical merge (octree)
|
||||
```python
|
||||
def merge_octree(node):
|
||||
if node.is_leaf and len(node.meshes) > 1:
|
||||
node.merged = merge(node.meshes)
|
||||
else:
|
||||
for c in node.children: merge_octree(c)
|
||||
# Coarse cull on octree node, fine draw merged buffer.
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 同 mesh 다수 | GPU instancing (best) |
|
||||
| Static, 多 unique mesh | Static merging + atlas |
|
||||
| Modern API (Vk/D3D12) | Indirect draw + bindless |
|
||||
| Mobile / WebGL legacy | Static batching + atlas |
|
||||
| Animated / dynamic transform | Per-object draw + culling |
|
||||
|
||||
**기본값**: Modern HW → instancing/indirect. Legacy → static merge + atlas.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Rendering Optimization]] · [[Draw Call]]
|
||||
- 변형: [[GPU Instancing]] · [[Mesh Shader]] · [[Indirect Draw]]
|
||||
- 응용: [[Texture Atlas]] · [[Octree]] · [[BVH]]
|
||||
- Adjacent: [[Frustum Culling]] · [[LOD]] · [[Vertex Buffer]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: Mobile / web renderer 최적화, asset pipeline 설계.
|
||||
**언제 X**: Highly dynamic scenes (animation/destruction).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Merge everything**: 매 culling 효과 무력화.
|
||||
- **Material 다른 mesh merge**: shader switch 강제 → benefit 없음.
|
||||
- **Skinned mesh static merge**: 매 animation broken.
|
||||
- **64k vertex 한계 모름**: 16-bit index 의 매 silent overflow.
|
||||
- **Modern API 에서 merge 만 사용**: indirect/instancing 무시.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Unity docs, Three.js BufferGeometryUtils, GPU Pro series).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — merging vs instancing/indirect 의 trade-off |
|
||||
|
||||
Reference in New Issue
Block a user