-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
822 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// This shader shows how to enable the gpu picking feature for a material | ||
|
||
// You'll need the mesh binding because that's where the entity index is | ||
#import bevy_pbr::mesh_bindings | ||
|
||
@group(1) @binding(0) | ||
var<uniform> color: vec4<f32>; | ||
|
||
// Gpu picking uses multiple fragment output | ||
struct FragmentOutput { | ||
@location(0) color: vec4<f32>, | ||
// You can detect the feature with this flag | ||
#ifdef GPU_PICKING | ||
@location(1) entity: vec2<u32>, | ||
#endif | ||
}; | ||
|
||
@fragment | ||
fn fragment( | ||
#import bevy_pbr::mesh_vertex_output | ||
) -> FragmentOutput { | ||
var out: FragmentOutput; | ||
out.color = color; | ||
// make sure to output the entity index for gpu picking to work correctly | ||
#ifdef GPU_PICKING | ||
out.entity = mesh.entity; | ||
#endif | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
crates/bevy_core_pipeline/src/entity_index_buffer_copy/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use bevy_app::Plugin; | ||
use bevy_ecs::{query::QueryItem, world::World}; | ||
use bevy_render::{ | ||
picking::{EntityTextures, ExtractedGpuPickingCamera}, | ||
render_graph::{RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, | ||
renderer::RenderContext, | ||
RenderApp, | ||
}; | ||
|
||
use crate::core_3d::CORE_3D; | ||
|
||
#[derive(Default)] | ||
pub struct EntityIndexBufferCopyNode; | ||
impl ViewNode for EntityIndexBufferCopyNode { | ||
type ViewQuery = (&'static EntityTextures, &'static ExtractedGpuPickingCamera); | ||
|
||
fn run( | ||
&self, | ||
_graph: &mut RenderGraphContext, | ||
render_context: &mut RenderContext, | ||
(entity_index_textures, gpu_picking_camera): QueryItem<Self::ViewQuery>, | ||
_world: &World, | ||
) -> Result<(), bevy_render::render_graph::NodeRunError> { | ||
let Some(buffers) = gpu_picking_camera.buffers.as_ref() else { | ||
return Ok(()); | ||
}; | ||
|
||
buffers.copy_texture_to_buffer( | ||
render_context.command_encoder(), | ||
&entity_index_textures.main.texture, | ||
); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
pub struct EntityIndexBufferCopyPlugin; | ||
impl Plugin for EntityIndexBufferCopyPlugin { | ||
fn build(&self, app: &mut bevy_app::App) { | ||
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; | ||
|
||
// 3D | ||
use crate::core_3d::graph::node::*; | ||
render_app | ||
.add_render_graph_node::<ViewNodeRunner<EntityIndexBufferCopyNode>>( | ||
CORE_3D, | ||
ENTITY_INDEX_BUFFER_COPY, | ||
) | ||
.add_render_graph_edge(CORE_3D, UPSCALING, ENTITY_INDEX_BUFFER_COPY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ keywords = ["bevy"] | |
|
||
[features] | ||
webgl = [] | ||
gpu_picking = [] | ||
|
||
[dependencies] | ||
# bevy | ||
|
Oops, something went wrong.