Skip to content

Re-sort retained transparent phase items when their entity moves - #25708

Open
karasikq wants to merge 6 commits into
bevyengine:mainfrom
karasikq:fix/refresh-retained-sort-keys
Open

Re-sort retained transparent phase items when their entity moves#25708
karasikq wants to merge 6 commits into
bevyengine:mainfrom
karasikq:fix/refresh-retained-sort-keys

Conversation

@karasikq

@karasikq karasikq commented Sep 7, 2026

Copy link
Copy Markdown

Objective

Solution

  • Add a DirtySortKeys render-world resource, filled in ExtractSchedule from entities with a changed GlobalTransform and cleared in RenderSystems::Cleanup.

Testing

NOTE: added tests test only position invalidation, if DirtySortKeys has another invalidation key then tests must be extended too. Also I introduced an Update system in the testbed, which is a precedent and I'm not sure the testbed is the right place for such a case.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

@karasikq
karasikq force-pushed the fix/refresh-retained-sort-keys branch from 84e5a23 to 8054386 Compare September 7, 2026 08:30
**Objective**

- Sorted phases Transparent2d, Transparent3d, Transmissive3d "freeze"
their sort key when an component is queued,
and moving an entity does not re-queue it, so blended meshes and sprites
could draw in the wrong order.

**Solution**

- Add a `DirtySortKeys` render-world resource, filled in
`ExtractSchedule` from entities with a changed `GlobalTransform` and
cleared in `RenderSystems::Cleanup`.

**Tests**

- New `sprite_z_order` example.
- New moving-entity scenes in the 2d and 3d testbeds.
@karasikq
karasikq force-pushed the fix/refresh-retained-sort-keys branch from 8054386 to 035dcf3 Compare September 7, 2026 08:32
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 7, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Sep 7, 2026
@alice-i-cecile

Copy link
Copy Markdown
Member

@Tehforsch can I get your review here? Even just testing is extremely helpful.

Comment thread examples/2d/sprite_z_order.rs Outdated
@@ -0,0 +1,81 @@
//! Shows that a blended sprite that only moves keeps the right draw order.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not a very useful example pedagogically. Can this be converted into a testbed scene?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree with you. I added it for 2 reasons:

  • I saw similar "example" test usage at
    //! This example is used to test how transforms interact with alpha modes for [`Mesh2d`] entities with a [`MeshMaterial2d`].
    //! This makes sure the depth buffer is correctly being used for opaque and transparent 2d meshes
  • I wasn't sure if the "Update" system in the testbed is safe to add, since CI screenshots after 100 frames and the system settles down after a 5. I think it's reasonable to keep sprite_z_order with transparent_sort_position and drop the example.

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Uncontroversial This work is generally agreed upon D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 7, 2026
@Tehforsch

Tehforsch commented Sep 8, 2026

Copy link
Copy Markdown

@Tehforsch can I get your review here? Even just testing is extremely helpful.

I just checked, this fixes the bug for me, both in the minimal example in #24826 and in my game.

@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2D: Changes to Z-ordering of entities with custom materials (not sprites) not reflected properly in rendering

3 participants