PDA

View Full Version : Sprite Z-fighting again.....



darkrappey
05-13-2007, 01:27 AM
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:
http://img523.imageshack.us/img523/7146/untitledta1.th.jpg (http://img523.imageshack.us/my.php?image=untitledta1.jpg)
(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

ZbuffeR
05-13-2007, 04:00 AM
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.

darkrappey
05-13-2007, 11:10 AM
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.

ZbuffeR
05-13-2007, 12:16 PM
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.

dorbie
05-14-2007, 02:25 AM
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.

darkrappey
05-14-2007, 06:00 PM
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.

darkrappey
05-15-2007, 12:12 AM
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.


Confirmed. Case closed :) Duplicate particles are drawn in exactly the same location.