bevyengine / bevyengine/bevy

Render the same object with two totally different rendering pipelines?

Open
#2,443 1 comment 4 reactions 0 assignees View on GitHub
A-Rendering C-Feature
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## 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](https://user-images.githubusercontent.com/18645627/125053321-ee94f380-e0df-11eb-8cc2-1393c535ed7f.png)

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 https://github.com/bevyengine/bevy/issues/22

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.