0

I'm currently having some problems with alpha transparency in XNA and for anybody who has experience with the framework I'd appreciate some help. The code is below but in this code example note that:

ReadStencil = new DepthStencilState() 
             { 
               DepthBufferEnable = true,
               DepthBufferWriteEnable = false 
             };

and...

WriteStencil = new DepthStencilState() 
              {
                DepthBufferEnable = true,
                DepthBufferWriteEnable = true 
              };    

So here is the actual code:

SB.Begin();
GraphicsDevice.DepthStencilState = WriteStencil;
if (Scene != null) Scene.Draw();
Map.Draw();
SB.End();
SB.Begin();
GraphicsDevice.DepthStencilState = ReadStencil;
for (int i = 0; i < Players.Length; i++) if (Players[i] != null && Players[i].Active && Players[i].Respawn <= 0) Players[i].Draw();
if (Effects.Count > 0) for (int i = 0; i < Effects.Count; i++) Effects[i].Draw();

In this image, the depth is set to DepthStencilState.Default. Of course, the depth in this case is correct, but it appears as if is drawing the stage behind the transparency rather than the parts of the object behind it/other objects written in the "WriteStencil" state. Also note that on the fox character it does the same thing around the outlines of the hair on the tail and on the head/face.

Image

In this image, the depth has been distorted once again, but the initial issue is fixed. There is no invisible border around the hair meshes.

Image

I can imagine there is some way to fix this since it's one of those problems where one problem fixes the other, but I would appreciate help if possible!

Thanks much.

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
  • What is the code that draws those blue things? Are they effects and as such drawn last? – Nico Schertler Nov 03 '15 at 14:55
  • Yes those are the effects. They're drawn after everything else and the code is: if (Effects.Count > 0) for (int i = 0; i < Effects.Count; i++) Effects[i].Draw(); Being drawn afterwards shouldn't make a difference but the Z buffer is off for some reason. – BlackAfricano Nov 05 '15 at 01:06
  • So do you want the effect to be in front of everything else? Then disable the depth buffer completely. The players should be drawn with the default depth stencil state. – Nico Schertler Nov 05 '15 at 07:17

0 Answers0