This is really bizzare.
I have 2 point sprites, one at (0,0,0) and the other at (0,0,1).
The first one is red, the second blue. The are both being rendered to the screen as textured quads, that face the camera (point sprites).
The red one is being rendered first, then the blue one second.

As you can see, this looks cool, and everything is working as expected.
However, if I then fly my ship round the other side of the sprites, I get this:

With the red quad "obscuring" the blue one, but nothing else in the scene.
How can I get around this bizzare problem? I'm guessing it's something to do with the Z-Buffer - but I don't know how to turn it on/off.
My Textured Quad Handler, in case this is of any help.
#region Using Directives
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using XNACore.Graphics;
using XNACore.Helpers;
#endregion
namespace XNACore.Graphics
{
class XNAHandler_TexturedQuad
{
private GraphicsDevice objDevice = null;
private XNAViewPort objViewPort = null;
private Effect objEffect;
private VertexBuffer myVertices;
private IndexBuffer myIndices;
public XNAHandler_TexturedQuad(ref XNAGame XNAGame, ref XNAViewPort XNAViewPort)
{
objDevice = XNAGame.Device;
objViewPort = XNAViewPort;
objEffect = XNAGame.Content.Load<Effect>(FolderHelper.ShadersFolder() + "TexturedQuad");
VertexPositionTexture[] verts = {
new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)),
new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1))};
int[] inds = { 0, 1, 2, 1, 3, 2 };
myVertices = new VertexBuffer(XNAGame.Device,
typeof(VertexPositionTexture), 4,
ResourceUsage.WriteOnly,
ResourceManagementMode.Automatic);
myVertices.SetData<VertexPositionTexture>(verts, 0, 4, SetDataOptions.None);
myIndices = new IndexBuffer(objDevice, typeof(int), 6,
ResourceUsage.WriteOnly, ResourceManagementMode.Automatic);
myIndices.SetData<int>(inds, 0, 6, SetDataOptions.None);
}
public void Render(ref XNAObject obj, Texture2D tex, Vector3 lookat)
{
XNAObject o = new XNAObject();
o.Position = obj.Position;
o.Rotation = obj.Rotation;
o.LookAt(lookat, 1.0f);
o.PitchDown(180.0f);
Render(ref o, tex);
}
public void Render(ref XNAObject obj, Texture2D tex)
{
objEffect.CurrentTechnique = objEffect.Techniques["TransformTexture"];
objEffect.Parameters["WorldViewProject"].SetValue(Matrix.CreateScale(obj.Scale)
* Matrix.CreateFromQuaternion(obj.Rotation)
* Matrix.CreateTranslation(obj.Position) *
objViewPort.MatrixView *
objViewPort.MatrixProjection);
objEffect.Begin();
foreach (EffectPass pass in objEffect.CurrentTechnique.Passes)
{
pass.Begin();
using (VertexDeclaration declaration = new VertexDeclaration(objDevice, VertexPositionTexture.VertexElements))
{
objDevice.VertexDeclaration = declaration;
objDevice.Textures[0] = tex;
objDevice.Vertices[0].SetSource(myVertices, 0, VertexPositionTexture.SizeInBytes);
objDevice.Indices = myIndices;
objDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);
}
pass.End();
}
objEffect.End();
}
}
}
And here's the Shader I'm using:
float4x4 WorldViewProject;
sampler TextureSampler;
struct VS_INPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
};
VS_OUTPUT Transform(VS_INPUT Input)
{
VS_OUTPUT Output;
Output.Position = mul(Input.Position, WorldViewProject);
Output.Texcoord = Input.Texcoord;
return Output;
}
struct PS_INPUT
{
float2 Texcoord : TEXCOORD0;
};
float4 Texture(PS_INPUT Input) : COLOR0
{
return tex2D(TextureSampler, Input.Texcoord);
};
technique TransformTexture
{
pass P0
{
VertexShader = compile vs_2_0 Transform();
PixelShader = compile ps_2_0 Texture();
}
}
Any help appreciated....
UPDATE:
I've noticed that I can turn off the depth buffer at shader level by adding the following line to my pass:
ZENABLE = FALSE;
However, this means that point sprites that should appear behind other objects, don't.

I've also noted that if I render the two point sprites the other way round, then the reverse happens. I.e. when the game first starts, the sprites appear obscured, and then moving round the other side makes it look normal again.
