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,
|
||||
},
|
||||
renderer::RenderDevice,
|
||||
view::RenderLayers,
|
||||
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
|
||||
};
|
||||
use bevy_transform::components::{GlobalTransform, Transform};
|
||||
|
@ -161,6 +162,10 @@ pub struct GizmoConfig {
|
|||
pub depth_bias: f32,
|
||||
/// Configuration for the [`AabbGizmo`].
|
||||
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 {
|
||||
|
@ -171,6 +176,7 @@ impl Default for GizmoConfig {
|
|||
line_perspective: false,
|
||||
depth_bias: 0.,
|
||||
aabb: Default::default(),
|
||||
render_layers: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
line_gizmo_vertex_buffer_layouts, DrawLineGizmo, LineGizmo, LineGizmoUniformBindgroupLayout,
|
||||
SetLineGizmoBindGroup, LINE_SHADER_HANDLE,
|
||||
line_gizmo_vertex_buffer_layouts, DrawLineGizmo, GizmoConfig, LineGizmo,
|
||||
LineGizmoUniformBindgroupLayout, SetLineGizmoBindGroup, LINE_SHADER_HANDLE,
|
||||
};
|
||||
use bevy_app::{App, Plugin};
|
||||
use bevy_asset::Handle;
|
||||
|
@ -17,7 +17,7 @@ use bevy_render::{
|
|||
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
||||
render_resource::*,
|
||||
texture::BevyDefault,
|
||||
view::{ExtractedView, Msaa, ViewTarget},
|
||||
view::{ExtractedView, Msaa, RenderLayers, ViewTarget},
|
||||
Render, RenderApp, RenderSet,
|
||||
};
|
||||
use bevy_sprite::{Mesh2dPipeline, Mesh2dPipelineKey, SetMesh2dViewBindGroup};
|
||||
|
@ -131,13 +131,22 @@ fn queue_line_gizmos_2d(
|
|||
mut pipelines: ResMut<SpecializedRenderPipelines<LineGizmoPipeline>>,
|
||||
pipeline_cache: Res<PipelineCache>,
|
||||
msaa: Res<Msaa>,
|
||||
config: Res<GizmoConfig>,
|
||||
line_gizmos: Query<(Entity, &Handle<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();
|
||||
|
||||
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())
|
||||
| Mesh2dPipelineKey::from_hdr(view.hdr);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ use bevy_render::{
|
|||
render_phase::{AddRenderCommand, DrawFunctions, RenderPhase, SetItemPipeline},
|
||||
render_resource::*,
|
||||
texture::BevyDefault,
|
||||
view::{ExtractedView, Msaa, ViewTarget},
|
||||
view::{ExtractedView, Msaa, RenderLayers, ViewTarget},
|
||||
Render, RenderApp, RenderSet,
|
||||
};
|
||||
|
||||
|
@ -147,11 +147,20 @@ fn queue_line_gizmos_3d(
|
|||
config: Res<GizmoConfig>,
|
||||
line_gizmos: Query<(Entity, &Handle<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();
|
||||
|
||||
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())
|
||||
| MeshPipelineKey::from_hdr(view.hdr);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
prelude::Image,
|
||||
render_asset::RenderAssets,
|
||||
render_resource::TextureView,
|
||||
view::{ColorGrading, ExtractedView, ExtractedWindows, VisibleEntities},
|
||||
view::{ColorGrading, ExtractedView, ExtractedWindows, RenderLayers, VisibleEntities},
|
||||
Extract,
|
||||
};
|
||||
use bevy_asset::{AssetEvent, Assets, Handle};
|
||||
|
@ -615,6 +615,7 @@ pub fn extract_cameras(
|
|||
&VisibleEntities,
|
||||
Option<&ColorGrading>,
|
||||
Option<&TemporalJitter>,
|
||||
Option<&RenderLayers>,
|
||||
)>,
|
||||
>,
|
||||
primary_window: Extract<Query<Entity, With<PrimaryWindow>>>,
|
||||
|
@ -628,6 +629,7 @@ pub fn extract_cameras(
|
|||
visible_entities,
|
||||
color_grading,
|
||||
temporal_jitter,
|
||||
render_layers,
|
||||
) in query.iter()
|
||||
{
|
||||
let color_grading = *color_grading.unwrap_or(&ColorGrading::default());
|
||||
|
@ -679,6 +681,10 @@ pub fn extract_cameras(
|
|||
if let Some(temporal_jitter) = temporal_jitter {
|
||||
commands.insert(temporal_jitter.clone());
|
||||
}
|
||||
|
||||
if let Some(render_layers) = render_layers {
|
||||
commands.insert(*render_layers);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue