Skip to content

Commit cea7545

Browse files
authored
Merge pull request #3 from DGriffin91/bloom-node-new
support for camera_2d
2 parents 7792070 + 04346c8 commit cea7545

File tree

1 file changed

+70
-35
lines changed
  • crates/bevy_pbr/src/bloom

1 file changed

+70
-35
lines changed

crates/bevy_pbr/src/bloom/mod.rs

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use std::num::NonZeroU32;
22

33
use bevy_app::{App, Plugin};
44
use bevy_asset::{load_internal_asset, HandleUntyped};
5-
use bevy_core_pipeline::{
6-
fullscreen_vertex_shader::fullscreen_shader_vertex_state, prelude::Camera3d,
7-
};
5+
use bevy_core_pipeline::fullscreen_vertex_shader::fullscreen_shader_vertex_state;
86
use bevy_ecs::{
97
prelude::{Component, Entity},
108
query::{QueryState, With},
@@ -29,7 +27,14 @@ use bevy_utils::HashMap;
2927
pub mod draw_3d_graph {
3028
pub mod node {
3129
/// Label for the bloom render node.
32-
pub const BLOOM: &str = "bloom";
30+
pub const BLOOM: &str = "bloom_3d";
31+
}
32+
}
33+
34+
pub mod draw_2d_graph {
35+
pub mod node {
36+
/// Label for the bloom render node.
37+
pub const BLOOM: &str = "bloom_2d";
3338
}
3439
}
3540

@@ -54,39 +59,69 @@ impl Plugin for BloomPlugin {
5459
.add_system_to_stage(RenderStage::Prepare, prepare_bloom_textures)
5560
.add_system_to_stage(RenderStage::Prepare, prepare_bloom_uniforms)
5661
.add_system_to_stage(RenderStage::Queue, queue_bloom_bind_groups);
57-
58-
let bloom_node = BloomNode::new(&mut render_app.world);
59-
let mut graph = render_app.world.resource_mut::<RenderGraph>();
60-
let draw_3d_graph = graph
61-
.get_sub_graph_mut(bevy_core_pipeline::core_3d::graph::NAME)
62-
.unwrap();
63-
draw_3d_graph.add_node(draw_3d_graph::node::BLOOM, bloom_node);
64-
draw_3d_graph
65-
.add_slot_edge(
66-
draw_3d_graph.input_node().unwrap().id,
67-
bevy_core_pipeline::core_3d::graph::input::VIEW_ENTITY,
68-
draw_3d_graph::node::BLOOM,
69-
BloomNode::IN_VIEW,
70-
)
71-
.unwrap();
72-
// MAIN_PASS -> BLOOM -> TONEMAPPING
73-
draw_3d_graph
74-
.add_node_edge(
75-
bevy_core_pipeline::core_3d::graph::node::MAIN_PASS,
76-
draw_3d_graph::node::BLOOM,
77-
)
78-
.unwrap();
79-
draw_3d_graph
80-
.add_node_edge(
81-
draw_3d_graph::node::BLOOM,
82-
bevy_core_pipeline::core_3d::graph::node::TONEMAPPING,
83-
)
84-
.unwrap();
62+
{
63+
let bloom_node = BloomNode::new(&mut render_app.world);
64+
let mut graph = render_app.world.resource_mut::<RenderGraph>();
65+
let draw_3d_graph = graph
66+
.get_sub_graph_mut(bevy_core_pipeline::core_3d::graph::NAME)
67+
.unwrap();
68+
draw_3d_graph.add_node(draw_3d_graph::node::BLOOM, bloom_node);
69+
draw_3d_graph
70+
.add_slot_edge(
71+
draw_3d_graph.input_node().unwrap().id,
72+
bevy_core_pipeline::core_3d::graph::input::VIEW_ENTITY,
73+
draw_3d_graph::node::BLOOM,
74+
BloomNode::IN_VIEW,
75+
)
76+
.unwrap();
77+
// MAIN_PASS -> BLOOM -> TONEMAPPING
78+
draw_3d_graph
79+
.add_node_edge(
80+
bevy_core_pipeline::core_3d::graph::node::MAIN_PASS,
81+
draw_3d_graph::node::BLOOM,
82+
)
83+
.unwrap();
84+
draw_3d_graph
85+
.add_node_edge(
86+
draw_3d_graph::node::BLOOM,
87+
bevy_core_pipeline::core_3d::graph::node::TONEMAPPING,
88+
)
89+
.unwrap();
90+
}
91+
{
92+
let bloom_node = BloomNode::new(&mut render_app.world);
93+
let mut graph = render_app.world.resource_mut::<RenderGraph>();
94+
let draw_2d_graph = graph
95+
.get_sub_graph_mut(bevy_core_pipeline::core_2d::graph::NAME)
96+
.unwrap();
97+
draw_2d_graph.add_node(draw_2d_graph::node::BLOOM, bloom_node);
98+
draw_2d_graph
99+
.add_slot_edge(
100+
draw_2d_graph.input_node().unwrap().id,
101+
bevy_core_pipeline::core_2d::graph::input::VIEW_ENTITY,
102+
draw_2d_graph::node::BLOOM,
103+
BloomNode::IN_VIEW,
104+
)
105+
.unwrap();
106+
// MAIN_PASS -> BLOOM -> TONEMAPPING
107+
draw_2d_graph
108+
.add_node_edge(
109+
bevy_core_pipeline::core_2d::graph::node::MAIN_PASS,
110+
draw_2d_graph::node::BLOOM,
111+
)
112+
.unwrap();
113+
draw_2d_graph
114+
.add_node_edge(
115+
draw_2d_graph::node::BLOOM,
116+
bevy_core_pipeline::core_2d::graph::node::TONEMAPPING,
117+
)
118+
.unwrap();
119+
}
85120
}
86121
}
87122

88123
// TODO: Write better documentation.
89-
/// Applies a bloom effect to an HDR-enabled Camera3d.
124+
/// Applies a bloom effect to a HDR-enabled Camera.
90125
///
91126
/// See also <https://en.wikipedia.org/wiki/Bloom_(shader_effect)>.
92127
#[derive(Component, Clone)]
@@ -488,9 +523,9 @@ impl FromWorld for BloomPipelines {
488523

489524
fn extract_bloom_settings(
490525
mut commands: Commands,
491-
cameras_3d: Extract<Query<(Entity, &Camera, &BloomSettings), With<Camera3d>>>,
526+
cameras: Extract<Query<(Entity, &Camera, &BloomSettings), With<Camera>>>,
492527
) {
493-
for (entity, camera, bloom_settings) in &cameras_3d {
528+
for (entity, camera, bloom_settings) in &cameras {
494529
if camera.is_active && camera.hdr {
495530
commands.get_or_spawn(entity).insert(bloom_settings.clone());
496531
}

0 commit comments

Comments
 (0)