Files
2nd/10_Wiki/Topics/AI_and_ML/Mipmap.md
T
koriweb d8a80f6272 chore(wiki): dangling 링크 canonical 정규화 (768파일/1200건)
이름만 다른(표기 변형) [[위키링크]]를 대상 문서의 canonical 제목으로 치환해
끊겼던 1,200개 링크를 연결. 제목/파일명 정규화 일치만 적용하고 별칭 매칭은
과병합 위험으로 제외(애매성 가드). 원본은 _link_reconcile_backup/ 에 백업.
도구: Datacollect/scripts/link_reconcile_apply.mjs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 12:24:15 +09:00

118 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: wiki-2026-0508-mipmap
title: Mipmap
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [mipmap, MIP map, LOD pyramid]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [graphics, gpu, texture, lod, sampling, opengl, vulkan]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack: { language: glsl, framework: opengl-vulkan }
---
# Mipmap
## 매 한 줄
> **"매 거리에 맞는 매 해상도"**. Mipmap 은 같은 텍스처를 1/2, 1/4, 1/8 … 로 미리 다운샘플해 둔 LOD 피라미드이며, 멀리 있는 픽셀이 작은 mip level 을 샘플링해 aliasing 과 메모리 대역폭을 동시에 줄인다.
## 매 핵심
### 매 동작 원리
- mip 0 = 원본 (e.g. 1024×1024), mip 1 = 512², mip 2 = 256², …, mip N = 1×1.
- 총 추가 메모리 = 원본의 약 33% (∑ 1/4ⁿ).
- 픽셀 footprint (∂u/∂x, ∂v/∂x …) → LOD λ 계산 → 적절 mip level 선택.
### 매 필터링
1. **Nearest mip + nearest** — 픽셀 단위 jitter.
2. **Nearest mip + linear (bilinear)** — mip 경계에서 hard switch.
3. **Linear mip + linear (trilinear)** — 두 mip level 사이 보간, 부드러움.
4. **Anisotropic** — 비스듬한 표면에서 footprint 가 늘어진 방향으로 더 많은 샘플 → 경사면 텍스처 선명.
### 매 효과
1. 멀리 있는 표면 aliasing/shimmering 제거.
2. cache hit ↑ (작은 mip 이 caches 에 잘 맞음).
3. fillrate / bandwidth 감소 → 모바일 GPU 에 특히 큼.
## 💻 패턴
### 1. OpenGL mipmap 자동 생성
```cpp
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // trilinear
```
### 2. Vulkan blit 으로 mip chain
```cpp
for (uint32_t i = 1; i < mipLevels; i++) {
VkImageBlit blit{};
blit.srcOffsets[1] = { mipW, mipH, 1 };
blit.dstOffsets[1] = { mipW>1?mipW/2:1, mipH>1?mipH/2:1, 1 };
vkCmdBlitImage(cmd, img, SRC_OPT, img, DST_OPT, 1, &blit, VK_FILTER_LINEAR);
}
```
### 3. Anisotropic
```cpp
GLfloat maxAniso;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAniso);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, std::min(8.0f, maxAniso));
```
### 4. Shader 강제 LOD
```glsl
vec4 c = textureLod(tex, uv, 2.0); // mip 2 강제
vec4 b = textureGrad(tex, uv, ddx, ddy);
```
### 5. LOD bias
```glsl
vec4 c = texture(tex, uv, -0.5); // 한 단계 더 선명 (alias 위험)
```
### 6. Streaming / partial residency
- 전체 mip 중 큰 것은 disk, 작은 것만 GPU resident (Sparse texture / DirectStorage).
### 7. Pre-built KTX2 + BasisU
```bash
toktx --genmipmap --bcmp out.ktx2 input.png
```
오프라인 generate + GPU compressed format 으로 메모리 ↓.
## 매 결정 기준
| 상황 | 설정 |
|---|---|
| 일반 3D 씬 | Trilinear + Aniso 4-8x |
| 픽셀아트 / UI | mipmap off, nearest |
| 모바일 저사양 | Bilinear + Aniso 2x |
| 거대 월드 | Streaming + Sparse mip |
| Procedural noise | runtime mip 생성 또는 explicit LOD |
**기본값**: trilinear + aniso 4x, GPU 압축 (BC7/ASTC) + KTX2 로 사전 생성.
## 🔗 Graph
- Adjacent: [[Texture Compression]], [[KTX2]]
## 🤖 LLM 활용
**언제**: filtering 차이 설명, 메모리 계산 (×1.33), shader API snippet 초안.
**언제 X**: 특정 GPU 의 anisotropic 품질/성능 측정 (실측 필요).
## ❌ 안티패턴
- mipmap off + 작게 그리기 → moiré/shimmer.
- non-POT 텍스처에 자동 mip + GL ES 2 — 일부 드라이버 문제.
- runtime `glGenerateMipmap` 매 프레임 — 첫 업로드 1회만.
- UI atlas 에 mip 생성 — bleeding 으로 인접 셀 색상 침투.
## 🧪 검증 / 중복
- Verified. 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup |