World_to_screen_pos + moving Camera causes a jittering problem when I trying to set a world position for GUI container

I have some strange problem with attaching my GUI container to some world position. Please, take a look at my small reproduction at the bottom of the message.

Main features:

  • My camera is top-down view (90 degrees by X)
  • Camera is moving by Math.sin()
  • GUI image jitters or makes some micro-jumps
    • Can you confirm that you see this as well or am I the only who sees it?
  • Other world objects move fine without jittering even when camera slows down
  • I can’t use attached to mesh GUI ADT type as I have many independent gui containers that should move with its meshes. So it will make many useless drawcalls count instead of having just one ADT and moving containers inside it and having just one drawcall per all the containers which move independently.

Could you please take me some your guesses what it can be? And what do I check first to solve this problem?

My guesses:

  • Wrong sampling method for ADT
    • Tried to change it from default one, but nothing changes
  • Vector3.Unproject gives me old coordinates from the previous frame
    • Tried to make my own projection function as the camera easily allows to do it as it’s just top-down view. It looks that works a little bit better but maybe it only seems to me so :smile:

Here is my: playground

scene.getTransformMatrix() is not yet updated for the current frame in the scene.registerBeforeRender observable. You should calculate the transformation matrix yourself:

However, as you can see, it doesn’t fix the jittering… I think the problem is that there are two transformations (world to screen and screen to gui), and because of floating point errors, the final position will jitter of one pixel from time to time. I don’t know how to fix it, unfortunately… Maybe others will be able to help.

1 Like