aevyrie / bevy_mod_picking

Picking and pointer events for Bevy.
https://crates.io/crates/bevy_mod_picking
Apache License 2.0
810 stars 176 forks source link

Color Picking Shader #3

Open aevyrie opened 4 years ago

aevyrie commented 4 years ago

For performance, I'd like to render the scene to an off-screen buffer that renders each pixel as an entity encoded into RGBA. Picking is then as simple(😆) as querying this buffer and doing a lookup to return the entity. This would only allow picking for the topmost item (no pick list), and would have limitations with transparency.

A hybrid mode that uses both might be a good solution.

Some input from others on Discord for reference: https://discord.com/channels/691052431525675048/743663924229963868/755912884885913751

aevyrie commented 3 years ago

For reference, here's an article that describes how a picking shader works: https://webglfundamentals.org/webgl/lessons/webgl-picking.html

Here's another good reference that shows how Our Machinery addressed picking through alpha masked objects as well: https://ourmachinery.com/post/borderland-part-2-picking/

arjo129 commented 1 year ago

We have been developing an application that uses an older version of bevy_mod_picking here. We recently ran into the need to have a color picking shader which I've prototyped in this branch. I am open to refactoring it and submitting a new backend (we do eventually need to migrate our app).

aevyrie commented 1 year ago

There is an open PR to add a picking shader to bevy, probably landing next release, 0.12. The plan is to make a backend to support this.