Skip to content

Commit 2512479

Browse files
committed
Revert "extract node 3d to core pipeline"
This reverts commit ef546ce.
1 parent 645a2a6 commit 2512479

File tree

6 files changed

+93
-127
lines changed

6 files changed

+93
-127
lines changed

crates/bevy_core_pipeline/src/core_3d/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub mod graph {
1212
pub const BLOOM: &str = "bloom";
1313
pub const TONEMAPPING: &str = "tonemapping";
1414
pub const FXAA: &str = "fxaa";
15-
pub const GIZMO: &str = "gizmo";
1615
pub const UPSCALING: &str = "upscaling";
1716
pub const END_MAIN_PASS_POST_PROCESSING: &str = "end_main_pass_post_processing";
1817
}

crates/bevy_core_pipeline/src/gizmo_3d/mod.rs

Lines changed: 0 additions & 109 deletions
This file was deleted.

crates/bevy_core_pipeline/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ pub mod core_3d;
55
pub mod fullscreen_vertex_shader;
66
pub mod fxaa;
77
pub mod gizmo_2d;
8-
pub mod gizmo_3d;
98
pub mod prepass;
109
pub mod tonemapping;
1110
pub mod upscaling;

crates/bevy_gizmos/src/lib.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::mem;
33
use bevy_app::{CoreSet, IntoSystemAppConfig, Plugin};
44
use bevy_asset::{load_internal_asset, Assets, Handle, HandleUntyped};
55
use bevy_core_pipeline::{
6+
core_3d,
67
gizmo_2d::{Gizmo2dPlugin, GizmoLine2d},
7-
gizmo_3d::{Gizmo3dPlugin, GizmoLine3d},
88
};
99
use bevy_ecs::{
1010
prelude::{Component, DetectChanges},
@@ -16,7 +16,8 @@ use bevy_math::Mat4;
1616
use bevy_reflect::TypeUuid;
1717
use bevy_render::{
1818
mesh::Mesh,
19-
render_phase::AddRenderCommand,
19+
render_graph::RenderGraph,
20+
render_phase::{sort_phase_system, AddRenderCommand, DrawFunctions},
2021
render_resource::{PrimitiveTopology, Shader, SpecializedMeshPipelines},
2122
Extract, ExtractSchedule, RenderApp, RenderSet,
2223
};
@@ -28,12 +29,14 @@ use bevy_sprite::{Mesh2dHandle, Mesh2dUniform};
2829

2930
pub mod gizmos;
3031

32+
mod node_3d;
33+
3134
#[cfg(feature = "bevy_sprite")]
3235
mod pipeline_2d;
3336
#[cfg(feature = "bevy_pbr")]
3437
mod pipeline_3d;
3538

36-
use crate::gizmos::GizmoStorage;
39+
use crate::{gizmos::GizmoStorage, node_3d::GizmoNode3d};
3740

3841
/// The `bevy_gizmos` prelude.
3942
pub mod prelude {
@@ -58,9 +61,6 @@ impl Plugin for GizmoPlugin {
5861
#[cfg(feature = "bevy_sprite")]
5962
app.add_plugin(Gizmo2dPlugin);
6063

61-
#[cfg(feature = "bevy_pbr")]
62-
app.add_plugin(Gizmo3dPlugin);
63-
6464
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return; };
6565

6666
render_app.add_system(extract_gizmo_data.in_schedule(ExtractSchedule));
@@ -83,8 +83,28 @@ impl Plugin for GizmoPlugin {
8383
render_app
8484
.init_resource::<GizmoPipeline3d>()
8585
.init_resource::<SpecializedMeshPipelines<GizmoPipeline3d>>()
86+
.init_resource::<DrawFunctions<GizmoLine3d>>()
8687
.add_render_command::<GizmoLine3d, DrawGizmoLines>()
88+
.add_system(sort_phase_system::<GizmoLine3d>)
89+
.add_system_to_schedule(ExtractSchedule, extract_gizmo_line_3d_camera_phase)
8790
.add_system(queue_gizmos_3d.in_set(RenderSet::Queue));
91+
92+
let gizmo_node = GizmoNode3d::new(&mut render_app.world);
93+
let mut binding = render_app.world.resource_mut::<RenderGraph>();
94+
let graph = binding.get_sub_graph_mut(core_3d::graph::NAME).unwrap();
95+
96+
graph.add_node(GizmoNode3d::NAME, gizmo_node);
97+
graph.add_slot_edge(
98+
graph.input_node().id,
99+
core_3d::graph::input::VIEW_ENTITY,
100+
GizmoNode3d::NAME,
101+
GizmoNode3d::IN_VIEW,
102+
);
103+
graph.add_node_edge(
104+
core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING,
105+
GizmoNode3d::NAME,
106+
);
107+
graph.add_node_edge(GizmoNode3d::NAME, core_3d::graph::node::UPSCALING);
88108
}
89109
}
90110
}

