Skip to content

Add optional transparency passthrough for sprite backend with bevy_picking #16388

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

Merged

Conversation

vandie
Copy link
Contributor

@vandie vandie commented Nov 14, 2024

Objective

Solution

Testing

  • Ran Sprite Picking example to check it was working both with transparency enabled and disabled
  • ModPicking version is currently in use in my own isometric game where this has been an extremely noticeable issue

Showcase

Sprite Picking Text

Migration Guide

Sprite picking now ignores transparent regions (with an alpha value less than or equal to 0.1). To configure this, modify the SpriteBackendSettings resource.

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

Copy link
Contributor

@mgi388 mgi388 left a comment

Choose a reason for hiding this comment

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

I’m excited for this change. I did a quick visual code review but haven’t tested it yet.

/// Off by default for backwards compatibility. This setting is provided to give you fine-grained
/// control over if transparency on sprites is ignored.
pub passthrough_transparency: bool,
/// How Opaque does part of a sprite need to be in order count as none-transparent (defaults to 10)
Copy link
Contributor

@mgi388 mgi388 Nov 14, 2024

Choose a reason for hiding this comment

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

Can you elaborate in the docs what the units are? 10 what? What is a valid range I could use, as a user?

Copy link
Member

Choose a reason for hiding this comment

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

Can these two options be combined into a single enum? It doesn't make sense to have an alpha cutoff setting when alpha passthrough is disabled. e.g.

SpritePickingAlphaTest {
    /// Don't test alpha, only consider the rect of sprites.
    Ignore,
    /// Test the pixel alpha when running hit tests. Alpha values below this will not be considered for picking.
    Threshold(u8)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah an enum is probably a better idea for those settings. Will rework to include.

@mgi388
Copy link
Contributor

mgi388 commented Nov 14, 2024

@vandie also see #14929 I think your PR fixes it.

@vandie
Copy link
Contributor Author

vandie commented Nov 14, 2024

@vandie also see #14929 I think your PR fixes it.

I think it does yeah.

@mgi388
Copy link
Contributor

mgi388 commented Nov 14, 2024

@vandie also see #14929 I think your PR fixes it.

I think it does yeah.

You can put “Fixes #{id}” in your PR description so merging this PR closes the issue as fixed. 😌

@kristoff3r kristoff3r added S-Needs-Review Needs reviewer attention (from anyone!) to move forward A-Picking Pointing at and selecting objects of all sorts D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Nov 14, 2024
@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Nov 14, 2024
@alice-i-cecile alice-i-cecile added the M-Needs-Release-Note Work that should be called out in the blog due to impact label Nov 14, 2024
@vandie
Copy link
Contributor Author

vandie commented Nov 17, 2024

Seems everyone agrees that this should be enabled by default so I've updated that and introduced a new SpriteBackendAlphaPassthrough enum so this can be controlled by a single setting rather than multiple.

@alice-i-cecile alice-i-cecile added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Nov 17, 2024
Copy link
Contributor

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

@alice-i-cecile
Copy link
Member

Can you add a small migration guide explaining that this is now on by default? Definitely the better default, but could break existing users.

@vandie
Copy link
Contributor Author

vandie commented Nov 17, 2024

Can you add a small migration guide explaining that this is now on by default? Definitely the better default, but could break existing users.

Added. Hope that's ok and clear?

@alice-i-cecile
Copy link
Member

The migration guide was clear and effective, but the tone / target audience was a bit weird. The goal is to communicate "why is my stuff broken and how do I fix it", but your initial draft was closer to a change log :) I've quickly edited the PR description incorporating the information you've added. These get automatically scraped / compiled, so it's good to clean them up here.

@andriyDev
Copy link
Contributor

andriyDev commented Nov 23, 2024

