Sprite Z-fighting again.....

Hello, I am working on the particle system for my game again and ran into a new/old problem. I sort the particles and draw them in order and such and, in most cases, there is no z-fighting. However I’ve noticed that if any of the particles (that are near each other) have different scales or spins (rotations along the viewer’s axis) a large amount of z-fighting occurs.

Here is a screen shot:

(looks worse in real-time)

I understand that if the particles are to close for the depth buffer to handle that z-fighting will occur, but how would the sprites being at different scales cause the problem?? :confused:

Thanks in advance

  1. Your z depth seem to be badly distributed. Try to put the near plane farther (and the far plane nearer if possible)
  2. If the particles are sorted, why using depth writes at all ? Keep depth testing so that particles are occluded by terrain, but disable depth writes so that so z-fighting can not occur between your particles.

Thanks for the reply,
I disabled depth writes and it did “fix” the problem , but as you mentioned occlusion doesn’t occur. Along with that, there is this strange flickering that doesn’t look like z-fighting. I think it is related to my sorting function. Perhaps that or something related to that is causing the z-fighting.

I’ll still do not understand why z-fighting would not occur if all particle are the same size, and not if they are different sizes.

but as you mentioned occlusion doesn’t occur.
With depth writes only for terrain and not for particles, there should be correct occlusion.

Maybe you don’t do the scaling/rotating of particles at the right place, so they twist a bit, and then end up as not parallel.

So it would not really be z-fighting. You can trying moving the near and far planes as I said : if there no significant changes on the picture, then it is not z-fighting.

Zbuffer is right, but your popping is unavoidable with a moving eye as one particle’s depth intersects anothers, the best way to improve this is manage more smaller particles (feasible since you’ll be heavily fill limited at the moment) or manage their alpha etc but this could take a pretty sophisticated system.

There is a popping issue as well, but I don’t think the flickering is part of it because it occurs even when the camera is only zooming and not rotating/panning.

It would not be bad to lower the far plane and and increase the near, but the game will be oriented around distant ocean views, but also close up views when managing characters on the battlefield. So unless there is no other way I’d like to keep it high.

(After thought) Would it be possible to dynamically manage the near/far clipping plane so that the range increases when the camera zooms out and decreases when the camera zooms in?

Maybe you don’t do the scaling/rotating of particles at the right place, so they twist a bit, and then end up as not parallel.

I’ll look into this, it would make a lot of sense for this to be the case since the z-fighting only occurs when the particles are at different scales/spins.

Just wanted to add:
I decreased the range of depth from 1-800 to 20-200 and that did not affect the z-fighting.
Perhaps the problem is that there truly is 2 quads on the exact same location for every sprite. This might not be a problem if they were the same size because traded pixels would be the same no matter which pixel takes the nearer depth. And once they become different sizes the pixels would be different.

[EDIT]
Confirmed. Case closed :slight_smile: Duplicate particles are drawn in exactly the same location.
[/EDIT]