crates/bevy_core_pipeline/src/gizmo_3d/node.rs renamed to crates/bevy_gizmos/src/node_3d.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use bevy_core_pipeline::core_3d::Camera3dDepthLoadOp;
12
use bevy_ecs::prelude::*;
23
use bevy_render::{
34
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
@@ -6,14 +7,10 @@ use bevy_render::{
67
renderer::RenderContext,
78
view::{ExtractedView, ViewDepthTexture, ViewTarget},
89
};
9-
#[cfg(feature = "trace")]
10-
use bevy_utils::tracing::info_span;
1110

12-
use crate::core_3d::Camera3dDepthLoadOp;
11+
use crate::pipeline_3d::GizmoLine3d;
1312

14-
use super::GizmoLine3d;
15-
16-
pub struct Gizmo3dNode {
13+
pub struct GizmoNode3d {
1714
view_query: QueryState<
1815
(
1916
&'static ViewTarget,
@@ -24,8 +21,9 @@ pub struct Gizmo3dNode {
2421
>,
2522
}
2623

27-
impl Gizmo3dNode {
24+
impl GizmoNode3d {
2825
pub const IN_VIEW: &'static str = "view";
26+
pub const NAME: &'static str = "gizmo_node_2d";
2927

3028
pub fn new(world: &mut World) -> Self {
3129
Self {
@@ -34,7 +32,7 @@ impl Gizmo3dNode {
3432
}
3533
}
3634

37-
impl Node for Gizmo3dNode {
35+
impl Node for GizmoNode3d {
3836
fn input(&self) -> Vec<SlotInfo> {
3937
vec![SlotInfo::new(Self::IN_VIEW, SlotType::Entity)]
4038
}

crates/bevy_gizmos/src/pipeline_3d.rs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
use std::cmp::Reverse;
2+
13
use bevy_asset::Handle;
2-
use bevy_core_pipeline::gizmo_3d::GizmoLine3d;
4+
use bevy_core_pipeline::prelude::Camera3d;
35
use bevy_ecs::{
46
entity::Entity,
57
query::With,
6-
system::{Query, Res, ResMut, Resource},
8+
system::{Commands, Query, Res, ResMut, Resource},
79
world::{FromWorld, World},
810
};
911
use bevy_pbr::*;
1012
use bevy_render::{
1113
mesh::Mesh,
14+
prelude::Camera,
15+
render_phase::{CachedRenderPipelinePhaseItem, DrawFunctionId, PhaseItem},
1216
render_resource::Shader,
1317
view::{ExtractedView, ViewTarget},
18+
Extract,
1419
};
1520
use bevy_render::{
1621
mesh::MeshVertexBufferLayout,
@@ -20,6 +25,7 @@ use bevy_render::{
2025
texture::BevyDefault,
2126
view::Msaa,
2227
};
28+
use bevy_utils::FloatOrd;
2329

2430
use crate::{GizmoConfig, GizmoMesh, LINE_SHADER_HANDLE};
2531

@@ -125,6 +131,59 @@ pub(crate) type DrawGizmoLines = (
125131
DrawMesh,
126132
);
127133

134+
pub struct GizmoLine3d {
135+
pub distance: f32,
136+
pub pipeline: CachedRenderPipelineId,
137+
pub entity: Entity,
138+
pub draw_function: DrawFunctionId,
139+
}
140+
141+
impl PhaseItem for GizmoLine3d {
142+
// NOTE: Values increase towards the camera. Front-to-back ordering for opaque means we need a descending sort.
143+
type SortKey = Reverse<FloatOrd>;
144+
145+
#[inline]
146+
fn entity(&self) -> Entity {
147+
self.entity
148+
}
149+
150+
#[inline]
151+
fn sort_key(&self) -> Self::SortKey {
152+
Reverse(FloatOrd(self.distance))
153+
}
154+
155+
#[inline]
156+
fn draw_function(&self) -> DrawFunctionId {
157+
self.draw_function
158+
}
159+
160+
#[inline]
161+
fn sort(items: &mut [Self]) {
162+
// Key negated to match reversed SortKey ordering
163+
radsort::sort_by_key(items, |item| -item.distance);
164+
}
165+
}
166+
167+
impl CachedRenderPipelinePhaseItem for GizmoLine3d {
168+
#[inline]
169+
fn cached_pipeline(&self) -> CachedRenderPipelineId {
170+
self.pipeline
171+
}
172+
}
173+
174+
pub fn extract_gizmo_line_3d_camera_phase(
175+
mut commands: Commands,
176+
cameras_3d: Extract<Query<(Entity, &Camera), With<Camera3d>>>,
177+
) {
178+
for (entity, camera) in &cameras_3d {
179+
if camera.is_active {
180+
commands
181+
.get_or_spawn(entity)
182+
.insert(RenderPhase::<GizmoLine3d>::default());
183+
}
184+
}
185+
}
186+
128187
#[allow(clippy::too_many_arguments)]
129188
pub(crate) fn queue_gizmos_3d(
130189
draw_functions: Res<DrawFunctions<GizmoLine3d>>,

0 commit comments

Comments
 (0)