Skip to content

Conversation

@almarklein
Copy link
Collaborator

@almarklein almarklein commented Oct 2, 2025

Closes #903, closes #839.

  • Graphics are no longer offset in depth, because the depth may actually mean something.
  • Except ImageGraphics, they are now pushed back (older further away).
  • Lines, points, and axes use depth_campare="<=" so that for objects at the same depth, the render order determines which one is on top.
  • Set render_queue of axes so they are rendered later than all the other objects.

This should make it that axes and graphics interact as expected in both 3D and 2D scenes. Note that in a 2D view (panzoom controller), if a scatter graphic has data that is nonzero for z, it can indeed cover the axes, but this is expected.

@almarklein
Copy link
Collaborator Author

One thing that makes this tricky is that although a lot of examples / use-cases are 2D, it's hard to determine reliably when we can assume the scene to be 2D. Therefore I went with an approach that more or less assumes 3D but also works well in 2D.

@kushalkolar
Copy link
Member

Older images pushed back, so this means if I add a new image it will appear on top of the existing ones? This is desired and most intuitive, and is similar with other plotting libs.

If I add a like and then scatter points, these points will appear on top of the line?

Usually the scene is 3D if the camera.fov > 50

Btw there was this related ideas before: #839

@almarklein
Copy link
Collaborator Author

if I add a new image it will appear on top of the existing ones?

Exactly. And yet the top image will still be below the points, lines, and axes.

If I add a like and then scatter points, these points will appear on top of the line?

Yes. But here it's a bit more tricky, since (assuming the data is 2D) they are both at z=0, and depth-fighting may be a thing.

There are a few reasons why depth-fighting should be unlikely:

  • The depth range for ortho projection is usually favorable, so we have plenty of precision in the depth buffer.
  • The use of depth_compare = '<=' avoids depth-fighting for two objects at exactly the same depth.

For reference, other measures we can take for depth fighting:

  • Use the invariant keyword for the position in the vertex shader (in PyGfx), which reduces differences due to float roundoff errors as a cause for depth-fighting.
  • Use depth offset, e.g. assign an increasing depth offset to the graphics, in the order they were added.

Usually the scene is 3D if the camera.fov > 50

Usually ... but it's perfectly sensible for sciency 3D data to be rendered using orthographic projection. Whether pan-zoom is used (and looking down z) would be a more appropriate signal. In any case, I really like the idea to create the scene in a way that works for both 2D and 3D cases, so users can switch and all keeps making sense. I think we can make that work.

Btw there was this related ideas before: #839

In the comment in #839 I still assumed the scene was always 2d :)

@github-actions
Copy link

github-actions bot commented Oct 2, 2025

📚 Docs preview built and uploaded! https://www.fastplotlib.org/ver/z-order

@almarklein
Copy link
Collaborator Author

So the release tests are know to fail - we need a new release of PyGfx.

But the other tests keep failing with:

image

I had a look at the diffs, and it looks like cases where previously the data was over the axes, and now it's under 👌

I tried to update the reference images by downloading them from the screenshots action, and replacing them. I am a little confused about the "screenshots-" vs "screenshots-imgui" artifacts, which both seem to contain the same screenshots?

I think I tried both, but to no avail...

@kushalkolar
Copy link
Member

Lines, points, and axes use depth_campare="<=" so that for objects at the same depth, the render order determines which one is on top.

Can you explain this a bit? I also made a issue on pygfx to understand depth_compare better so maybe I'll wait for that.

Copy link
Member

@kushalkolar kushalkolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice, few comments 😄

@almarklein
Copy link
Collaborator Author

Lines, points, and axes use depth_campare="<=" so that for objects at the same depth, the render order determines which one is on top.

Can you explain this a bit? I also made a issue on pygfx to understand depth_compare better so maybe I'll wait for that.

See pygfx/pygfx#1213 (comment)

@kushalkolar kushalkolar merged commit e5a818a into main Oct 10, 2025
4 of 52 checks passed
@kushalkolar kushalkolar deleted the z-order branch October 10, 2025 23:31
@kushalkolar kushalkolar mentioned this pull request Oct 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure axes are on top with orthographic projections Dynamically place axes on camera near clipping plane

3 participants