r3n

I have a primative which I am rendering from a vertex buffer (positioned, colored, textured), among some meshes.

All of the meshes seem to work fine with the Z buffer, texutre transparency works fine... except for when I make my primative transparent, you can only see the cleared background, and none of the meshes behind it.

Just to give you an idea, here's some code! (obviously not all in the same method).

frontVertices = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured),
4, Device,
Usage.WriteOnly, CustomVertex.PositionColoredTextured.Format, Pool.Default);

CustomVertex.PositionColoredTextured[] vertices = frontVertices.Lock(0, LockFlags.None) as CustomVertex.PositionColoredTextured[];

vertices[0] = new CustomVertex.PositionColoredTextured(0, 0, 1, colour, 0, 0);
vertices[1] =
new CustomVertex.PositionColoredTextured(50, 0, 1, colour, 1, 0);
vertices[2] =
new CustomVertex.PositionColoredTextured(0, 50, 1, colour, 0, 1);
vertices[3] =
new CustomVertex.PositionColoredTextured(50, 50, 1, colour, 1, 1);

frontVertices.Unlock();


----------------------------------------


int alpha = 180;

Device.RenderState.TextureFactor =
Color.FromArgb(alpha, 255, 255, 255).ToArgb();
Device.TextureState[0].AlphaOperation =
TextureOperation.Modulate;
Device.TextureState[0].AlphaArgument1 =
TextureArgument.TextureColor;
Device.TextureState[0].AlphaArgument2 =
TextureArgument.TFactor;
Device.RenderState.AlphaBlendEnable =
true;
Device.RenderState.SourceBlend =
Blend.SourceAlpha;
Device.RenderState.DestinationBlend =
Blend.InvSourceAlpha;

Device.SetTexture(0, mainTexture);
Device.SetStreamSource(0, frontVertices, 0);
Device.VertexFormat =
CustomVertex.PositionColoredTextured.Format;
Device.DrawPrimitives(
PrimitiveType.TriangleStrip, 0, 2);



Re: Game Technologies: Graphics Using VertexBuffer with Z-Buffer

Ralf Kornmann

If you only need full transparent and full solid you should use alpha test instead of alpha blending. If you need partial transparency you have to sort your objects back to front based on the Z value in screen space.






Re: Game Technologies: Graphics Using VertexBuffer with Z-Buffer

r3n

Hi Ralf, the entire texture needs to be transparent, as it fades out to reviel the object behind it.

Anyway, simple enough, I have solved the problem:

This was meerly a case of rendering in the right order. Because I was rendering the primatives before the meshes, I guess DirectX assumed the Z position of the primatives was behind the meshes. Unless anyone can provide a more logical explanantion