使用 directxtk 禁用 z 缓冲不起作用
disable z buffering is not working using directxtk
我正在尝试禁用和启用 z 缓冲区,但 skydome 仍然写入 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();
GeometricPrimitive
和 Model
都在内部设置了所需的渲染状态,包括 depth/stencil 状态作为其 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, you can use the same setCustomState
callback on the Draw
method for a quick tweak, or you can just implement the Advanced Drawing pattern. See the wiki
我正在尝试禁用和启用 z 缓冲区,但 skydome 仍然写入 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();
GeometricPrimitive
和 Model
都在内部设置了所需的渲染状态,包括 depth/stencil 状态作为其 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, you can use the same setCustomState
callback on the Draw
method for a quick tweak, or you can just implement the Advanced Drawing pattern. See the wiki