Skip to main content
GameDev.net gamedev.net
🔒 Locked

Depth Buffer Driving me Crazy

Started by abeltherock007 Nov 15, 2010 at 12:04 AM 2 replies 1.3k views
Original Post
abeltherock007
abeltherock007
http://www.gamedev.net/community/forums/topic.asp?topic_id=583846&PageSize=25&WhichPage=2

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.
Xeile
Xeile
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.
Jason Z
Jason Z
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.
Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 
abeltherock007
abeltherock007
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;/*	SetCursorPos(iScreenWidth/2,iScreenHeight/2);*/	DXGI_SWAP_CHAIN_DESC sd;	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.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 	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;#endif	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		(LPVOID*)&pBackBuffer)))	{		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,		NULL, 		&m_pRenderTargetView)))	{		Assert(0, "Failed to create render target view.");	}	pBackBuffer->Release();	// 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;	HRESULT hr;	ID3D10Texture2D* pDepthStencil = 0;	hr = m_pDevice->CreateTexture2D( &descDepth, NULL, &pDepthStencil );	if( FAILED( hr ) )		return hr;	// Create the depth stencil view	D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;	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;		}	else	{		m_RasterizerDesc.FillMode = D3D10_FILL_SOLID;	}	m_pDevice->CreateRasterizerState(&m_RasterizerDesc, &m_pRasterizerState);	m_pDevice->RSSetState(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

GetMeshDevice()->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

during the render....

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.