Quick Reference
opaque geometry -> depth test ON, write ALL, LESS/LESS_EQUAL
transparent geometry -> depth test ON, write ZERO, sort policy 필요
sky/background -> projection·clear convention에 맞는 compare
stencil mask -> read/write mask + front/back operations 지정Depth texture를 만들고 DSV를 binding해도 state의 DepthEnable과 DepthWriteMask가 꺼져 있으면 기대한 가림이 생기지 않습니다. Clear value와 comparison function은 normal-Z 또는 reversed-Z convention에 맞춥니다.
Texture와 State
Depth texture의 width, height와 sample count는 함께 묶는 render target과 호환되어야 합니다. Depth를 shader에서 읽으려면 typeless resource format과 호환되는 DSV·SRV view format을 선택하고, 읽는 pass 전에 DSV binding을 해제합니다.
D3D11_DEPTH_STENCIL_DESC 필드 | 기본값 | 변경 효과 |
|---|---|---|
DepthEnable | TRUE | FALSE면 depth test·write를 사용하지 않음 |
DepthWriteMask | ALL | ZERO면 test는 하되 depth를 기록하지 않음 |
DepthFunc | LESS | normal-Z·reversed-Z·equal pass에 맞춰 비교 변경 |
StencilEnable | FALSE | stencil compare와 operation 활성화 |
StencilReadMask / WriteMask | 0xFF / 0xFF | 읽고 기록할 bit 제한 |
Front/Back Func | ALWAYS | face별 reference 비교 |
| Front/Back fail·depth-fail·pass op | KEEP | 조건 결과에 따른 stencil 값 변경 |
위 값은 CD3D11_DEPTH_STENCIL_DESC(D3D11_DEFAULT) 기준입니다. OMSetDepthStencilState의 두 번째 인자인 stencil reference는 state object 안이 아니라 draw/pass binding 시점에 전달합니다.
Stencil은 pixel마다 작은 정수 mask를 유지합니다. Outline, portal, 제한 영역처럼 pass 사이 분류가 필요할 때 reference value, compare, pass/fail/depth-fail operation을 명확히 설계합니다.
자주 틀리는 점
- 매 frame depth clear를 빠뜨리지 않습니다.
- Transparent pass에서 depth write를 켜 뒤 particle을 잘못 가리지 않습니다.
- MSAA RTV와 non-MSAA DSV를 함께 묶지 않습니다.
- Reversed-Z에서 clear와 compare 중 하나만 뒤집지 않습니다.
참고 링크
2 sources