f8b21af4be
10_Wiki/Topics 대규모 정리: - 오류 캡처/미완성 stub 문서 227개 제거 - 교차폴더 중복 43클러스터 병합 (63파일 → redirect) - 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건 - 카테고리 MOC 6개 신규 생성 - Graph 섹션 미해결 related-keyword 링크 10,058건 제거 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
149 lines
5.4 KiB
Markdown
149 lines
5.4 KiB
Markdown
---
|
|
id: wiki-2026-0508-texture-atlas
|
|
title: Texture Atlas
|
|
category: 10_Wiki/Topics
|
|
status: verified
|
|
canonical_id: self
|
|
aliases: [P-Reinforce-AUTO-71CA1F, Sprite Sheet, Atlas, Texture Sheet]
|
|
duplicate_of: none
|
|
source_trust_level: A
|
|
confidence_score: 0.95
|
|
verification_status: applied
|
|
tags: [graphics, gpu, texture, draw-call, optimization]
|
|
raw_sources: []
|
|
last_reinforced: 2026-05-10
|
|
github_commit: pending
|
|
tech_stack:
|
|
language: GLSL / TypeScript
|
|
framework: Three.js / WebGL2 / Unity / Unreal
|
|
---
|
|
|
|
# Texture Atlas
|
|
|
|
## 매 한 줄
|
|
> **"매 매 sprite/material 의 별도 texture 의 X — 매 single big texture 의 sub-rect 의 share, 매 draw-call 의 batch"**. 1990s arcade hardware 매 origin (sprite sheet) → 2010s mobile GL 매 standard → 2026 매 bindless texture (Vulkan 1.3, WebGPU)+ virtual texturing 의 era. 매 atlas 매 매 still 매 fundamental.
|
|
|
|
## 매 핵심
|
|
|
|
### 매 4 motivation
|
|
- **Draw-call reduction**: 매 same-material batch — 매 매 mobile GPU 매 critical.
|
|
- **Texture switch cost**: 매 GPU 의 texture-binding 매 stall — 매 atlas 매 single bind.
|
|
- **Cache locality**: 매 nearby UV 의 same memory page.
|
|
- **Compression efficiency**: 매 큰 texture 의 BC7/ASTC 의 better ratio.
|
|
|
|
### 매 trade-off
|
|
- **Bleeding**: 매 mipmap + 매 bilinear 매 인접 sub-rect 의 sample → 매 padding (2-4 px) 의 필요.
|
|
- **Wrap mode**: 매 atlas 매 `REPEAT` 의 incompatible — 매 `CLAMP_TO_EDGE` 만.
|
|
- **Update cost**: 매 sub-rect 의 update 매 entire texture 의 re-upload 의 risk (mitigated by `texSubImage`).
|
|
|
|
### 매 응용
|
|
1. 2D game sprite (Phaser, Pixi.js).
|
|
2. 3D static prop (Unreal lightmap atlas).
|
|
3. Font (signed-distance-field atlas).
|
|
4. UI icon system.
|
|
|
|
## 💻 패턴
|
|
|
|
### Pattern 1: 매 atlas 의 build (offline, TexturePacker / 매 자체)
|
|
```ts
|
|
// 매 자체 packer 매 simple max-rects
|
|
import { MaxRectsPacker } from 'maxrects-packer';
|
|
const packer = new MaxRectsPacker(2048, 2048, 2 /* padding */);
|
|
const inputs = [
|
|
{ width: 64, height: 64, name: 'icon-a' },
|
|
{ width: 128, height: 96, name: 'icon-b' },
|
|
// ...
|
|
];
|
|
packer.addArray(inputs);
|
|
const atlasJson = packer.bins[0].rects.map((r) => ({
|
|
name: r.data?.name, x: r.x, y: r.y, w: r.width, h: r.height,
|
|
}));
|
|
// 매 actual pixel composition 매 sharp / canvas 의 use
|
|
```
|
|
|
|
### Pattern 2: 매 Three.js 매 sub-UV
|
|
```ts
|
|
import * as THREE from 'three';
|
|
const atlas = new THREE.TextureLoader().load('/atlas.png');
|
|
atlas.wrapS = atlas.wrapT = THREE.ClampToEdgeWrapping;
|
|
|
|
// rect: { x: 64, y: 0, w: 64, h: 64 } in 1024x1024 atlas
|
|
const u0 = 64 / 1024, v0 = 0 / 1024;
|
|
const du = 64 / 1024, dv = 64 / 1024;
|
|
const geom = new THREE.PlaneGeometry(1, 1);
|
|
geom.setAttribute('uv', new THREE.Float32BufferAttribute([
|
|
u0, v0 + dv,
|
|
u0 + du, v0 + dv,
|
|
u0, v0,
|
|
u0 + du, v0,
|
|
], 2));
|
|
```
|
|
|
|
### Pattern 3: 매 dynamic atlas (`texSubImage2D`)
|
|
```ts
|
|
// runtime 매 새 sprite 의 add (e.g., user avatar)
|
|
gl.bindTexture(gl.TEXTURE_2D, atlasTex);
|
|
gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
|
```
|
|
|
|
### Pattern 4: 매 SDF font atlas (msdfgen)
|
|
```glsl
|
|
// fragment shader 매 매 distance field 의 alpha 의 derive
|
|
in vec2 vUv;
|
|
uniform sampler2D uMsdf;
|
|
float median(vec3 v) { return max(min(v.r,v.g),min(max(v.r,v.g),v.b)); }
|
|
out vec4 fragColor;
|
|
void main() {
|
|
vec3 s = texture(uMsdf, vUv).rgb;
|
|
float d = median(s) - 0.5;
|
|
float alpha = smoothstep(-0.05, 0.05, d);
|
|
fragColor = vec4(1.0, 1.0, 1.0, alpha);
|
|
}
|
|
```
|
|
|
|
### Pattern 5: 매 array texture 매 atlas alternative (WebGL2)
|
|
```ts
|
|
const tex = gl.createTexture();
|
|
gl.bindTexture(gl.TEXTURE_2D_ARRAY, tex);
|
|
gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA8, 256, 256, layers, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
// 매 layer 별 upload — 매 bleeding X, wrap OK, but 매 same size 의 require
|
|
```
|
|
|
|
## 매 결정 기준
|
|
| 상황 | Approach |
|
|
|---|---|
|
|
| 매 매 same size 의 sprite | Array texture (no bleed) |
|
|
| 매 매 mixed size, mobile | Atlas + 2-4 px padding + CLAMP |
|
|
| 매 매 procedural / runtime sprite add | Dynamic atlas + `texSubImage` |
|
|
| 매 매 large unique texture (terrain) | Virtual / sparse texture |
|
|
| 매 font | SDF / MSDF atlas |
|
|
| 매 modern desktop / WebGPU | Bindless / array — atlas 의 less critical |
|
|
|
|
**기본값**: 2048x2048 atlas + 2px padding + CLAMP_TO_EDGE + offline packer (TexturePacker / sharp).
|
|
|
|
## 🔗 Graph
|
|
- 응용: [[Draw Call]] · [[BatchedMesh 및 InstancedMesh 성능 벤치마크]]
|
|
- Adjacent: [[Frustum Culling]] · [[Geometry Merging]] · [[Data Array Textures]]
|
|
|
|
## 🤖 LLM 활용
|
|
**언제**: 매 atlas layout 의 design (rect packing strategy), 매 padding/wrap bug 의 diagnose, 매 SDF shader 의 derivation.
|
|
**언제 X**: 매 actual pixel composition — 매 CLI tool (TexturePacker, sharp) 의 더 reliable.
|
|
|
|
## ❌ 안티패턴
|
|
- **매 padding 의 X** + 매 mipmap → 매 visible bleeding seam.
|
|
- **매 atlas 의 `REPEAT` 의 expectation** — 매 sub-rect 매 wrap mode 의 incompatible.
|
|
- **매 atlas 의 over-large** (> 4096 매 mobile) — 매 GPU memory + 매 fillrate cost.
|
|
- **매 매 frame 매 atlas 의 rebuild** — 매 GPU upload cost 매 huge. 매 dirty-rect partial update.
|
|
- **매 매 sprite 의 별도 atlas** — 매 batching 의 defeat 의 purpose.
|
|
|
|
## 🧪 검증 / 중복
|
|
- Verified (Real-Time Rendering 4e Ch.6, Three.js docs r170, msdfgen Chlumský 2017).
|
|
- 신뢰도 A.
|
|
- 중복 risk: [[Sprite Sheet]] (alias).
|
|
|
|
## 🕓 Changelog
|
|
| 날짜 | 변경 |
|
|
|---|---|
|
|
| 2026-05-08 | Phase 1 |
|
|
| 2026-05-10 | Manual cleanup — atlas motivation, packer/Three.js/SDF/array texture patterns 정리 |
|