• Advertisement
Sign in to follow this  

Rendering Multiple cubes

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

Hi,

 

I've a simple model. 

Several cubes. one 25 x 25 x 25 and one 10 x 10 x 10.

 

I render these largest to smallest however i only see the largest cube. whats could be the issue.

 

This project is an upgrade from directx9 managed code, where the cubes were stored in two mesh object and then rendered. and rendered correctly.

 

Please Help, I am a beginner and i am stuck!!

 

here is my Depth Stencil

D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
// Initialize the description of the stencil state.
ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));
			
// Set up the description of the stencil state.
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;

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;

My RasterizerState

D3D11_RASTERIZER_DESC rasterizerDescription;
ZeroMemory(&rasterizerDescription, sizeof(D3D11_RASTERIZER_DESC));
rasterizerDescription.FillMode = D3D11_FILL_SOLID;
/*rasterizerDescription.CullMode = D3D11_CULL_BACK;*/
rasterizerDescription.CullMode = D3D11_CULL_NONE;
/*rasterizerDescription.FrontCounterClockwise = FALSE;*/
rasterizerDescription.FrontCounterClockwise = TRUE;
rasterizerDescription.DepthBias = FALSE;
rasterizerDescription.DepthBiasClamp = 0.0f;
rasterizerDescription.SlopeScaledDepthBias = 0.0f;
/*rasterDescription.DepthClipEnable = TRUE;*/
rasterizerDescription.DepthClipEnable = FALSE;
rasterizerDescription.ScissorEnable = FALSE;
rasterizerDescription.MultisampleEnable = FALSE;
rasterizerDescription.AntialiasedLineEnable = FALSE;

and BlendState

blendStateDescription.RenderTarget[0].BlendEnable = TRUE;
//blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendStateDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendStateDescription.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
/*blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;*/
blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendStateDescription.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendStateDescription.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

Share this post


Link to post
Share on other sites
Advertisement

Could it be that you render both cubes in same position, so larger cube covers smaller cube?

 

Yes they are rendered at the same origin (0,0,0), however the largest is rendered first.

In Directx9 this resulted in the following.

 

DirectX9_1.png

 

 

however DirectX11 does this.

 

DirectX11.png

Share this post


Link to post
Share on other sites

If the smaller cube depth tests against the values already written to the depth-stencil buffer by the larger, its pixels will be found to be covered and discarded.

Try to set the DepthEnable member of your depth-stencil description to false to disable this and see if that makes it draw as intended, since it appears that you specify the desired drawing order yourself.

Share this post


Link to post
Share on other sites

If the smaller cube depth tests against the values already written to the depth-stencil buffer by the larger, its pixels will be found to be covered and discarded.

Try to set the DepthEnable member of your depth-stencil description to false to disable this and see if that makes it draw as intended, since it appears that you specify the desired drawing order yourself.

 

Hi,

 

Well i set the DepthEnable = False;

now it draws inside out.

 

DirectX11_DisableDepth.png

Share this post


Link to post
Share on other sites

Maybe it will work if you use D3D11_COMPARISON_LESS_EQUAL instead of D3D11_COMPARISON_LESS?

 

 

Vinterberg, your the man!!

Let me buy you a beer.

Share this post


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

  • Advertisement