# Rendering Multiple cubes

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

## 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.

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.DepthFunc = D3D11_COMPARISON_LESS;

depthStencilDesc.StencilEnable = true;

// 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].SrcBlendAlpha = D3D11_BLEND_ONE;*/
blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;


##### Share on other sites

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

##### Share on other sites

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.

however DirectX11 does this.

##### 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 on other sites

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

##### 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.

##### Share on other sites

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