Depth Buffer The zbuffer Algorithm Z buffer Algorithm
Depth Buffer
The z-buffer Algorithm Z buffer Algorithm의 개략적 순서 n n n (1) frame buffer와 z buffer를 초기화 (2) 임의의 순서로 각 polygon을 scan한다. (3) polygon의 각 pixel(x, y)에 해당하는 깊이 z(x, y)를 계산하고, 그 위치의 z buffer에 저장된 값 Z(x, y)와 비교한다. n (4) if (z(x, y) > Z(x, y)) Z(x, y)를 z(x, y)로 갱신한다. Otherwise No action 3
The z-buffer Algorithm The addition of two polygon to an image (example) (a) 빈 z buffer에 일정한 z의 polygon을 추가함. (b) 또 다른 polygon을 추가하여 처음의 것과 교차 시킴. 4
The z-buffer Algorithm 장점 n n 알고리즘이 간단하다. 구현이 쉽다. 단점 n n n z buffer를 위한 많은 기억장소의 요구 Aliasing 문제(z buffer가 image precision algorithm이므로) the generated z values in a z-buffer tend not to be distributed evenly across the z-buffer range W-buffer n n more evenly distributed between the near and far clip planes than a z -buffer. 하지만, z-Buffer만큼 하드웨어 지원이 많지는 않다. 6
The z-buffer Algorithm 몇몇 장비는 Z-Buffer 대신에 HSR(Hidden Surface Removal) 기법을 지원하며 이는 D 3 DPRASTERCAPS_ZBUFFERLESSHSR이라 는 이림의 플래그를 사용. HSR 기능에서는 Z-Buffer를 사용하지 않음 7
Querying for Depth Buffer Support // p. Caps 은 D 3 DCAPS 8 구조체 변수 // 장치가 16비트 깊이 버퍼를 지원하는가를 검사 if( FAILED( m_p. D 3 D->Check. Device. Format( p. Caps->Adapter. Ordinal, p. Caps->Device. Type, Format, D 3 DUSAGE_DEPTHSTENCIL, D 3 DRTYPE_SURFACE, D 3 DFMT_D 16 ) ) ) return E_FAIL; // 장치가 Depth-Stencil 버퍼를 지원하는 가를 검사. if( FAILED( m_p. D 3 D->Check. Depth. Stencil. Match( p. Caps->Adapter. Ordinal, p. Caps->Device. Type, Adapter. Format, RTFormat, D 3 DFMT_D 24 S 8 ) ) ) return E_FAIL; 8
Creating a Depth Buffer 새로운 depth buffer surface 생성 - IDirect 3 DDevice 8: : Create. Depth. Stencil. Surface. 새 depth-buffer surface를 장치에 설정. - Direct 3 DDevice 8: : Set. Render. Target D 3 DPRESENT_PARAMETERS d 3 dpp; Zero. Memory( &d 3 dpp, sizeof(d 3 dpp) ); d 3 dpp. Windowed = TRUE; d 3 dpp. Swap. Effect = D 3 DSWAPEFFECT_COPY_VSYNC; d 3 dpp. Enable. Auto. Depth. Stencil = TRUE; d 3 dpp. Auto. Depth. Stencil. Format = D 3 DFMT_D 16; if( FAILED( g_p. D 3 D->Create. Device( D 3 DADAPTER_DEFAULT, D 3 DDEVTYPE_HAL, h. Wnd, D 3 DCREATE_SOFTWARE_VERTEXPROCESSING, &d 3 dpp, &d 3 d. Device ) ) ) return E_FAIL; 9
Functions for Depth Buffer Support Enabling Depth Buffering - IDirect 3 DDevice 8: : Set. Render. State method Retrieving a Depth Buffer - LPDIRECT 3 DSURFACE 8 p. ZBuffer; - m_d 3 d. Device->Get. Depth. Stencil. Surface( &p. ZBuffer ); Clearing Depth Buffers - IDirect 3 DDevice 8: : Clear Changing Depth Buffer Write Access Changing Depth Buffer Comparison Functions - IDirect 3 DDevice 8: : Set. Render. State method - State parameter set to D 3 DRS_ZFUNC. 10
- Slides: 10