diff --git a/crates/bevy_debug_draw/src/debuglines.wgsl b/crates/bevy_debug_draw/src/debuglines.wgsl index 668e5dfad8a0f5..df399957e19a80 100644 --- a/crates/bevy_debug_draw/src/debuglines.wgsl +++ b/crates/bevy_debug_draw/src/debuglines.wgsl @@ -33,7 +33,7 @@ fn vertex(in: VertexInput) -> VertexOutput { fn fragment(in: VertexOutput) -> FragmentOutput { var out: FragmentOutput; -#ifdef DEPTH_TEST_ENABLED +#ifdef DEPTH_TEST out.depth = in.pos.z; #else out.depth = 1.0; diff --git a/crates/bevy_debug_draw/src/lib.rs b/crates/bevy_debug_draw/src/lib.rs index 1cbcb7dc89e09c..23bce0baf689c8 100644 --- a/crates/bevy_debug_draw/src/lib.rs +++ b/crates/bevy_debug_draw/src/lib.rs @@ -45,7 +45,7 @@ impl Plugin for DebugDrawPlugin { app.init_resource::() .init_resource::() - .add_system_to_stage(CoreStage::PostUpdate, update) + .add_system_to_stage(CoreStage::Last, update) .sub_app_mut(RenderApp) .add_system_to_stage(RenderStage::Extract, extract); @@ -82,6 +82,8 @@ pub struct DebugDrawConfig { /// Defaults to `true`. pub enabled: bool, /// Whether debug drawing should ignore depth and draw on top of everything else. + /// + /// This setting only affects 3D. In 2D, debug drawing is always on top. /// /// Defaults to `true`. pub always_on_top: bool, diff --git a/crates/bevy_debug_draw/src/pipeline_2d.rs b/crates/bevy_debug_draw/src/pipeline_2d.rs index 3da36f093e80bc..f3c4ac23337996 100644 --- a/crates/bevy_debug_draw/src/pipeline_2d.rs +++ b/crates/bevy_debug_draw/src/pipeline_2d.rs @@ -16,7 +16,7 @@ use bevy_render::{ use bevy_sprite::*; use bevy_utils::FloatOrd; -use crate::{DebugDrawConfig, DebugDrawMesh, SHADER_HANDLE}; +use crate::{DebugDrawMesh, SHADER_HANDLE}; #[derive(Resource)] pub(crate) struct DebugLinePipeline { @@ -93,14 +93,13 @@ pub(crate) type DrawDebugLines = ( #[allow(clippy::too_many_arguments)] pub(crate) fn queue( - config: Res, draw2d_functions: Res>, debug_line_pipeline: Res, mut pipeline_cache: ResMut, mut specialized_pipelines: ResMut>, render_meshes: Res>, msaa: Res, - material_meshes: Query<(&Mesh2dUniform, &Mesh2dHandle), With>, + material_meshes: Query<&Mesh2dHandle, With>, mut views: Query<(&VisibleEntities, &mut RenderPhase)>, ) { for (view, mut phase) in &mut views { @@ -108,32 +107,26 @@ pub(crate) fn queue( let msaa_key = Mesh2dPipelineKey::from_msaa_samples(msaa.samples); for visible_entity in &view.entities { - if let Ok((uniform, mesh_handle)) = material_meshes.get(*visible_entity) { - if let Some(mesh) = render_meshes.get(&mesh_handle.0) { - let mesh_key = msaa_key - | Mesh2dPipelineKey::from_primitive_topology(PrimitiveTopology::LineList); - let mesh_z = if config.always_on_top { - f32::MAX - } else { - uniform.transform.w_axis.z - }; - let pipeline = specialized_pipelines - .specialize( - &mut pipeline_cache, - &debug_line_pipeline, - mesh_key, - &mesh.layout, - ) - .unwrap(); - phase.add(Transparent2d { - entity: *visible_entity, - draw_function: draw_mesh2d, - pipeline, - sort_key: FloatOrd(mesh_z), - batch_range: None, - }); - } - } + let Ok(mesh_handle) = material_meshes.get(*visible_entity) else { continue; }; + let Some(mesh) = render_meshes.get(&mesh_handle.0) else { continue; }; + + let mesh_key = + msaa_key | Mesh2dPipelineKey::from_primitive_topology(PrimitiveTopology::LineList); + let pipeline = specialized_pipelines + .specialize( + &mut pipeline_cache, + &debug_line_pipeline, + mesh_key, + &mesh.layout, + ) + .unwrap(); + phase.add(Transparent2d { + entity: *visible_entity, + draw_function: draw_mesh2d, + pipeline, + sort_key: FloatOrd(f32::MAX), + batch_range: None, + }); } } } diff --git a/crates/bevy_debug_draw/src/pipeline_3d.rs b/crates/bevy_debug_draw/src/pipeline_3d.rs index 0b4eba26a0baca..25d7bbb21ba3c3 100644 --- a/crates/bevy_debug_draw/src/pipeline_3d.rs +++ b/crates/bevy_debug_draw/src/pipeline_3d.rs @@ -45,7 +45,7 @@ impl SpecializedMeshPipeline for DebugLinePipeline { let mut shader_defs = Vec::new(); shader_defs.push("DEBUG_LINES_3D".to_string()); if depth_test { - shader_defs.push("DEPTH_TEST_ENABLED".to_string()); + shader_defs.push("DEPTH_TEST".to_string()); } let vertex_buffer_layout = layout.get_layout(&[