Буфер глубины на DirectX10 не работает

Итак, я пытаюсь создать сцену в DirectX10, и по какой-то причине мой zbuffer (буфер глубины), похоже, не работает. Вот код, в котором я установил Zbuffer:

// Initialize the description of the depth buffer.
ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));

// Set up the description of the depth buffer.
depthBufferDesc.Width = _iScreenWidth;
depthBufferDesc.Height = _iScreenHeight;
depthBufferDesc.MipLevels = 1;
depthBufferDesc.ArraySize = 1;
depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthBufferDesc.SampleDesc.Count = 1;
depthBufferDesc.SampleDesc.Quality = 0;
depthBufferDesc.Usage = D3D10_USAGE_DEFAULT;
depthBufferDesc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
depthBufferDesc.CPUAccessFlags = 0;
depthBufferDesc.MiscFlags = 0;

// Create the texture for the depth buffer using the filled out description.
if(FAILED(m_pDevice->CreateTexture2D(&depthBufferDesc, NULL, &m_pDepthStencilBuffer)))
{
    return false;
}

// Initialize the description of the stencil state.
ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));

// Set up the description of the stencil state.
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D10_COMPARISON_LESS;

depthStencilDesc.StencilEnable = true;
depthStencilDesc.StencilReadMask = 0xFF;
depthStencilDesc.StencilWriteMask = 0xFF;

// Stencil operations if pixel is front-facing.
depthStencilDesc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_INCR;
depthStencilDesc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;

// Stencil operations if pixel is back-facing.
depthStencilDesc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_DECR;
depthStencilDesc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;

// Create the depth stencil state.
if(FAILED(m_pDevice->CreateDepthStencilState(&depthStencilDesc, &m_pDepthStencilState)))
{
    return false;
}

// Set the depth stencil state on the D3D device.
m_pDevice->OMSetDepthStencilState(m_pDepthStencilState, 1);

// Initailze the depth stencil view.
ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));

// Set up the depth stencil view description.
depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilViewDesc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
depthStencilViewDesc.Texture2D.MipSlice = 0;

// Create the depth stencil view.
if(FAILED(m_pDevice->CreateDepthStencilView(m_pDepthStencilBuffer, &depthStencilViewDesc, &m_pDepthStencilView)))
{
    return false;
}

// Bind the render target view and depth stencil buffer to the output render pipeline.
m_pDevice->OMSetRenderTargets(1, &m_pRenderTargetView, m_pDepthStencilView);

// Setup the raster description which will determine how and what polygons will be drawn.
rasterDesc.AntialiasedLineEnable = true;
rasterDesc.CullMode = D3D10_CULL_BACK;
rasterDesc.DepthBias = 0;
rasterDesc.DepthBiasClamp = 0.0f;
rasterDesc.DepthClipEnable = true;
rasterDesc.FillMode = D3D10_FILL_SOLID;
rasterDesc.FrontCounterClockwise = false;
rasterDesc.MultisampleEnable = false;
rasterDesc.ScissorEnable = false;
rasterDesc.SlopeScaledDepthBias = 0.0f;

// Uncomment to turn off back-face culling
//rasterDesc.CullMode = D3D10_CULL_NONE;
//rasterDesc.FillMode = D3D10_FILL_WIREFRAME;

// Create the rasterizer state from the description we just filled out.
if(FAILED(m_pDevice->CreateRasterizerState(&rasterDesc, &m_pRasterState)))
{
    return false;
}

А вот как это выглядит в моей сцене: http://imgur.com/UsaURcR

Я использовал ресурс (http://msdn.microsoft.com/en-us/library/windows/desktop/bb205074%28v=vs.85%29.aspx), чтобы шаг за шагом пройти меня, но теперь я совершенно не понимаю, почему он не работает .

Любая помощь будет ОЧЕНЬ признательна, спасибо!


person Crackerhead    schedule 30.04.2014    source источник
comment
Пожалуйста, прекратите использование похоже, не работает, судя по картинке, я не вижу, что не так, вы должны указать более подробную информацию.   -  person zdd    schedule 01.05.2014
comment
Извините, я не знаю, какие еще детали, кроме ZBuffer, кажется, просто не работают. Как вы можете видеть на картинке, вода находится внутри прудов, но вода течет по бассейну. Таким образом, он не определяет, что сторона бассейна находится ближе, и вместо этого рисует ее.   -  person Crackerhead    schedule 01.05.2014


Ответы (1)


1> Ваши форматы depthBufferDesc и depthStencilViewDesc должны быть такими:

DXGI_FORMAT_D32_FLOAT

2> И в зависимости от вашей модели вы можете попробовать установить rasterDesc.FrontCounterClockwise в значение true.

rasterDesc.FrontCounterClockwise = true;

3> Убедитесь, что в вашем окне просмотра установлено:

ViewPort.MinDepth = 0.0f;
ViewPort.MaxDepth = 1.0f;

4> И вы должны проверить себя возле плоскости отсечения в вашей камере. Значение должно быть больше нуля.

person Tobias Schwandt    schedule 22.05.2014