2014-04-30 3 views
1

DirectX10에서 장면을 만들려고하고 있는데 왜 어떤 이유로 zbuffer (깊이 버퍼)가 작동하지 않는 것 같습니다. 여기DirectX10의 깊이 버퍼가 작동하지 않습니다.

// 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; 
} 

그리고 내 장면에서 모습입니다 : : 여기가 z 버퍼를 설정 한 코드는 내가 단계 나를 통해 단계로 자원 (http://msdn.microsoft.com/en-us/library/windows/desktop/bb205074(v=vs.85).aspx)를 사용 http://imgur.com/UsaURcR

가 있지만입니다 지금 그것이 작동하지 않는 이유에 관해서는 꽤 혼란 스럽습니다.

어떤 도움을 주시면 감사하겠습니다.

DXGI_FORMAT_D32_FLOAT 

2> 그리고 모델에 따라, true로 설정 rasterDesc.FrontCounterClockwise을 시도 할 수 있습니다 : 같은

+0

* 사용하지 마십시오 * 작동하지 않는 것 같습니다. * 그림에서 무엇이 잘못되었는지를 볼 수 없으므로 자세한 내용을 제공해야합니다. – zdd

+0

죄송합니다. 다른 ZBuffer가 제공하지 않는 다른 세부 정보가 단순히 작동하지 않는 것 같습니다. 사진에서 볼 수 있듯이 물은 연못 안에 있지만 물은 수영장 위로 흐르고 있습니다. 그래서 수영장의 측면이 더 가깝다는 것을 감지하지 못합니다. – Crackerhead

답변

0

1> 귀하의 depthBufferDesc 및 depthStencilViewDesc 형식이어야합니다.

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

4> 그리고 당신은 당신의 카메라에 비행기를 클리핑 근처를 확인해야 :

rasterDesc.FrontCounterClockwise = true; 

3> 당신이 설정 한 뷰포트 있는지 확인하십시오. 값은 0보다 커야합니다.

관련 문제