Z-буфер движка DirectX 9 не работает с D3DImage

Я пытаюсь интегрировать мой движок Direct9 в мое новое приложение WPF через D3DImage. Все работает, кроме буфера Z. С AutoDepthStencil в FALSE я могу визуализировать свои сетки, но глубина не работает. Когда я активирую AutoDepthStencil, ничего не рисуется. Я искал вокруг в течение нескольких дней и не нашел ничего, чтобы помочь meq

Ее параметры презентации

ZeroMemory( m_pp, sizeof(m_pp) );

m_pp->AutoDepthStencilFormat = D3DFMT_D16;
m_pp->BackBufferCount            = 1;
m_pp->MultiSampleQuality         = 0;
m_pp->Windowed                   = Windowed;
m_pp->MultiSampleType            = D3DMULTISAMPLE_8_SAMPLES;
m_pp->EnableAutoDepthStencil     = FALSE;
m_pp->PresentationInterval       = D3DPRESENT_INTERVAL_ONE;
m_pp->Windowed                   = TRUE;
m_pp->BackBufferHeight           = 1;
m_pp->BackBufferWidth            = 1;
m_pp->SwapEffect                 = D3DSWAPEFFECT_DISCARD;
m_pp->BackBufferFormat           = D3DFMT_A8R8G8B8;

RenderStates:

m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_LIGHTING, TRUE);    // turn off the 3D lighting
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50,50,50));
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_SPECULARENABLE, TRUE );
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);    // both sides of the triangles
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_ZENABLE, TRUE);    // turn on the z-buffer
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
m_graphics->GetDeviceD3D()->LightEnable( 0, TRUE );

Сброс:

m_graphics->GetDeviceD3D()->Clear(0, NULL, D3DCLEAR_TARGET , D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
m_graphics->GetDeviceD3D()->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

Создание поверхности и устройства:

if (FAILED(m_pD3D9->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd,
dwVertexProcessing,
m_pp, NULL, GetDevicePtr())))
{
return NULL;
}

// obtain the standard D3D device interface
if (FAILED(GetDeviceD3D()->QueryInterface(__uuidof(IDirect3DDevice9), reinterpret_cast<void **>(GetDevicePtr()))))
{
return NULL;
}

// create and set the render target surface
// it should be lockable on XP and nonlockable on Vista

if (FAILED(GetDeviceD3D()->CreateRenderTarget(Width, Height,
D3DFMT_A8R8G8B8, D3DMULTISAMPLE_8_SAMPLES, 0,
false, // lockable
GetSurfacePtr(), NULL)))
{
return NULL;
}
GetDeviceD3D()->SetRenderTarget(0, m_surface);

Матрицы:

    // set the projection transform
D3DXMATRIX matProjection;    // the projection transform matrix
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),    // the horizontal field of view
1.f, // aspect ratio TODO
0.001f,    // the near view-plane
1000.0f);    // the far view-plane
m_graphics->GetDeviceD3D()->SetTransform(D3DTS_PROJECTION, &matProjection);     // set the projection

//CAMERA
D3DXMATRIX matView;
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (m_scene->Cam->Position.X, m_scene->Cam->Position.Y, m_scene->Cam->Position.Z),   // the camera position
&D3DXVECTOR3 (m_scene->Cam->Target.X, m_scene->Cam->Target.Y, m_scene->Cam->Target.Z),    // the look-at position
&D3DXVECTOR3 (m_scene->Cam->UpVector.X, m_scene->Cam->UpVector.Y, m_scene->Cam->UpVector.Z));    // the up direction
d3ddev->m_device->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView

1

Решение

С EnableAutoDepthStencil, установленным в TRUE, убедитесь, что CreateRenderTarget использует ту же ширину и высоту, что и параметры презентации

1

Другие решения