Reputation: 15896
I'm having a problem with the XNA SpriteBatch object.
When I draw an element that is semi-transparent in front of other elements, the other elements are hidden entirely, until the semi-transparent element is entirely transparent. This is really frustrating because I am trying to make a fade-in and fade-out effect.
Batch.Instance.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null);
That is how I start my SpriteBatch. As you can see, I set it to CullNone, but it appears that it still does Z-culling.
How can I prevent this?
Upvotes: 0
Views: 703
Reputation: 27245
Z-culling is a property of DepthStencilState
. To turn it off you need to use DepthStencilState.None
. The culling performed by RasterizerState
is by triangle winding order. Which I already explained to you in detail here.
You cannot use the depth buffer with transparency. You can use alpha-testing as a work-around for "alpha cut-outs". However for semi-transparent objects (like when they are fading in and out), drawing them in depth-order is your only option.
Which I've already suggested to you here. You never answered my question there: why on earth are you drawing your GUI that way anyway?
For more information: I've gone into more detail about transparency and the Z-buffer here.
Upvotes: 3