I got some problem with texture transparency, I hope ya can help.
Details:
- XNA 4.0
-
Texture source is BMP, what I make transparent by code:
public void Feketealapú(string Azonosító) { //textúra megállapítása Texture2D Textúra = Textúrák[TextúraSzáma(Azonosító)]; //adatok lekérése Color[] buffer = new Color[Textúra.Width * Textúra.Height]; Textúra.GetData<Color>(buffer); //adatok módosítása for (int i = 0; i < buffer.Length; i++) { Color szín = buffer[i]; szín.A = ((byte)((szín.R + szín.B + szín.G) / 3)); buffer[i] = szín; } //adatok visszaírása Textúra.SetData<Color>(buffer); } -
I use the following before I start drawing 3d stuff:
public void Rajzolj() { GStatic.Játék.GrafikaiCsatorna.BlendState = BlendState.AlphaBlend; GStatic.Játék.GrafikaiCsatorna.DepthStencilState = DepthStencilState.Default; GStatic.Játék.GrafikaiCsatorna.RasterizerState = RasterizerState.CullCounterClockwise; GStatic.Játék.GrafikaiCsatorna.SamplerStates[0] = SamplerState.LinearWrap;..etc.
-
If I use BlendState.Opaque I get no transparent textures.
-
I get into the following trouble: http://youtu.be/ZiPzyk7AWu8
-
Edit: Bit more detail about the problem is: the problem is with the transparent texture, what simulates a fire effect. The fire is from several rectangles with these transparent textures. If I see the fire from an angle, I should see another fire effect’s rectangle through the transparent texture, what is also transparent. The problem is that instead of this, I see the floor’s texture behind the model instead.
So could someone help me out a bit?
Thanks in advance:
Péter
Never mind I don’t think the transparency is the issue. I think that whats happening is the first thing in the Z-Buffer is being draw and nothing else behind it.
http://blogs.msdn.com/b/shawnhar/archive/2009/02/18/depth-sorting-alpha-blended-objects.aspx
The most import part being the where he specifies how best to order your scene and manipulate the DepthBuffer.