-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AlphaMode Blend - Z ordering errors #11608
Comments
This issue is also present in billboard crate for text. It happens whenever 2 or more transparent meshes are on top of each other. Just transparent background and billboard text mesh is enough to break things. I thought that stacking transparent images is edge-case, but it turned out that it is also triggered by 3D non-transparent text, which I assume also uses blend mode under the hood. This just bumped the issues severity and I now consider it a blocker for Bevy's future world-space UI. |
I cannot reproduce it with the |
There is no way to correctly sort transparent objects correctly in all scenarios when drawing them separately. Bevy sorts transparent objects based on their distance to the camera, which is common practice. From what I can tell this is working correctly in your example, even if the result looks odd. To get the expected behavior, either change the origin of the 3D models used or apply a depth bias in the material to force the desired sorting, see bevy/crates/bevy_pbr/src/pbr_material.rs Lines 374 to 384 in 71be08a
|
Of course, here it is https://github.com/IDEDARY/Bevycom/tree/bevy-issue-z-ordering
Ok, that seems like it might be able to do something. I will try it later |
It seems the calculated distance is wrong under some camera angles, which results in wrong sorted render order. Correct case:
The correct render order is 1->4->2->5->3->6. Wrong case:
Now the order became 1->2->4->3->5->6. |
@IDEDARY Could you help test the PR in this case? |
Update: The PR mentioned here was closed as it did not solve the issue completely. |
This still exists in 0.13.2: bug-transparency.mp4These are basically just PBR bundles of cuboid meshes with standard materials set from colors, but with @alice-i-cecile do you see any hope for this to get a fix for 0.14? Hoping to avoid waiting for 0.15 for using transparency. EDIT: I also tried @IDEDARY 's repro above but changed to Bevy main branch just to make sure it isn't already fixed, and I see the bug there as well |
The only way to fix this is order-independent transparency. Plain apps blending by ordering draws by their transform origins in view space only works up to a point. If you have intersecting triangles or situations like in the original video then what bevy currently supports out of the box will not be sufficient. |
Agreed on the need for order-independent-transparency. @IceSentry had a really lovely implementation that I'd be happy to see upstreamed by him or someone else. No chance it makes it for 0.14 though. |
Excuse me, is this issue scheduled to be fixed? @alice-i-cecile |
@superdump Note that in the original video/reproducible I posted, there are no intersections. Nomeshes collide with each other, they are just stacked closely next to each other. It should be possible to fix that with order dependent draw calls. |
This issue has now been fixed by @IceSentry with his #14876 Order Independent PR. To enable OIT, just modify your camera like this: (more info in the OIT example) @alice-i-cecile I'm closing this as completed :) |
Bevy version
Version 0.12.1 or Bevy main, latest commit:
e94297f
What you did
I used
AlphaMode:Blend
onStandard Material
slapped ontoQuad
meshbug.mp4
What went wrong
The Z-ordering is most likely breaking under different camera angles. Most likely a math error somewhere in the blending pipeline.
You can see the
semi-transparent texture
blinking in certain moments.The text's alpha is
100%
and black background is75%
.The issue only happens when
AlphaMode
is set toBlend
Additional information
The code for replicating this should be simple. I did not do anything to rendering, but I encountered it while developing UI library. The code is currently private and WIP, but I can provide it early if people are interested to fix this issue.
The text was updated successfully, but these errors were encountered: