Sign in to follow this  
Aardvajk

Pointsprites and depth buffer woes

Recommended Posts

Aardvajk    13207
I know pointsprites are frowned upon now but I'm writing a 3D modelling package and want to be able to render a small, 3x3 dot over each vertex in my projection view and they seem to work perfectly.

Apart from occlusion. I have z-buffering enabled when I render the actual model, but when I then render the pointsprite dots, those that should be occluded by a triangle from the model appear and disappear apparently at random as I rotate the model around, almost as if at certain rotations they are sneaking through the depth test.

I have tried literally everything I can think of - problem remains regardless of the point size, I've tried just rendering one triangle instead of the model, I've tried performing strange dances around my living room, nothing.

So has anyone ever experienced problems with inconsistent results from depth-buffering very small point sprites whose size is governed by pixel units?

Look: at this rotation some are visible and some aren't.

[attachment=2399:Image1.jpg]

Move the model very slightly around, some pop out of sight, others appear.

[attachment=2400:Image2.jpg]

Please don't say its just because driver support for pointsprites is rubbish, even if its true, because I'm screwed then. This is a D3D9 project so I can't start using complex geometry shaders and stuff.

Share this post


Link to post
Share on other sites
Jason Z    6436
Have you tried rendering the point sprites first? In that case the z-buffer should default to having the first entry visible instead of the polygon.

If that still doesn't work, you might be able to alter your view matrix slightly to add a small bias in the viewing direction when rendering the point sprites. That is kind of a hack, but so is using point sprites :P It might work, and should be fairly easy to try out.

Share this post


Link to post
Share on other sites
Aardvajk    13207
Thanks for the idea. Drawing the point sprites first did slightly reduce the problem, but the little sods are still sneaking through. Messing about with a depth bias didn't work either. Got a horrible feeling it's some kind of driver issue with pointsprites - hardly surprising since I'm the only person using them in the last five years :).

Think I'm going to have to rethink and try and do something complicated with billboards in a vertex shader. Even if I found a hack that worked with pointsprites, there is no guarantee it would be reliable on another graphics card.

Interestingly, with the REF device and software vertex processing, the problem is still there but very much reduced, so this is clearly not an issue with the actual approach.

But thanks for the idea anyway.

Share this post


Link to post
Share on other sites
Aardvajk    13207
FIXED IT! :)

I am such an idiot. It was nothing to do with pointsprites "sneaking through the depth test". It was plain and simple z-fighting because the depth buffer wasn't actually enabled due to me setting up the projection matrix wrong.

Funny how your mind can play tricks and miss something so obvious due to preconceptions - you see what you expect to see and no doubt.

I was getting the (WARN) Unable to compute ZNear and ZFar in the debug output, but I had it in my head that for D3DXMatrixPerspectiveFovLH, I had to pass 0 and 1 as these values and the debug was saying it had done this for me. Got no errors in the debug window so never thought that that could prevent the depth buffer being switched on. Still find it odd.

But after some desperate Googling, discovered that 0 is a bad value for a near-clip plane. Using 0.01f and 1000.0f has sorted it, now the depth buffer is on it is working perfectly and I can probably sleep again now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this