@vandie When you have time, could you take a look at vandie#2 ? I tested it and it looks like it solves a lot of issues! (just wanna make sure it doesn't get lost)

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 3, 2024
pull bot pushed a commit to kinglew/bevy that referenced this pull request Dec 3, 2024
…cking (bevyengine#16388)

# Objective

- Allow bevy_sprite_picking backend to pass through transparent sections
of the sprite.
- Fixes bevyengine#14929

## Solution

- After sprite picking detects the cursor is within a sprites rect,
check the pixel at that location on the texture and check that it meets
an optional transparency cutoff. Change originally created for
mod_picking on bevy 0.14
(aevyrie/bevy_mod_picking#373)

## Testing

- Ran Sprite Picking example to check it was working both with
transparency enabled and disabled
- ModPicking version is currently in use in my own isometric game where
this has been an extremely noticeable issue

## Showcase

![Sprite Picking
Text](https://github.com/user-attachments/assets/76568c0d-c359-422b-942d-17c84d3d3009)

## Migration Guide

Sprite picking now ignores transparent regions (with an alpha value less
than or equal to 0.1). To configure this, modify the
`SpriteBackendSettings` resource.

---------

Co-authored-by: andriyDev <[email protected]>
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 5, 2024
Merged via the queue into bevyengine:main with commit 4be7530 Dec 5, 2024
28 checks passed
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
…cking (bevyengine#16388)

# Objective

- Allow bevy_sprite_picking backend to pass through transparent sections
of the sprite.
- Fixes bevyengine#14929

## Solution

- After sprite picking detects the cursor is within a sprites rect,
check the pixel at that location on the texture and check that it meets
an optional transparency cutoff. Change originally created for
mod_picking on bevy 0.14
(aevyrie/bevy_mod_picking#373)

## Testing

- Ran Sprite Picking example to check it was working both with
transparency enabled and disabled
- ModPicking version is currently in use in my own isometric game where
this has been an extremely noticeable issue

## Showcase

![Sprite Picking
Text](https://github.com/user-attachments/assets/76568c0d-c359-422b-942d-17c84d3d3009)

## Migration Guide

Sprite picking now ignores transparent regions (with an alpha value less
than or equal to 0.1). To configure this, modify the
`SpriteBackendSettings` resource.

---------

Co-authored-by: andriyDev <[email protected]>
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
…cking (bevyengine#16388)

# Objective

- Allow bevy_sprite_picking backend to pass through transparent sections
of the sprite.
- Fixes bevyengine#14929

## Solution

- After sprite picking detects the cursor is within a sprites rect,
check the pixel at that location on the texture and check that it meets
an optional transparency cutoff. Change originally created for
mod_picking on bevy 0.14
(aevyrie/bevy_mod_picking#373)

## Testing

- Ran Sprite Picking example to check it was working both with
transparency enabled and disabled
- ModPicking version is currently in use in my own isometric game where
this has been an extremely noticeable issue

## Showcase

![Sprite Picking
Text](https://github.com/user-attachments/assets/76568c0d-c359-422b-942d-17c84d3d3009)

## Migration Guide

Sprite picking now ignores transparent regions (with an alpha value less
than or equal to 0.1). To configure this, modify the
`SpriteBackendSettings` resource.

---------

Co-authored-by: andriyDev <[email protected]>
mgi388 pushed a commit to mgi388/bevy that referenced this pull request Feb 24, 2025
…cking (bevyengine#16388)

# Objective

- Allow bevy_sprite_picking backend to pass through transparent sections
of the sprite.
- Fixes bevyengine#14929

## Solution

- After sprite picking detects the cursor is within a sprites rect,
check the pixel at that location on the texture and check that it meets
an optional transparency cutoff. Change originally created for
mod_picking on bevy 0.14
(aevyrie/bevy_mod_picking#373)

## Testing

- Ran Sprite Picking example to check it was working both with
transparency enabled and disabled
- ModPicking version is currently in use in my own isometric game where
this has been an extremely noticeable issue

## Showcase

![Sprite Picking
Text](https://github.com/user-attachments/assets/76568c0d-c359-422b-942d-17c84d3d3009)

## Migration Guide

Sprite picking now ignores transparent regions (with an alpha value less
than or equal to 0.1). To configure this, modify the
`SpriteBackendSettings` resource.

---------

Co-authored-by: andriyDev <[email protected]>
@alice-i-cecile
Copy link
Member

Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1961 if you'd like to help out.

@alice-i-cecile
Copy link
Member

Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1966 if you'd like to help out.

github-merge-queue bot pushed a commit that referenced this pull request May 5, 2025
# Objective

- Docs in sprite picking plugin / example contain outdated information.

References:
- Sprite picking now always require `Picking` - #17842
- Transparency pass-through added - #16388

## Solution

- Fix the docs.
andrewzhurov pushed a commit to andrewzhurov/bevy that referenced this pull request May 17, 2025
# Objective

- Docs in sprite picking plugin / example contain outdated information.

References:
- Sprite picking now always require `Picking` - bevyengine#17842
- Transparency pass-through added - bevyengine#16388

## Solution

- Fix the docs.
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 D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide M-Needs-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for alpha-testing in sprite picking backend
9 participants