禁用z缓冲使用directxtk无效

时间:2016-05-15 11:59:13

标签: c++ directx directx-11

我正在尝试禁用和启用z缓冲区,但是skydome仍然会写入zbuffer。我正在使用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();

1 个答案:

答案 0 :(得分:0)

GeometricPrimitiveModel都在内部设置了所需的渲染状态,包括深度/模板状态作为其API的一部分。

对于GeometricPrimitive,您可以使用setCustomState回调覆盖默认状态设置。例如,这是一个使用lambda的例子:

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,您可以在setCustomState方法上使用相同的Draw回调进行快速调整,或者您可以实现高级绘图模式。请参阅wiki