Jump to content
  • Advertisement
Sign in to follow this  
Blasp

How to disable depth write?

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

I am making a particle system. My particles are rendered as quads with additive blending only, so no sorting necessary. However they have squarish artifacts around them (see the screenshot), which if I am not mistaken is a result of depth writing not getting disabled. How to disable it correctly?

 

Here is what I do:

ID3D11DepthStencilState* pDepthdisabledStencilState;
ID3D11DepthStencilState* pDepthenabledStencilState;


// initialization

	D3D11_DEPTH_STENCIL_DESC depth_write_disabled_desc;
	depth_write_disabled_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
	hr = d3d11Device->CreateDepthStencilState(&depth_write_disabled_desc, &pDepthdisabledStencilState);

	D3D11_DEPTH_STENCIL_DESC depth_write_enabled_desc;
	depth_write_enabled_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
	hr = d3d11Device->CreateDepthStencilState(&depth_write_enabled_desc, &pDepthenabledStencilState);



// rendering

	d3d11DevCon->OMSetBlendState(Blend_Add, blendFactor_full, 0xffffffff);
	d3d11DevCon->OMSetDepthStencilState(pDepthdisabledStencilState, NULL);
	for (Drawable* drawable_ptr : Drawable_ptr_Vector)
	{
		if (drawable_ptr->attributes.x == 8.0)		// Quads, Particles
		{
			drawable_ptr->Draw();
		}
	}
	d3d11DevCon->OMSetDepthStencilState(pDepthenabledStencilState, NULL);

What am I doing wrong?

Share this post


Link to post
Share on other sites
Advertisement

Here is the blend mode I am using for particles:

D3D11_BLEND_DESC blendDesc;
	ZeroMemory(&blendDesc, sizeof(blendDesc));
	blendDesc.AlphaToCoverageEnable = true;
	D3D11_RENDER_TARGET_BLEND_DESC rtbd;
	ZeroMemory(&rtbd, sizeof(rtbd));
	rtbd.BlendEnable = true;

	rtbd.SrcBlend = D3D11_BLEND_BLEND_FACTOR;
	rtbd.DestBlend = D3D11_BLEND_ONE;
	rtbd.BlendOp = D3D11_BLEND_OP_ADD;
	rtbd.SrcBlendAlpha = D3D11_BLEND_BLEND_FACTOR;
	rtbd.DestBlendAlpha = D3D11_BLEND_ONE;
	rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD;
	rtbd.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
	blendDesc.RenderTarget[0] = rtbd;
	d3d11Device->CreateBlendState(&blendDesc, &Blend_Add);

I forgot to tell that the particles are constructed on the CPU as one big model and rendered with a single draw call. Indeed, they blend correctly with everything but each other, It looks as if only the nearest particles are visible and obscures the others.

Share this post


Link to post
Share on other sites

Attached is a screenshot of five quads rendered separately. They were rendered in this order from the camera: 1st, 2nd, 5th, 4th, 3rd. As you can see, they blend correctly if sorted from furthest to nearest, but not in the opposite case.

 

However I shouldnt have to sort particles for a simple additive blending..

Share this post


Link to post
Share on other sites


D3D11_DEPTH_STENCIL_DESC depth_write_enabled_desc;
depth_write_enabled_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
hr = d3d11Device->CreateDepthStencilState(&depth_write_enabled_desc, &pDepthenabledStencilState);

 

Is this your actual code verbatim? In that snippet you're only setting one value of the D3D11_DEPTH_STENCIL_DESC structure, so the rest will be stack garbage. What's the return value of the call to CreateDepthStencilState?

 

If you use the directx debug runtime, is there any interesting spew?

Share this post


Link to post
Share on other sites
What happens inside the drawable_ptr->Draw() call? It's not also setting the depth/stencil state, is it?

[edit]
On phil's post above, you should always initialize descriptors to zero with:
D3D11_DEPTH_STENCIL_DESC depth_blah = {};

Share this post


Link to post
Share on other sites

On phil's post above, you should always initialize descriptors to zero with:
D3D11_DEPTH_STENCIL_DESC depth_blah = {};

 

This solved the problem! :)

 

Thank you all for help!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!