Skip to content

Add optional alpha-threshold passthrough to the UI picking backend - #25077

Open
mgi388 wants to merge 16 commits into
bevyengine:mainfrom
mgi388:issue-17448
Open

Add optional alpha-threshold passthrough to the UI picking backend#25077
mgi388 wants to merge 16 commits into
bevyengine:mainfrom
mgi388:issue-17448

Conversation

@mgi388

@mgi388 mgi388 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Objective

Solution

Testing

  • Added a new example, similar to the sprite_picking example:
cargo run --example ui_image_picking --features ui_picking

Showcase

Screen.Recording.2026-07-20.at.10.35.18.pm.mov

@mgi388 mgi388 added C-Feature A new feature, making something new possible A-UI Graphical user interfaces, styles, layouts, and widgets D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged A-Picking Pointing at and selecting objects of all sorts labels Jul 20, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in UI Jul 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

@mgi388 mgi388 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 Jul 21, 2026
@mgi388
mgi388 marked this pull request as ready for review July 21, 2026 04:47
@mgi388 mgi388 added this to the 0.20 milestone Jul 21, 2026
@vandie

vandie commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Probably should have done this back when we did the non-ui version. Sorry that's on me for not thinking 😂 Nice one!

@vandie vandie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice Job!

@mgi388

mgi388 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Probably should have done this back when we did the non-ui version. Sorry that's on me for not thinking 😂 Nice one!

Not at all! You deserve the credit here and paved the way for this so thank you!

Comment thread _release-content/migration-guides/ui_picking_alpha_threshold.md
Comment thread _release-content/migration-guides/ui_picking_alpha_threshold.md Outdated
Comment thread crates/bevy_ui/src/picking_backend.rs
Comment thread crates/bevy_ui/src/picking_backend.rs
// bottom right.
let relative_cursor_position =
node.transform.inverse().transform_point2(*cursor_position)
/ node.node.size();

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.

Is this right with respect to borders and padding? I would like some tests to verify: it's easy for this to get confused.

// A backing panel that fills the node's rectangle, so the
// transparent parts of the image are visible against it.
ImageNode { image: "branding/bevy_bird_dark.png" }
BackgroundColor(Color::srgb(0.15, 0.15, 0.15))

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.

We should account for the effects of the BackgroundColor as well, right? Can you add a test to make sure that works?


let Ok(color) = image.get_color_at(texture_position.x as u32, texture_position.y as u32) else {
// We don't know how to interpret the pixel.
return false;

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.

We should at least warn! here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe this will be too spammy if we log anything here but I'll double check when I resolve the other feedback.

Comment thread crates/bevy_ui/src/picking_backend.rs
}

#[cfg(test)]
mod tests {

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.

These tests need more coverage of the node -> correct UV path.

/// `0..1` with `(0, 0)` at the top left) has an alpha value greater than
/// `cutoff`.
///
/// Nodes whose image can't be sampled are treated as hits. This includes nodes

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.

The semantics feel weird here. Should we be returning something other than a bool?

@alice-i-cecile alice-i-cecile left a comment

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.

More cleanup to do, and a couple of possible bugs <3 More tests please!

@alice-i-cecile alice-i-cecile added X-Uncontroversial This work is generally agreed upon S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 28, 2026
@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 Aug 14, 2026
@mgi388

mgi388 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@alice-i-cecile I'm still working on resolving the rest of your comments, so I'm reverting the label change if that's OK :)

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

Labels

A-Picking Pointing at and selecting objects of all sorts A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes 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

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Add optional alpha / transparency passthrough for UI picking backend

3 participants