Author Topic: Z-Ordering problem (solved)  (Read 4600 times)

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Z-Ordering problem (solved)
« on: January 04, 2011, 08:43:48 pm »
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!
« Last Edit: January 05, 2011, 02:30:04 pm by Hrolf »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Z-Ordering problem
« Reply #1 on: January 04, 2011, 09:03:19 pm »
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!?

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Z-Ordering problem
« Reply #2 on: January 04, 2011, 09:50:46 pm »
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Z-Ordering problem
« Reply #3 on: January 04, 2011, 09:59:47 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Z-Ordering problem
« Reply #4 on: January 04, 2011, 10:03:51 pm »
BTW: Have you tried what happens when you don't tilt them?

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Z-Ordering problem
« Reply #5 on: January 04, 2011, 10:34:38 pm »
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?
« Last Edit: January 05, 2011, 02:29:40 pm by Hrolf »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Z-Ordering problem
« Reply #6 on: January 04, 2011, 11:06:51 pm »
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
« Last Edit: January 04, 2011, 11:13:37 pm by EgonOlsen »

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Z-Ordering problem
« Reply #7 on: January 05, 2011, 04:49:42 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Z-Ordering problem
« Reply #8 on: January 05, 2011, 08:06:54 am »
Wrong sorting of a different kind might be a side effect, but i don't expect it.

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: Z-Ordering problem (solved)
« Reply #9 on: January 05, 2011, 02:31:50 pm »
As far as I can tell this version works perfectly - many thanks!