• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

DirectX11 Depth Buffer Problem (solved)

8 posts in this topic

Hello everyone,
I have this problem with my depth buffer and all the solutions from the countless other threads with this problem do not seem to work for me.


I use the same code as shown here: [url="http://www.rastertek.com/dx11tut03.html"]http://www.rastertek.../dx11tut03.html[/url]

[i]Global Variables:[/i]
extern ID3D11Device* pDevice;
extern ID3D11DeviceContext* pDevCon;
extern ID3D11RenderTargetView* pRenderTargetView;
extern ID3D11DepthStencilState* pDepthStencilState;
extern ID3D11DepthStencilView* pDepthStencilView;
extern ID3D11Texture2D* pDepthStencilBuffer;
extern ID3D11RasterizerState* pRasterState;

[i]Direct3D initialisation:[/i]
HRESULT result;

D3D11_TEXTURE2D_DESC depthBufferDesc;
depthBufferDesc.Width = Width;
depthBufferDesc.Height = Height;
depthBufferDesc.MipLevels = 1;
depthBufferDesc.ArraySize = 1;
depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthBufferDesc.SampleDesc.Count = 1;
depthBufferDesc.SampleDesc.Quality = 0;
depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthBufferDesc.CPUAccessFlags = 0;
depthBufferDesc.MiscFlags = 0;

result = pDevice->CreateTexture2D(&depthBufferDesc, NULL, &pDepthStencilBuffer);

MessageBox(NULL, L"Error1", L"Error", MB_OK | MB_ICONERROR);

D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
ZeroMemory(&depthStencilDesc, sizeof(D3D11_DEPTH_STENCIL_DESC));
// Depth test parameters
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
// Stencil test parameters
depthStencilDesc.StencilEnable = true;
depthStencilDesc.StencilReadMask = 0xFF;
depthStencilDesc.StencilWriteMask = 0xFF;
// Stencil operations if pixel is front-facing
depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
// Stencil operations if pixel is back-facing.
depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

result = pDevice->CreateDepthStencilState(&depthStencilDesc, &pDepthStencilState);
pDevCon->OMSetDepthStencilState(pDepthStencilState, 1);

MessageBox(NULL, L"Error2", L"Error", MB_OK | MB_ICONERROR);

