Z-Ordering problem (solved)

Started by Hrolf, January 04, 2011, 08:43:48 PM

Previous topic - Next topic

Hrolf

I seem to be having a problem with the z-ordering in my game. When objects are close together they intermittently overwrite each other even though they are at different distances from the camera. You can see this happening to the soldiers on the tower in this video.
This happens with both software and LWJGL rendering. What might be causing this? How can I prevent it?
Thanks in advance!

EgonOlsen

Difficult to tell from the video what exactly is going on here. I assume that the soldiers are billboards (not that it would matter much...)? There is a method in Object3D called setSortOffset to deal with improper sorting. However, it's not very handy for this situation, because the sort offset might change from frame to frame when the camera rotates. You can of course recompute (or reestimate) it for each frame, but that doesn't feel like a very good solution to me.
Can you provide me with a simple test case that shows this problem, so that i can be sure what exactly is causing it!?

Hrolf

Ah, I was hoping it was a known issue!  :-\
They aren't exactly billboarded, they're rotated by the Y axis to face the camera, then tilted back slightly based on the camera height so they're foreshortened when viewed from directly above. I'll try and get a test-case together...

EgonOlsen

The issue itself is common when sorting transparent objects. Painter's algorithm isn't perfect when sorting, so wrong sort order may happen depending on how the objects are located to each other. But that doesn't seem to be the exact case here. Looks more as if all objects share the same depth value for sorting, which actually can't be. That's why a test case would be really helpful.

EgonOlsen

BTW: Have you tried what happens when you don't tilt them?

Hrolf

#5
Actually they aren't tilted after all, they stay vertical.
Test case here (source here). It's not intermittent but seems to show the same issue?

EgonOlsen

#6
Thank you for the test case. It's an accuracy issue with floating point values. I'll see if i can find a general solution or if i have to add some additional setting...

Edit: Please give this beta jar a try to see if it fixes the issue and doesn't introduce any other problems: http://www.jpct.net/download/beta/jpct.jar

Hrolf

God, you're good! That certainly fixes the test case - I'll plug it into the game tomorrow for a fuller test - any particular side effects I should look out for?

EgonOlsen

Wrong sorting of a different kind might be a side effect, but i don't expect it.

Hrolf

As far as I can tell this version works perfectly - many thanks!