我的應用程序中有一個clipplanes問題,我可以從DirectX SDK的示例(2010年2月)中重現該問題。使用硬件和軟件頂點處理時Direct3D中的Clipplanes,頂點着色器和硬件頂點處理9
...
D3DXPLANE g_Plane(0.0f, 1.0f, 0.0f, 0.0f);
...
void SetupClipPlane(const D3DXMATRIXA16 & view, const D3DXMATRIXA16 & proj)
{
D3DXMATRIXA16 m = view * proj;
D3DXMatrixInverse(&m, NULL, &m);
D3DXMatrixTranspose(&m, &m);
D3DXPLANE plane;
D3DXPlaneNormalize(&plane, &g_Plane);
D3DXPLANE clipSpacePlane;
D3DXPlaneTransform(&clipSpacePlane, &plane, &m);
DXUTGetD3D9Device()->SetClipPlane(0, clipSpacePlane);
}
void CALLBACK OnFrameMove(double fTime, float fElapsedTime, void* pUserContext)
{
// Update the camera's position based on user input
g_Camera.FrameMove(fElapsedTime);
// Set up the vertex shader constants
D3DXMATRIXA16 mWorldViewProj;
D3DXMATRIXA16 mWorld;
D3DXMATRIXA16 mView;
D3DXMATRIXA16 mProj;
mWorld = *g_Camera.GetWorldMatrix();
mView = *g_Camera.GetViewMatrix();
mProj = *g_Camera.GetProjMatrix();
mWorldViewProj = mWorld * mView * mProj;
g_pConstantTable->SetMatrix(DXUTGetD3D9Device(), "mWorldViewProj", &mWorldViewProj);
g_pConstantTable->SetFloat(DXUTGetD3D9Device(), "fTime", (float)fTime);
SetupClipPlane(mView, mProj);
}
void CALLBACK OnFrameRender(IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext)
{
// If the settings dialog is being shown, then
// render it instead of rendering the app's scene
if(g_SettingsDlg.IsActive())
{
g_SettingsDlg.OnRender(fElapsedTime);
return;
}
HRESULT hr;
// Clear the render target and the zbuffer
V(pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 45, 50, 170), 1.0f, 0));
// Render the scene
if(SUCCEEDED(pd3dDevice->BeginScene()))
{
pd3dDevice->SetVertexDeclaration(g_pVertexDeclaration);
pd3dDevice->SetVertexShader(g_pVertexShader);
pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(D3DXVECTOR2));
pd3dDevice->SetIndices(g_pIB);
pd3dDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0);
V(pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, g_dwNumVertices,
0, g_dwNumIndices/3));
pd3dDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, 0);
RenderText();
V(g_HUD.OnRender(fElapsedTime));
V(pd3dDevice->EndScene());
}
}
當我旋轉相機我有不同的視覺效果:
我添加了一個clipplane到HLSLwithoutEffects樣品。 在軟件頂點處理模式下或使用參考設備時,剪裁平面按預期正常工作。在硬件模式下,它似乎隨相機旋轉。
如果我刪除了對RenderText()的調用;從OnFrameRender,然後硬件渲染也可以正常工作。進一步的調試顯示問題出在ID3DXFont :: DrawText中。
我在Windows Vista和Windows 7中遇到此問題,但在Windows XP中沒有此問題。我使用最新的NVidia和ATI驅動程序在不同PC上的所有三個操作系統中測試了代碼。 它是一個DirectX問題?或clipplanes的使用不正確?
感謝
伊戈爾