2016-05-15 43 views
0

我想禁用和啓用z緩衝區,但仍然skydome寫入到zbuffer。我正在使用DirectXTK來達到這個目的,但它似乎不能正常工作。禁用z緩衝不工作使用directxtk

CommonStates states(m_Graphics.getDevice()); 
    m_Graphics.getContext()->RSSetState(states.CullNone()); 
    XMMATRIX sphereWorld; 
    XMMATRIX sphereScale = XMMatrixScaling(200.0f, 200.0f, 200.0f); 
    XMMATRIX Translation = XMMatrixTranslation(m_Camera.Position().x, 
     m_Camera.Position().y, m_Camera.Position().z); 

    sphereWorld = sphereScale*Translation; 
    m_Graphics.getContext()->OMSetDepthStencilState(states.DepthNone(), 1); 
    m_shape->Draw(sphereWorld,m_Camera.ViewMatrix(), m_Camera.ProjectionMatrix(), Colors::White, m_texture.Get()); 
    m_Graphics.getContext()->OMSetDepthStencilState(states.DepthDefault(),1); 

    XMMATRIX cameraInverse = XMMatrixInverse(nullptr, m_Graphics.getViewMatrix()); 
    XMMATRIX translate = XMMatrixTranslation(2.0f, -3.0f, 2.0f); 
    XMMATRIX rotation = XMMatrixRotationRollPitchYaw((float)XM_PI/9.0f, (float)XM_PI/0.2f, (float)XM_PI/0.1f); 
    XMMATRIX world = rotation *translate *cameraInverse; 

    m_Tiny->Draw(m_Graphics.getContext(), states, world, m_Graphics.getViewMatrix(), m_Graphics.getProjectionMatrix()); 

    m_Graphics.getContext()->RSSetState(states.CullCounterClockwise()); 
    m_Graphics.getContext()->RSSetState(states.Wireframe()); 

    m_Grid.DrawGrid(); 

回答

0

GeometricPrimitiveModel都設置所需的渲染狀態在內部包括深度/模板狀態作爲其API的一部分。

對於GeometricPrimitive,您使用setCustomState回調來覆蓋默認狀態設置。例如,下面是一個使用拉姆達的例子:

m_shape->Draw(sphereWorld,m_Camera.ViewMatrix(), m_Camera.ProjectionMatrix(), 
Colors::White, m_texture.Get(), false, [=] 
{ 
    m_Graphics.getContext()->RSSetState(states.CullNone()); 
    m_Graphics.getContext()->OMSetDepthStencilState(states.DepthNone(), 1); 
}); 

Model,您可以使用該方法Draw相同setCustomState回調快速的調整,或者你可以實現高級繪圖模式。請參閱wiki