Geometry shaders and depth testing

I’ve recently been working on using Cg geometry shaders for generating point sprites rather using than ARB sprites. In order to have the sprites be in “world space” rather than screen space, I’m doing the MVP multiplication in the geometry shader like so:

POINT
TRIANGLE_OUT
void SpriteGeomProg(
	AttribArray<float4> pos		: POSITION,
	AttribArray<float2> params	: TEXCOORD0, //x=width, y=height
	uniform float3		world_up,
	uniform float3		eye_right )
{
  // Expand point into vertically alligned quad
  const float4 pos1 = mul( glstate.matrix.mvp, pos[0] + float4( -eye_right * params[0].x, 1.f ) );
  const float4 pos2 = mul( glstate.matrix.mvp, pos[0] + float4(  eye_right * params[0].x, 1.f ) );
  const float4 pos3 = mul( glstate.matrix.mvp, pos[0] + float4(  eye_right * params[0].x + world_up * params[0].y, 1.f ) );
  const float4 pos4 = mul( glstate.matrix.mvp, pos[0] + float4( -eye_right * params[0].x + world_up * params[0].y, 1.f ) );

  emitVertex( pos1: POSITION );
  emitVertex( pos2: POSITION );
  emitVertex( pos3: POSITION );

  emitVertex( pos3: POSITION );
  emitVertex( pos1: POSITION );
  emitVertex( pos4: POSITION );
}

The problem I’m seeing is that it appears as though the depth testing against other elements in the scene is not working as expected. While the sprites occlude one another, they are not occluded by other objects in the scene. The ARB point sprites did not behave this way. Also, if I perform the MVP multiplication in the vertex program, there is no problem.

Is there a problem with doing the MVP multiplication in the geometry shader in this way?

FYI, I’m running on an 8800M GTX with 177.89 GL3 beta drivers.

The problem maybe is
float4( -eye_right * params[0].x, 1.f ) );
change those to 0.0f

having a vertex_pos.w=2 won’t be nice :slight_smile:

DOH! That was it. Good catch! Thanks very much!