Jump to content
  • Advertisement
Sign in to follow this  

Depth Buffer Driving me Crazy

This topic is 2806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


In reference to the above thread,

I am having the same issue. But my Min Depth is 0.0f, and Max Depth is 1.0f, still the Depth Buffer doesn't seem to work.. I am wasting my days on this simple issue.

Share this post

Link to post
Share on other sites
Without the code how you create your depth buffer and the code how you use your depth buffer no one will be able to help you Abeltherock007.

Share this post

Link to post
Share on other sites
I didn't follow the thread link, but your minimum depth should be greater than zero - even if it is extremely small. Try setting it to 0.01f to start with.

Also, if it still seems like you are not rendering your geometry properly, fire up PIX and do a frame capture. This way, you can take a look at the vertex positions prior and after the transformations to see if the output values are what you expect.

Share this post

Link to post
Share on other sites
thanks xiele.... the following is my code to enable the depth buffer

bool MyDXFramework::Initialize(HWND hWnd)
//get the render window dimensions
RECT rc;
GetClientRect(hWnd, &rc);
unsigned int uiScreenWidth = 1280;//rc.right - rc.left;
unsigned int uiScreenHeight = 720; //rc.bottom - rc.top;

ZeroMemory(&sd, sizeof(sd));
sd.BufferCount = 1; //back buffer and front buffer
sd.BufferDesc.Width = uiScreenWidth;
sd.BufferDesc.Height = uiScreenHeight;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;

tell DX how the back buffer will be used.
We want to render to the back buffer.

sd.OutputWindow = hWnd;
sd.SampleDesc.Count = 1; //multi sample properties. Which we will not use
sd.SampleDesc.Quality = 0; //disable multi sampling
sd.Windowed = true;

UINT iCreateDeviceFlags = 0;
#ifdef _DEBUG
iCreateDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;

if (FAILED(D3D10CreateDeviceAndSwapChain(NULL,
D3D10_DRIVER_TYPE_HARDWARE, //use hardware rendering
NULL, //must be NULL for hardware rendering. Software rendering use only
iCreateDeviceFlags, //creation flags
D3D10_SDK_VERSION, //SDK version
&sd, //swap chain description
&m_pSwapChain, //swap chain
&m_pDevice))) //d3d device
Assert(0, "Failed to create swap chain.");;

bind the back buffer of the swap chain as a render target, so
D3D10 can render to it.

ID3D10Texture2D *pBackBuffer = 0;

//call GetBuffer() to get the back buffer
if (FAILED(m_pSwapChain->GetBuffer(0,
__uuidof(ID3D10Texture2D), //interface used to manipulate the buffer
Assert(0, "Failed to get back buffer.");

resource views are a resource that can be bound to the graphics
pipeline at a specific stage. In this case, we are creating a
render target view resource that will be used as the back buffer

if (FAILED(m_pDevice->CreateRenderTargetView(pBackBuffer,
Assert(0, "Failed to create render target view.");


// Create depth stencil texture
D3D10_TEXTURE2D_DESC descDepth;
descDepth.Width = uiScreenWidth;
descDepth.Height = uiScreenHeight;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_D32_FLOAT;
descDepth.SampleDesc.Count = 1;
descDepth.SampleDesc.Quality = 0;
descDepth.Usage = D3D10_USAGE_DEFAULT;
descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
ID3D10Texture2D* pDepthStencil = 0;
hr = m_pDevice->CreateTexture2D( &descDepth, NULL, &pDepthStencil );
if( FAILED( hr ) )
return hr;

// Create the depth stencil view
descDSV.Format = descDepth.Format;
descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
descDSV.Texture2D.MipSlice = 0;
hr = m_pDevice->CreateDepthStencilView( pDepthStencil, &descDSV, &m_pDepthStencilView );
if( FAILED( hr ) )
return hr;

now we have created both the render target and depth stencil buffer,
we can bind them both to the pipeline so they will be used
at render time.

m_pDevice->OMSetRenderTargets( 1, &m_pRenderTargetView, m_pDepthStencilView );

//create our viewport
m_oMainViewport.Width = uiScreenWidth;
m_oMainViewport.Height = uiScreenHeight;
m_oMainViewport.MinDepth = 0.0f;
m_oMainViewport.MaxDepth = 1.0f;
m_oMainViewport.TopLeftX = 0;
m_oMainViewport.TopLeftY = 0;
m_pDevice->RSSetViewports(1, &m_oMainViewport);

//Alternate View Port is not used at the moment
//setup alternate render target
m_oAltViewport.Width = 1024;
m_oAltViewport.Height = 1024;
m_oAltViewport.MinDepth = 0.0f;
m_oAltViewport.MaxDepth = 1.0f;
m_oAltViewport.TopLeftX = 0;
m_oAltViewport.TopLeftY = 0;
//CreateAltRenderTarget(uiScreenWidth, uiScreenHeight);
//CreateAltDepthStencilTarget(uiScreenWidth, uiScreenHeight);

m_bIsMultiThreaded = false;

//Rasterizer State
ZeroMemory(&m_RasterizerDesc, sizeof(m_RasterizerDesc));
m_RasterizerDesc.CullMode = D3D10_CULL_BACK;
m_RasterizerDesc.FrontCounterClockwise = false;
//m_RasterizerDesc.DepthBias = 1;
//m_RasterizerDesc.DepthBiasClamp = 0;
//m_RasterizerDesc.SlopeScaledDepthBias = 0;
//m_RasterizerDesc.DepthClipEnable = false;
m_RasterizerDesc.ScissorEnable = false;
m_RasterizerDesc.MultisampleEnable = true;
m_RasterizerDesc.AntialiasedLineEnable = true;

m_bIsWireFrame = false;
if( m_bIsWireFrame )
m_RasterizerDesc.FillMode = D3D10_FILL_WIREFRAME;
m_RasterizerDesc.FillMode = D3D10_FILL_SOLID;

m_pDevice->CreateRasterizerState(&m_RasterizerDesc, &m_pRasterizerState);

return true;

thanks jason Z. i tried with PIX, it shows a black screen in depth buffer and a pinkn screen in stencil.. regarding the geometry it think the issue might be with the geometry.. Because when i run GPU perf Studio 2, the frame debugger shows the Input Assembly Topology to be D3D10_PRIMITIVE_TOPOLOGY_POINTLIST but i use


during the render....

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!