Depth stencil state issue

Started by
20 comments, last by unbird 10 years, 6 months ago

Hi!

The black depth channel is somewhat expected, due to the non-linear distribution of the z-values. Right beside the combobox where you selected the "depth" channel, you have a gray bar that allows you to filter the range displayed linearly. There are tiny triangles (top-left at the bar, and bottom-right). These are the lower and upper bounds. You can move them around, so that you have the lower bound around 0.95. That should show you something.

On the top left of the window is a small "save" icon. You could save the PIXrun and upload it, so that we might have a look.

Best, Tsus

Advertisement

Additionally, click on the device context "hyperlink" (it only turns blue after you have looked at the render or mesh tab). You can now inspect what states are set and what resources are bound, one tab for every pipeline stage.

Lucky guess: Depth doesn't work if the render target and depth buffer have a mismatching size or sample description, but that should turn up from the debug layer (in PIX it's the "Output Log" tab). Also check your projection matrix: What near plane do you use ?

https://docs.google.com/file/d/0B7G-_39cTN3nSUFyYldITk1VUlU/edit?usp=sharing

here'the run.....thanks everybody for the help by the way...

P.S this is my projection matrix


mProj = XMMatrixPerspectiveFovLH( 1.0, set->mapSettings["SCREEN_WIDTH"] / (FLOAT)set->mapSettings["SCREEN_HEIGHT"], 0.01f, 100.0f );

and viewport just in case


void Engine::InitViewport()
{
	ZeroMemory (&mViewport, sizeof(D3D11_VIEWPORT));
	//set the viewport
	mViewport.TopLeftX = 0;
	mViewport.TopLeftY = 0;
	mViewport.Width = set->mapSettings["SCREEN_WIDTH"];
	mViewport.Height = set->mapSettings["SCREEN_HEIGHT"];
	mViewport.MinDepth = 0.0f;
    mViewport.MaxDepth = 1.0f;
	SetViewport();
}

void Engine::SetViewport()
{
	mDeviceContext -> RSSetViewports(1, &mViewport);
}

These are the lower and upper bounds. You can move them around, so that you have the lower bound around 0.95. That should show you something.

actually it doesn't :) i tried different values but it's still either full black or full white...

kind of expectable since it's not working in the first place :/

Lucky guess: Depth doesn't work if the render target and depth buffer have a mismatching size or sample description, but that should turn up from the debug layer (in PIX it's the "Output Log" tab). Also check your projection matrix: What near plane do you use ?

this might be it actually.. .i never set a render target view description...... I'm coding it right now to see if it helps....

EDIT:

http://msdn.microsoft.com/en-us/library/windows/desktop/ff476201(v=vs.85).aspx

there doesn't seem to be a sample description...

ok i probably am missing something on how to add a target description as it seems to work differently than for other resources...


ID3D11Texture2D* pTexture;
	mSwapChain -> GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pTexture);

	D3D11_TEXTURE2D_DESC textureDesc;
	textureDesc.Width = set->mapSettings["SCREEN_WIDTH"];
	textureDesc.Height = set->mapSettings["SCREEN_HEIGHT"];
	textureDesc.MipLevels = 1;
	textureDesc.ArraySize = 1;
	textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
	textureDesc.Usage = D3D11_USAGE_DEFAULT;
	textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET;
	textureDesc.SampleDesc.Count=1;
	textureDesc.SampleDesc.Quality=0;
	textureDesc.CPUAccessFlags = 0;
	textureDesc.MiscFlags = 0;

	HRESULT hr = mDevice->CreateTexture2D(&textureDesc, NULL, &pTexture);

	D3D11_RENDER_TARGET_VIEW_DESC targetViewDescription;
	ZeroMemory(&targetViewDescription, sizeof(D3D11_RENDER_TARGET_VIEW_DESC));
	targetViewDescription.Format = DXGI_FORMAT_D32_FLOAT;

	hr =mDevice ->CreateRenderTargetView(pTexture, &targetViewDescription, &mTargetView);
	pTexture -> Release();
	pTexture = 0;

first hr is ok and second invalidarg

Now you made it worse (by adding to the confusion). Take a step back. You already had a render target view (mRenderTargetView_Backbuffer) set otherwise nothing would render. So your PIX run was "fine", and I think I was spot on: Your bound render target texture (probably coming from your swap chain) has is 1304x478 and your depth buffer is 1280x720.

Normally I would suspect the common pitfall of a mismatch between windows client size and render target size (search the forum and also lookup GetClientRect and AdjustWindowRectEx in the WinAPI docs).

But here the height is so far off, there's likely something else going on. Anyway: render target and depth size must match (forget about sample description for now, this is only for MSAA, just use (1,0) throughout).

It looks like you're getting your dimensions from a (global) configuration. Make sure those values are correct after window and swapchain creation (and after window resize, if you handle that too).

Edit: Wait, PIX is making a mess on my side with that run. The swapchain texture changes size dependant of the render tab size (huh?). In the objects tab the sizes match perfectly 1280x720. Strange. Depth seems to work, by the way.

Edit: Oh, yeah: You really should use the D3D11_CREATE_DEVICE_DEBUG flag. In that PIX run you still don't. As said, the debug layer would scream about the size mismatch.

ok so i noticed i was using different samples for the swapchain and the depth buffer...

now if i set them both to 1,0 i can see my meshes but not the console..... if i set them to 8,1 i can see them both.. does someone have an explanation for this?

the depth buffer is not working anyway...

It's working.... ok turns out i forgot to set the swapchain width and height.....

so i set them same way i set everything else and it's now working correctly...

This topic is closed to new replies.

Advertisement