-
-
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.
Co-authored-by: Kaylee Simmons <[email protected]> Co-authored-by: Nicola Papale <[email protected]>
- Loading branch information
Showing
15 changed files
with
931 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,28 @@ | ||
// 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 mesh | ||
#import bevy_pbr::mesh_vertex_output MeshVertexOutput | ||
|
||
@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) mesh_id: u32, | ||
#endif | ||
}; | ||
|
||
@fragment | ||
fn fragment(in: MeshVertexOutput) -> FragmentOutput { | ||
var out: FragmentOutput; | ||
out.color = color; | ||
// make sure to output the entity index for gpu picking to work correctly | ||
#ifdef GPU_PICKING | ||
out.mesh_id = mesh[in.instance_index].id; | ||
#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
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
use bevy_app::Plugin; | ||
use bevy_ecs::{query::QueryItem, world::World}; | ||
use bevy_render::{ | ||
picking::{CurrentGpuPickingBufferIndex, ExtractedGpuPickingCamera, VisibleMeshIdTextures}, | ||
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 VisibleMeshIdTextures, | ||
&'static ExtractedGpuPickingCamera, | ||
); | ||
|
||
fn run( | ||
&self, | ||
_graph: &mut RenderGraphContext, | ||
render_context: &mut RenderContext, | ||
(mesh_id_textures, gpu_picking_camera): QueryItem<Self::ViewQuery>, | ||
world: &World, | ||
) -> Result<(), bevy_render::render_graph::NodeRunError> { | ||
let current_buffer_index = world.resource::<CurrentGpuPickingBufferIndex>(); | ||
gpu_picking_camera.run_node( | ||
render_context.command_encoder(), | ||
&mesh_id_textures.main.texture, | ||
current_buffer_index, | ||
); | ||
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
Oops, something went wrong.