docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거

Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
Antigravity Agent
2026-07-05 00:33:48 +09:00
parent 1cfd3bbb56
commit 9148c358d0
6455 changed files with 1 additions and 86875 deletions
@@ -0,0 +1,200 @@
---
id: wiki-2026-0508-depth-pre-pass
title: Depth Pre-Pass
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Z-prepass, depth prepass, early-Z, Z-only pass]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [graphics, rendering, gpu, optimization, depth-buffer, overdraw]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: HLSL / GLSL / Shader
framework: Unreal / Unity / Custom
---
# Depth Pre-Pass
## 매 한 줄
> **"매 main shading 전 의 depth-only render"**. 매 overdraw 의 reduce — 매 expensive pixel shader 의 hidden surface 의 skip. 매 modern GPU 의 early-Z + Hi-Z + 매 deferred / forward+. 매 cost: 매 vertex 2x.
## 매 핵심
### 매 motivation
- **Overdraw**: 매 same pixel 의 shade 여러 번.
- **Expensive shader**: 매 PBR + IBL + many light → 매 pixel cost ↑.
- **Solution**: 매 depth 만 의 first → 매 main pass 의 occluded fragment 의 reject.
### 매 mechanism
1. **Pass 1**: 매 depth-only (vertex + null pixel shader).
2. **Pass 2**: 매 full shading + EQUAL depth test.
3. 매 GPU 의 early-Z 의 pixel shader 전 의 reject.
### 매 trade-off
- **Win**: 매 expensive pixel shader 의 occluded fragment 의 skip.
- **Loss**: 매 vertex stage 2x.
- **Net**: 매 shader complexity 의 high 의 win.
### 매 modern variant
- **Hi-Z**: 매 hierarchical depth 의 GPU 의 cull tile.
- **Forward+**: 매 light culling + Z-prepass.
- **Deferred**: 매 G-buffer 의 prepass-like.
- **Visibility buffer**: 매 modern alternative (Unreal 5 Nanite).
### 매 응용
1. **Open world**: 매 dense vegetation overdraw.
2. **Particle**: 매 alpha sort cost.
3. **PBR-heavy**: 매 expensive shader.
4. **VR**: 매 fill rate critical.
5. **Mobile**: 매 tile-based 의 different approach (defer to TBDR).
## 💻 패턴
### Z-prepass (Unreal-style HLSL)
```hlsl
// Pass 1 — depth only
struct VSInput { float3 pos : POSITION; };
float4 VS_DepthOnly(VSInput v) : SV_POSITION {
return mul(float4(v.pos, 1.0), MVP);
}
// 매 no pixel shader (or null)
// Pass 2 — full shading with EQUAL test
DepthStencilState : DepthFunc = EQUAL; DepthWrite = OFF;
float4 PS_Main(VSOutput v) : SV_TARGET {
return PBR_Shade(v); // 매 expensive
}
```
### OpenGL setup
```cpp
// Pass 1
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
DrawScene(depth_only_program);
// Pass 2
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_FALSE);
glDepthFunc(GL_EQUAL);
DrawScene(main_program);
```
### Vulkan render pass
```cpp
VkAttachmentDescription depthAttach = {
.format = VK_FORMAT_D32_SFLOAT,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
};
// Subpass 1: depth only
// Subpass 2: shading w/ EQUAL test, read-only depth
```
### Cost-benefit decision
```cpp
bool should_use_depth_prepass(SceneStats stats) {
// 매 high overdraw + expensive shader → 매 win
float avg_overdraw = stats.pixels_shaded / stats.unique_pixels;
float shader_cost = stats.shader_alu_count;
return avg_overdraw > 2.0 && shader_cost > 100;
}
```
### Hi-Z chain (compute)
```hlsl
// 매 each level 의 max of 4 source pixels
[numthreads(8, 8, 1)]
void GenerateHiZ(uint3 tid : SV_DispatchThreadID) {
float4 d;
d.x = SrcDepth[tid.xy * 2 + uint2(0, 0)];
d.y = SrcDepth[tid.xy * 2 + uint2(1, 0)];
d.z = SrcDepth[tid.xy * 2 + uint2(0, 1)];
d.w = SrcDepth[tid.xy * 2 + uint2(1, 1)];
DstDepth[tid.xy] = max(max(d.x, d.y), max(d.z, d.w));
}
```
### Occlusion query (validation)
```cpp
GLuint q;
glGenQueries(1, &q);
glBeginQuery(GL_SAMPLES_PASSED, q);
DrawObject(obj);
glEndQuery(GL_SAMPLES_PASSED);
GLuint samples;
glGetQueryObjectuiv(q, GL_QUERY_RESULT, &samples);
// 매 samples == 0 → fully occluded
```
### Early-Z disqualification
```hlsl
// 매 pixel shader 의 discard / depth-write → 매 early-Z 의 disabled
float4 PS_Bad(VSOut v) : SV_TARGET {
if (alpha < 0.5) discard; // ❌ early-Z 의 break
return shade(v);
}
// 매 ✅ early-Z friendly: 매 alpha test 의 discard 의 separate pass
[earlydepthstencil]
float4 PS_Good(VSOut v) : SV_TARGET {
return shade(v);
}
```
### TBDR mobile (no prepass needed)
```
// 매 mobile (Adreno, Mali, Apple) 의 tile-based deferred
// 매 already 의 hidden surface 의 reject before pixel shader
// 매 explicit Z-prepass 의 redundant
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Desktop + heavy PBR | Z-prepass |
| Mobile (TBDR) | NO (HW already does it) |
| Forward+ | Z-prepass + light cull |
| Deferred | G-buffer pass = prepass |
| Particle / transparent | After opaque (no prepass) |
| Modern Unreal 5 | Visibility buffer / Nanite |
**기본값**: 매 desktop + 매 heavy shader → Z-prepass. 매 mobile → skip. 매 modern engine → visibility buffer.
## 🔗 Graph
- 부모: [[Rendering-Pipeline]]
- 변형: [[Depth Pre-Pass|Early-Z]] · [[Hi-Z]]
- 응용: [[Deferred-Rendering]]
- Adjacent: [[Overdraw]] · [[Compute Shader (WebGPU)]]
## 🤖 LLM 활용
**언제**: 매 PBR-heavy desktop. 매 dense scene. 매 fill-rate-bound.
**언제 X**: 매 mobile TBDR. 매 vertex-bound. 매 simple shader.
## ❌ 안티패턴
- **Always prepass**: 매 vertex-bound 의 lose.
- **Discard in main**: 매 early-Z 의 break.
- **Mobile prepass**: 매 redundant + cost.
- **No EQUAL test in main**: 매 prepass 의 useless.
- **Animated geometry mismatch**: 매 prepass 와 main 의 different vertex.
## 🧪 검증 / 중복
- Verified (Real-Time Rendering 4ed, Unreal docs, Vulkan spec).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-04-20 | Auto-reinforced |
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — Z-prepass + 매 HLSL / GL / Vulkan / Hi-Z code |