• Advertisement
Sign in to follow this  

[SharpDX] Question about Z-Buffer

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

In my game I need to render a background starsphere which obviously has to be rendered behind everything else.

With XNA it was pretty easy to do this with DepthStencilState.None before the draw call abd DepthStencilState.Default after it.

 

In SharpDX these two DepthStencilStates also exist (from looking at the source code), but somehow I can't access them.

 

So, is there an easy way to turn the Z-Buffer off and then back on, or do I need to dive deeper?

Share this post


Link to post
Share on other sites
Advertisement

You need to set the DepthStencilState of the DeviceContext .

For disabling DepthTesting and Writing to DepthBuffer :

DepthStencilStateDescription desc = new DepthStencilStateDescription();
desc.IsDepthEnabled=false;
desc.DepthComparison = Comparison.Always;
desc.DepthWriteMask = DepthWriteMask.Zero;
DepthStencilState state = new DepthStencilState(device, desc);
contex.OutputMerger.SetDepthStencilState(state); 

and for restarting back to default state you can just set DepthStencilState to null :

contex.OutputMerger.SetDepthStencilState(null); 

Share this post


Link to post
Share on other sites
In SharpDX these two DepthStencilStates also exist (from looking at the source code), but somehow I can't access them.

 

SharpDX is providing low-level DirectX and a higher level API with the Toolkit. I assume you are talking about the Toolkit, but please in the future, try to give more context.

 

That being said, I don't know how you are looking at the source code or even you are usually using an API, but the method GraphicsDevice.SetDepthStencilState is well defined.

 

Also, GraphicsDevice.DepthStencilStates.Default and None provides default states, and can be used like this:

GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.Default);
....

GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.None);

It is the same behavior for blend states and rasterizer states.

Share this post


Link to post
Share on other sites

 

In SharpDX these two DepthStencilStates also exist (from looking at the source code), but somehow I can't access them.

 

SharpDX is providing low-level DirectX and a higher level API with the Toolkit. I assume you are talking about the Toolkit, but please in the future, try to give more context.

 

That being said, I don't know how you are looking at the source code or even you are usually using an API, but the method GraphicsDevice.SetDepthStencilState is well defined.

 

Also, GraphicsDevice.DepthStencilStates.Default and None provides default states, and can be used like this:

GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.Default);
....

GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.None);

It is the same behavior for blend states and rasterizer states.

 

Thanks, that did the trick :) I was simply looking in the wrong place (doh).

 

Yes, I was talking about the toolkit.

 

As for the source code, I was looking here: https://github.com/sharpdx/SharpDX

Share this post


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

  • Advertisement