mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Add option to disable gizmo rendering for specific cameras (#8952)
Added `GizmoConfig::render_layers`, which will ensure Gizmos are only rendered on cameras that can see those `RenderLayers`. --------- Co-authored-by: Carter Anderson <mcanders1@gmail.com>
This commit is contained in:
parent
418d3273fd
commit
e29981dcbd
4 changed files with 39 additions and 9 deletions
|
@ -50,6 +50,7 @@ use bevy_render::{
|
||||||
VertexFormat, VertexStepMode,
|
VertexFormat, VertexStepMode,
|
||||||
},
|
},
|
||||||
renderer::RenderDevice,
|
renderer::RenderDevice,
|
||||||
|
view::RenderLayers,
|
||||||
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
|
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
|
||||||
};
|
};
|
||||||
use bevy_transform::components::{GlobalTransform, Transform};
|
use bevy_transform::components::{GlobalTransform, Transform};
|
||||||
|
@ -161,6 +162,10 @@ pub struct GizmoConfig {
|
||||||
pub depth_bias: f32,
|
pub depth_bias: f32,
|
||||||
/// Configuration for the [`AabbGizmo`].
|
/// Configuration for the [`AabbGizmo`].
|
||||||
pub aabb: AabbGizmoConfig,
|
pub aabb: AabbGizmoConfig,
|
||||||
|
/// Describes which rendering layers gizmos will be rendered to.
|
||||||
|
///
|
||||||
|
/// Gizmos will only be rendered to cameras with intersecting layers.
|
||||||
|
pub render_layers: RenderLayers,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GizmoConfig {
|
impl Default for GizmoConfig {
|
||||||
|
@ -171,6 +176,7 @@ impl Default for GizmoConfig {
|
||||||
line_perspective: false,
|
line_perspective: false,
|
||||||
depth_bias: 0.,
|
depth_bias: 0.,
|
||||||
aabb: Default::default(),
|
aabb: Default::default(),
|
||||||
|
render_layers: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
line_gizmo_vertex_buffer_layouts, DrawLineGizmo, LineGizmo, LineGizmoUniformBindgroupLayout,
|
line_gizmo_vertex_buffer_layouts, DrawLineGizmo, GizmoConfig, LineGizmo,
|
||||||
SetLineGizmoBindGroup, LINE_SHADER_HANDLE,
|
LineGizmoUniformBindgroupLayout, SetLineGizmoBindGroup, LINE_SHADER_HANDLE,
|
||||||
};
|
};
|
||||||
use bevy_app::{App, Plugin};
|
use bevy_app::{App, Plugin};
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
|
@ -17,7 +17,7 @@ use bevy_render::{
|
||||||
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
||||||
render_resource::*,
|
render_resource::*,
|
||||||
texture::BevyDefault,
|
texture::BevyDefault,
|
||||||
view::{ExtractedView, Msaa, ViewTarget},
|
view::{ExtractedView, Msaa, RenderLayers, ViewTarget},
|
||||||
Render, RenderApp, RenderSet,
|
Render, RenderApp, RenderSet,
|
||||||
};
|
};
|
||||||
use bevy_sprite::{Mesh2dPipeline, Mesh2dPipelineKey, SetMesh2dViewBindGroup};
|
use bevy_sprite::{Mesh2dPipeline, Mesh2dPipelineKey, SetMesh2dViewBindGroup};
|
||||||
|
@ -131,13 +131,22 @@ fn queue_line_gizmos_2d(
|
||||||
mut pipelines: ResMut<SpecializedRenderPipelines<LineGizmoPipeline>>,
|
mut pipelines: ResMut<SpecializedRenderPipelines<LineGizmoPipeline>>,
|
||||||
pipeline_cache: Res<PipelineCache>,
|
pipeline_cache: Res<PipelineCache>,
|
||||||
msaa: Res<Msaa>,
|
msaa: Res<Msaa>,
|
||||||
|
config: Res<GizmoConfig>,
|
||||||
line_gizmos: Query<(Entity, &Handle<LineGizmo>)>,
|
line_gizmos: Query<(Entity, &Handle<LineGizmo>)>,
|
||||||
line_gizmo_assets: Res<RenderAssets<LineGizmo>>,
|
line_gizmo_assets: Res<RenderAssets<LineGizmo>>,
|
||||||
mut views: Query<(&ExtractedView, &mut RenderPhase<Transparent2d>)>,
|
mut views: Query<(
|
||||||
|
&ExtractedView,
|
||||||
|
&mut RenderPhase<Transparent2d>,
|
||||||
|
Option<&RenderLayers>,
|
||||||
|
)>,
|
||||||
) {
|
) {
|
||||||
let draw_function = draw_functions.read().get_id::<DrawLineGizmo2d>().unwrap();
|
let draw_function = draw_functions.read().get_id::<DrawLineGizmo2d>().unwrap();
|
||||||
|
|
||||||
for (view, mut transparent_phase) in &mut views {
|
for (view, mut transparent_phase, render_layers) in &mut views {
|
||||||
|
let render_layers = render_layers.copied().unwrap_or_default();
|
||||||
|
if !config.render_layers.intersects(&render_layers) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let mesh_key = Mesh2dPipelineKey::from_msaa_samples(msaa.samples())
|
let mesh_key = Mesh2dPipelineKey::from_msaa_samples(msaa.samples())
|
||||||
| Mesh2dPipelineKey::from_hdr(view.hdr);
|
| Mesh2dPipelineKey::from_hdr(view.hdr);
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ use bevy_render::{
|
||||||
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
||||||
render_resource::*,
|
render_resource::*,
|
||||||
texture::BevyDefault,
|
texture::BevyDefault,
|
||||||
view::{ExtractedView, Msaa, ViewTarget},
|
view::{ExtractedView, Msaa, RenderLayers, ViewTarget},
|
||||||
Render, RenderApp, RenderSet,
|
Render, RenderApp, RenderSet,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -147,11 +147,20 @@ fn queue_line_gizmos_3d(
|
||||||
config: Res<GizmoConfig>,
|
config: Res<GizmoConfig>,
|
||||||
line_gizmos: Query<(Entity, &Handle<LineGizmo>)>,
|
line_gizmos: Query<(Entity, &Handle<LineGizmo>)>,
|
||||||
line_gizmo_assets: Res<RenderAssets<LineGizmo>>,
|
line_gizmo_assets: Res<RenderAssets<LineGizmo>>,
|
||||||
mut views: Query<(&ExtractedView, &mut RenderPhase<Transparent3d>)>,
|
mut views: Query<(
|
||||||
|
&ExtractedView,
|
||||||
|
&mut RenderPhase<Transparent3d>,
|
||||||
|
Option<&RenderLayers>,
|
||||||
|
)>,
|
||||||
) {
|
) {
|
||||||
let draw_function = draw_functions.read().get_id::<DrawLineGizmo3d>().unwrap();
|
let draw_function = draw_functions.read().get_id::<DrawLineGizmo3d>().unwrap();
|
||||||
|
|
||||||
for (view, mut transparent_phase) in &mut views {
|
for (view, mut transparent_phase, render_layers) in &mut views {
|
||||||
|
let render_layers = render_layers.copied().unwrap_or_default();
|
||||||
|
if !config.render_layers.intersects(&render_layers) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let mesh_key = MeshPipelineKey::from_msaa_samples(msaa.samples())
|
let mesh_key = MeshPipelineKey::from_msaa_samples(msaa.samples())
|
||||||
| MeshPipelineKey::from_hdr(view.hdr);
|
| MeshPipelineKey::from_hdr(view.hdr);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
prelude::Image,
|
prelude::Image,
|
||||||
render_asset::RenderAssets,
|
render_asset::RenderAssets,
|
||||||
render_resource::TextureView,
|
render_resource::TextureView,
|
||||||
view::{ColorGrading, ExtractedView, ExtractedWindows, VisibleEntities},
|
view::{ColorGrading, ExtractedView, ExtractedWindows, RenderLayers, VisibleEntities},
|
||||||
Extract,
|
Extract,
|
||||||
};
|
};
|
||||||
use bevy_asset::{AssetEvent, Assets, Handle};
|
use bevy_asset::{AssetEvent, Assets, Handle};
|
||||||
|
@ -615,6 +615,7 @@ pub fn extract_cameras(
|
||||||
&VisibleEntities,
|
&VisibleEntities,
|
||||||
Option<&ColorGrading>,
|
Option<&ColorGrading>,
|
||||||
Option<&TemporalJitter>,
|
Option<&TemporalJitter>,
|
||||||
|
Option<&RenderLayers>,
|
||||||
)>,
|
)>,
|
||||||
>,
|
>,
|
||||||
primary_window: Extract<Query<Entity, With<PrimaryWindow>>>,
|
primary_window: Extract<Query<Entity, With<PrimaryWindow>>>,
|
||||||
|
@ -628,6 +629,7 @@ pub fn extract_cameras(
|
||||||
visible_entities,
|
visible_entities,
|
||||||
color_grading,
|
color_grading,
|
||||||
temporal_jitter,
|
temporal_jitter,
|
||||||
|
render_layers,
|
||||||
) in query.iter()
|
) in query.iter()
|
||||||
{
|
{
|
||||||
let color_grading = *color_grading.unwrap_or(&ColorGrading::default());
|
let color_grading = *color_grading.unwrap_or(&ColorGrading::default());
|
||||||
|
@ -679,6 +681,10 @@ pub fn extract_cameras(
|
||||||
if let Some(temporal_jitter) = temporal_jitter {
|
if let Some(temporal_jitter) = temporal_jitter {
|
||||||
commands.insert(temporal_jitter.clone());
|
commands.insert(temporal_jitter.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(render_layers) = render_layers {
|
||||||
|
commands.insert(*render_layers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue