Jump to content
  • Advertisement
Sign in to follow this  

Depth sorting issue

This topic is 2096 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

Hey guys I'm makeing a little renderer with direct3d 11 and some other external libs in c++ and yertserday I finished my meshloader.

Now I load the sponza model with only one texture assigned, but I get a problem with the depth sorting of the faces.

I checked the depthstencil state for Front/Backfaces and the rasterizer but I don't know why it does that..

Well here is a picture, where you can see that some meshes are drawn over others ,although they are behind the others : http://s1.directupload.net/images/131019/vzungyy4.jpg


I hope you can help me Thanks :)

Share this post

Link to post
Share on other sites

For testing purposes do not set any depth stencil state, default one works properly.

Did you actually create & set your depth stencil? Did you check return codes? They use different formats and personally I often have troubles with it.

Share this post

Link to post
Share on other sites

Hey thanks I checked that stuff with the result code and found out that the last depth stencil view creation fails but I don't know why.I get the code E_INVALIDARG , that means I paste a invalid argument to the methode but I followed the code in MSDN and have exactly the same code :/


I know it isn't very cool so paste here the code but maybe somebody see the issue ? Would be very nice 

D3D11_TEXTURE2D_DESC tmp_depthdesc;
    ZeroMemory( &tmp_depthdesc, sizeof(tmp_depthdesc) );
    tmp_depthdesc.Width = m_width;
    tmp_depthdesc.Height = m_height;
    tmp_depthdesc.MipLevels = 1;
    tmp_depthdesc.ArraySize = 1;
    tmp_depthdesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
    tmp_depthdesc.SampleDesc.Count = 1;
    tmp_depthdesc.SampleDesc.Quality = 0;
    tmp_depthdesc.Usage = D3D11_USAGE_DEFAULT;
    tmp_depthdesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
    tmp_depthdesc.CPUAccessFlags = 0;
    tmp_depthdesc.MiscFlags = 0;
    result =  m_direct3DDevice->CreateTexture2D( &tmp_depthdesc, NULL, &m_depthStencilTex ); // Erstellen der Depthstencil Textur


	D3D11_DEPTH_STENCIL_DESC tmp_StencilStateDesc;
	tmp_StencilStateDesc.DepthEnable = true;
	tmp_StencilStateDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
	tmp_StencilStateDesc.DepthFunc = D3D11_COMPARISON_LESS;

	tmp_StencilStateDesc.StencilEnable = true;
	tmp_StencilStateDesc.StencilReadMask = 0xFF;
	tmp_StencilStateDesc.StencilWriteMask = 0xFF;

	// Stencil operations if pixel is front-facing.
	tmp_StencilStateDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	tmp_StencilStateDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
	tmp_StencilStateDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	tmp_StencilStateDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

	// Stencil operations if pixel is back-facing.
	tmp_StencilStateDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	tmp_StencilStateDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
	tmp_StencilStateDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	tmp_StencilStateDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

	result = m_direct3DDevice->CreateDepthStencilState(&tmp_StencilStateDesc,&m_depthStencilState);

	D3D11_DEPTH_STENCIL_VIEW_DESC tmp_depthViewDesc;
    ZeroMemory( &tmp_depthViewDesc, sizeof(tmp_depthViewDesc) );
    tmp_depthViewDesc.Format = DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
    tmp_depthViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
    tmp_depthViewDesc.Texture2D.MipSlice = 0;

	result = m_direct3DDevice->CreateDepthStencilView( m_depthStencilTex, // Depth stencil texture
                                         &tmp_depthViewDesc, // Depth stencil desc
                                         &m_depthStencil);  // [out] Depth stencil view

	ACore::IConsole::Instance()->AddHRESULTInfo(result,"HERE THE FAILURE");

Share this post

Link to post
Share on other sites

And the CreateTexture2D is fine, no errors nor warnings?


Try not setting the Depth Stencil State in between, maybe it becomes unavailable somehow when it's set, and as you use it to create a new view afterwards, it's maybe not possible (I don't actually know if this is the case, but I'm just trying to narrow down the problem).


EDIT: I guess it's fine as you check it, sorry about this.

Edited by Migi0027

Share this post

Link to post
Share on other sites

You create DXGI_FORMAT_D24_UNORM_S8_UINT texture (32 bit) why your DSV is DXGI_FORMAT_D32_FLOAT_S8X24_UINT (64 bits) that's why it doesn't work.

If need Stencil and still want to use that texture format then I think DXGI_FORMAT_D24_UNORM_S8_UINT is the right choice for DSV.

You can also pass nullptr for 2nd parameter in CreateDepthStencilView() call, it'll use default values which shouldn't fail.

Edited by Zaoshi Kaba

Share this post

Link to post
Share on other sites

Hey thanks for the answer I added the directx debug layer yesterday and it told me the fact with the format.

I passed in the Format from the ID3D11Texture2D creation above and now it works.Also I had a problem with the flags but with ZeroMemory it works fine now.


Well now I have a issue with the OMSetRenderTargets function smile.png

It tells me the rendertargetview and the depthstencil are not compatible.My rendertargetview is a líttle bit smaller from the dimensions..I don't know why..

ID3D11DeviceContext::OMSetRenderTargets: The RenderTargetView at slot 0 is not compatable with the DepthStencilView. DepthStencilViews may only be used with RenderTargetViews if the effective dimensions of the Views are equal, as well as the Resource types, multisample count, and multisample quality. The RenderTargetView at slot 0 has (w:1008,h:730,as:1), while the Resource is a Texture2D with (mc:1,mq:0). The DepthStencilView has (w:1024,h:768,as:1), while the Resource is a Texture2D with (mc:1,mq:0). D3D11_RESOURCE_MISC_TEXTURECUBE factors into the Resource type, unless GetFeatureLevel() returns D3D_FEATURE_LEVEL_10_1 or greater. [ STATE_SETTING ERROR #388: OMSETRENDERTARGETS_INVALIDVIEW]



EDIT: I've got it.Just got the client dimensions with GetClientRect and passed it to the desc.Well I never saw that before...always the normal resolution..

Edited by StanIAm

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!