1

そのため、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(v=vs.85).aspx ) を使用して手順を追って説明しましたが、その理由についてかなり混乱しています動いていない。

どんな助けでも大歓迎です、ありがとう!

4

1 に答える 1

0

1> depthBufferDesc および depthStencilViewDesc 形式は次のようになります。

DXGI_FORMAT_D32_FLOAT

2> モデルによっては、rasterDesc.FrontCounterClockwise を true に設定してみてください。

rasterDesc.FrontCounterClockwise = true;

3> ビューポートが設定されていることを確認してください:

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

4> そして、カメラのクリッピング プレーンの近くを確認する必要があります。値はゼロより大きい必要があります。

于 2014-05-22T07:55:30.647 に答える