Skip to content
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

Render the same object with two totally different rendering pipelines? #2443

Open
VRichardJP opened this issue Jul 9, 2021 · 1 comment
Open
Labels
A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible

Comments

@VRichardJP
Copy link

VRichardJP commented Jul 9, 2021

What problem does this solve or what need does it fill?

I am trying to implement an object picking plugin based on this method: https://snoozetime.github.io/2019/05/02/object-picking.html

The concept is rather simple (but tricky to implement):

  1. each object entity id is encoded into a unique RGB color
  2. id colors are sent to a specific pipeline which renders them on a specific texture
  3. after the texture is rendered, the host look at the color at the mouse cursor position
  4. a table lookup is then used to know which object is currently hovered

I have implemented a small PoC of the method, where the object hovered by the mouse is highlighted in pink (the debug window shows id color pass result):
image

I based my rendering pipeline on @rmsc render_to_file example and readout node implementation: https://github.com/rmsc/bevy/blob/render_to_file/crates/bevy_render/src/render_graph/nodes/texture_readout_node.rs

Currently my solution is:

  • I have a specific IdColorPass and IdColorPipeline for my id color rendering
  • for each object I want to interact with, I attach a child with the same mesh, but with my IdColorPass and IdColorPipeline instead of the MainPass and default PBR pipeline. As far as I know it is not possible to have 2 different render pass, with 2 different pipelines to render the same object to 2 different textures from the same object.

It is quite hacky, but it works.
However it is kinda slow when I start to have a lot of objects (2 times slower than bevy_mod_picking with the same scene). After some testing/tracing, I suspect it is partly because I am duplicating all my meshes. I have no idea how I could simply have the same object go through 2 totally different rendering pipelines (is it possible?)

What solution would you like?

To be able to have the same object go through 2 totally different rendering pipelines.

For example, to be able to create from a scene:

  • a window with the PBR rendering,
  • another window with wireframe only,
  • another window with objects deformed by a custom shader
  • etc

(If it is already possible, I think it could be a great example!)

What alternative(s) have you considered?

I have looked at render_to_texture, wireframe and multiple_windows examples, but I think none of them demonstrate how it would be possible to achieve that.

Additional context

Related to #22

@VRichardJP VRichardJP added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Jul 9, 2021
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Jul 10, 2021
@ghost
Copy link

ghost commented Mar 20, 2023

@VRichardJP Can you please share the code for color id pass. I am implementing a plugin and I will like to know how it works. Thanks 🙏

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-Feature A new feature, making something new possible
Projects
None yet
Development

No branches or pull requests

2 participants