깊은 무늬의 사용
2045 단어 DirectX
1. 깊이 텍스처 생성
//
//1
IDirect3DSurface9 * pSurface = nullptr;
hr = pDevice->GetRenderTarget(0, &pSurface); //ref count +1
if (FAILED(hr))
{
MessageBox(NULL, _T(" RenderTarget failed"), NULL, MB_OK);
return false;
}
D3DSURFACE_DESC desc;
pSurface->GetDesc(&desc);
pSurface->Release(); //ref count -1
int texWidth, texHeight;
texWidth = desc.Width;
texHeight = desc.Height;
//2
hr = pDevice->CreateTexture(texWidth,
texHeight,
1,
D3DUSAGE_DEPTHSTENCIL,
D3DFMT_D16,
D3DPOOL_DEFAULT,
&g_pShadowTexture,
nullptr);
2. 깊이 무늬를 백그라운드로 설정
IDirect3DSurface9 * pOldDepthSurface = nullptr;
IDirect3DSurface9 * pNewDepthSurface = nullptr;
hr = pDev->GetDepthStencilSurface(&pOldDepthSurface);
assert(SUCCEEDED(hr));
hr = g_pShadowTexture->GetSurfaceLevel(0, &pNewDepthSurface); // 0, , 1,
assert(SUCCEEDED(hr));
hr = pDev->SetDepthStencilSurface(pNewDepthSurface); //
assert(SUCCEEDED(hr));
pDev->Clear(0, NULL, D3DCLEAR_ZBUFFER, 0, 1.f, 0); //*** // ,
3. 깊이 캐시를 설정한 후에 장면의 렌더링을 할 수 있고 깊이 값을 위에서 설정한 깊이 캐시에 쓸 수 있다.
Render Objects
장면을 렌더링하기 전에 색상 캐시에 대한 쓰기 작업을 끄고 나중에 켜는 것이 좋습니다
pDev->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
4. 원래의 깊이 캐시로 돌아가고 색 쓰기 동작을 켜기
pDev->SetDepthStencilSurface(pOldDepthSurface); //
pOldDepthSurface->Release();
pNewDepthSurface->Release();
pDev->SetRenderState(D3DRS_COLORWRITEENABLE, //
D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED);
5、뒤에 우리의 정상적인 조작을 진행할 수 있다
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
PickingPicking 마우스 클릭을 통해 Object를 고를 때 사실 화면에서 보여지는 것은 2D로 변환된 Screen Space이다. 따라서 우린 Ray Casting을 사용해 레이저를 쏘듯 카메라에서 Object까지 가...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.