Z Fighting - I know, I know, use polygon offset, but...

The thing is, Polygon Offset doesn’t seem to work correctly for me. The situation is like this:

I have 3 concentric cylinders which may or may not touch at certain points. Now, where they touch I’m hopefully alpha-testing fragments away but sometimes the fragment isn’t alphad’ away and I’m left with a bit of z fighting where that fragment shows through. Because the fragments are all part of cylinders, its difficult to work out what parameters to use in polygon offset or even whether its appropriate at all!

Any hints? (ehem…)

Originally posted by Robbo:
[b]
The thing is, Polygon Offset doesn’t seem to work correctly for me. The situation is like this:

I have 3 concentric cylinders which may or may not touch at certain points. Now, where they touch I’m hopefully alpha-testing fragments away but sometimes the fragment isn’t alphad’ away and I’m left with a bit of z fighting where that fragment shows through. Because the fragments are all part of cylinders, its difficult to work out what parameters to use in polygon offset or even whether its appropriate at all!

Any hints? (ehem…)[/b]

what are you using for your near and far clip planes?

use the stencil buffer.

Stencil buffer sounds ideal but the problem is it isn’t hardware accelerated - so its going to slow down my fps considerably.

My near\far clip plane is currently 1.0 to 150.0 - however, I’ve played around with it (ie. 0.1 - 200.0 or 1.0 to 1000.0 etc.).

I’ve solved the problem for now by alpha testing away bits that touch or might touch - not quite correct but it works.

By moving the near plane or using glDepthRange you can get similar functionality as polygon offset. I’ve had much more consistent results using the above methods than using glPolygonOffset.

Actually, I think the stencil buffer is the answer because changing the near\far planes or using glPolygonOffset will alter selection buffer results anyway - and I’m using the GL selection buffer at the moment (pending geometry based hit testing implementation).