D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
ZeroMemory(&depthStencilViewDesc, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthStencilViewDesc.Texture2D.MipSlice = 0;
result = pDevice->CreateDepthStencilView(pDepthStencilBuffer, &depthStencilViewDesc, &pDepthStencilView);
pDevCon->OMSetRenderTargets(1, &pRenderTargetView, pDepthStencilView);

MessageBox(NULL, L"Error3", L"Error", MB_OK | MB_ICONERROR);

rasterDesc.AntialiasedLineEnable = false;
rasterDesc.CullMode = D3D11_CULL_BACK;
rasterDesc.DepthBias = 0;
rasterDesc.DepthBiasClamp = 0.0f;
rasterDesc.DepthClipEnable = true;
rasterDesc.FillMode = D3D11_FILL_SOLID;
rasterDesc.FrontCounterClockwise = false;
rasterDesc.MultisampleEnable = false;
rasterDesc.ScissorEnable = false;
rasterDesc.SlopeScaledDepthBias = 0.0f;

result = pDevice->CreateRasterizerState(&rasterDesc, &pRasterState);

MessageBox(NULL, L"Error4", L"Error", MB_OK | MB_ICONERROR);

D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = Width;
viewport.Height = Height;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;

pDevCon->RSSetViewports(1, &viewport);

[i]Camera Code:[/i]
m_pV3Pos = &Position;
m_pV3LookAt = &LookAt;
m_pV3View = (D3DXVECTOR3*)malloc(sizeof(D3DXVECTOR3));
m_pV3Up = (D3DXVECTOR3*)malloc(sizeof(D3DXVECTOR3));
*m_pV3View = *m_pV3Pos - *m_pV3LookAt;
D3DXVec3Normalize(m_pV3View, m_pV3View);
D3DXVec3Cross(m_pV3Up, &D3DXVECTOR3(0,1,0), m_pV3View);
D3DXVec3Cross(m_pV3Up, m_pV3View, m_pV3Up);
m_pMatView = (D3DXMATRIX*)malloc(sizeof(D3DXMATRIX));
m_pMatProj = (D3DXMATRIX*)malloc(sizeof(D3DXMATRIX));

D3DXVec3Normalize(m_pV3Up, m_pV3Up);
D3DXMatrixLookAtLH(m_pMatView, m_pV3Pos, m_pV3LookAt, m_pV3Up);
D3DXMatrixPerspectiveFovLH(m_pMatProj, FOV, (float)Width/Height, 1.0f, 1000.0f);

[i]Draw Code:[/i]
D3DXCOLOR bgColor( 0, 0.2f, 0.4f, 1.0f );
pDevCon->ClearRenderTargetView(pRenderTargetView, bgColor);
pDevCon->ClearDepthStencilView(pDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
pSwapChain->Present(0, 0);

I realy have no ideas left so if anyone could help me with this issue I would be most grateful [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by Rudi Media

Share this post

Link to post
Share on other sites
Wow D3D11 looks alot different than D3D9 o.O. In the link you gave, he didnt use the flag '[b]D3D11_CLEAR_STENCIL[/b]', maybe take that out and try again.

Draw Code:
D3DXCOLOR bgColor( 0, 0.2f, 0.4f, 1.0f );
pDevCon->ClearRenderTargetView(pRenderTargetView, bgColor);
pDevCon->ClearDepthStencilView(pDepthStencilView, D3D11_CLEAR_DEPTH| D3D11_CLEAR_STENCIL, 1.0f, 0);
pSwapChain->Present(0, 0);
[/code] Edited by Muzzy A

Share this post

Link to post
Share on other sites
[color=#000000]pDevCon[/color][color=#666600]->[/color][color=#660066]OMSetDepthStencilState[/color][color=#666600]([/color][color=#000000]pDepthStencilState[/color][color=#666600],[/color][color=#000000] [/color][color=#006666]1[/color][color=#666600]);[/color]

[color=#000000] [/color][color=#660066]MessageBox[/color][color=#666600]([/color][color=#000000]NULL[/color][color=#666600],[/color][color=#000000] L[/color][color=#008800]"Error2"[/color][color=#666600],[/color][color=#000000] L[/color][color=#008800]"Error"[/color][color=#666600],[/color][color=#000000] MB_OK [/color][color=#666600]|[/color][color=#000000] MB_ICONERROR[/color][color=#666600]);[/color]

Your error handling code at least doens't work as it should. You don't seems to update your result variable.
Also, enable d3d debugging to see any error messages in the debug window.

Otherwise, it seems that you z-buffer doesn't work as intended. As if it wasn't bound or z-testing is disabled.

You can also disable stencil testing at this point since you don't use it.

Best regards!

Share this post

Link to post
Share on other sites
Well [b]OMSetDepthStencilState[/b] doesn't return a [b]HRESULT[/b] value, which is why I don't update my result variable at this place.
Regarding d3d debugging I have actually no experience at all. I'm currently using the VS11 beta and heard that such a feature is already built-in but it seems like you're only able to use it if you have Windows 8 installed. Is there any other way to debug your d3d applications?

Share this post

Link to post
Share on other sites
Go to the DirectX control panel (it should be findable by just typing "DirectX Control Panel" in your Start menu) and enable debugging from there.

One potential problem however that I can see is that you're creating and setting your depth testing state before you create your depth/stencil view - maybe try doing it after instead and see what happens?

Share this post

Link to post
Share on other sites

Other things to verify:

- by any chance, are you using a multisampled back buffer? if so, AFAIK, the depth buffer has to be multisampled too
- depth buffer resolution has to be same as back buffer resolution

- Enable the d3d debug as instructed earlier (works on Win7 too). If there is that kind of problem, it should be able to tell you about it.


Share this post

Link to post
Share on other sites
[quote name='kauna' timestamp='1335874932' post='4936398']
- by any chance, are you using a multisampled back buffer? if so, AFAIK, the depth buffer has to be multisampled too

Hey thank you that was my problem [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

Share this post

Link to post
Share on other sites

glad to be able to help. I got the idea from looking your screenshot which seemed to be multisampled :)

Best regards!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By lonewolff
      Hi Guys,
      I am revisiting an old DX11 framework I was creating a while back and am scratching my head with a small issue.
      I am trying to set the pixel shader resources and am getting the following error on every loop.
      As you can see in the below code, I am clearing out the shader resources as per the documentation. (Even going overboard and doing it both sides of the main PSSet call). But I just can't get rid of the error. Which results in the render target not being drawn.
      ID3D11ShaderResourceView* srv = { 0 }; d3dContext->PSSetShaderResources(0, 1, &srv); for (std::vector<RenderTarget>::iterator it = rtVector.begin(); it != rtVector.end(); ++it) { if (it->szName == name) { //std::cout << it->srv <<"\r\n"; d3dContext->PSSetShaderResources(0, 1, &it->srv); break; } } d3dContext->PSSetShaderResources(0, 1, &srv);  
      I am storing the RT's in a vector and setting them by name. I have tested the it->srv and am retrieving a valid pointer.
      At this stage I am out of ideas.
      Any help would be greatly appreciated
    • By bowerbirdcn
      hi, guys, how to understand the math used in CDXUTDirectionWidget ::UpdateLightDir 
      the  following code snippet is taken from MS DXTU source code
        D3DXMATRIX mInvView;
          D3DXMatrixInverse( &mInvView, NULL, &m_mView );
          mInvView._41 = mInvView._42 = mInvView._43 = 0;
          D3DXMATRIX mLastRotInv;
          D3DXMatrixInverse( &mLastRotInv, NULL, &m_mRotSnapshot );
          D3DXMATRIX mRot = *m_ArcBall.GetRotationMatrix();
          m_mRotSnapshot = mRot;
          // Accumulate the delta of the arcball's rotation in view space.
          // Note that per-frame delta rotations could be problematic over long periods of time.
          m_mRot *= m_mView * mLastRotInv * mRot * mInvView;
          // Since we're accumulating delta rotations, we need to orthonormalize 
          // the matrix to prevent eventual matrix skew
          D3DXVECTOR3* pXBasis = ( D3DXVECTOR3* )&m_mRot._11;
          D3DXVECTOR3* pYBasis = ( D3DXVECTOR3* )&m_mRot._21;
          D3DXVECTOR3* pZBasis = ( D3DXVECTOR3* )&m_mRot._31;
          D3DXVec3Normalize( pXBasis, pXBasis );
          D3DXVec3Cross( pYBasis, pZBasis, pXBasis );
          D3DXVec3Normalize( pYBasis, pYBasis );
          D3DXVec3Cross( pZBasis, pXBasis, pYBasis );
    • By YixunLiu
      I have a surface mesh and I want to use a cone to cut a hole on the surface mesh.
      Anybody know a fast method to calculate the intersected boundary of these two geometries?
    • By hiya83
      Hi, I tried searching for this but either I failed or couldn't find anything. I know there's D11/D12 interop and there are extensions for GL/D11 (though not very efficient). I was wondering if there's any Vulkan/D11 or Vulkan/D12 interop?
    • By lonewolff
      Hi Guys,
      I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
      Any advice would be greatly appreciated
  • Popular Now