@@ -2,9 +2,7 @@ use std::num::NonZeroU32;
2
2
3
3
use bevy_app:: { App , Plugin } ;
4
4
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;
8
6
use bevy_ecs:: {
9
7
prelude:: { Component , Entity } ,
10
8
query:: { QueryState , With } ,
@@ -29,7 +27,14 @@ use bevy_utils::HashMap;
29
27
pub mod draw_3d_graph {
30
28
pub mod node {
31
29
/// 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" ;
33
38
}
34
39
}
35
40
@@ -54,39 +59,69 @@ impl Plugin for BloomPlugin {
54
59
. add_system_to_stage ( RenderStage :: Prepare , prepare_bloom_textures)
55
60
. add_system_to_stage ( RenderStage :: Prepare , prepare_bloom_uniforms)
56
61
. 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
+ }
85
120
}
86
121
}
87
122
88
123
// TODO: Write better documentation.
89
- /// Applies a bloom effect to an HDR-enabled Camera3d .
124
+ /// Applies a bloom effect to a HDR-enabled Camera .
90
125
///
91
126
/// See also <https://en.wikipedia.org/wiki/Bloom_(shader_effect)>.
92
127
#[ derive( Component , Clone ) ]
@@ -488,9 +523,9 @@ impl FromWorld for BloomPipelines {
488
523
489
524
fn extract_bloom_settings (
490
525
mut commands : Commands ,
491
- cameras_3d : Extract < Query < ( Entity , & Camera , & BloomSettings ) , With < Camera3d > > > ,
526
+ cameras : Extract < Query < ( Entity , & Camera , & BloomSettings ) , With < Camera > > > ,
492
527
) {
493
- for ( entity, camera, bloom_settings) in & cameras_3d {
528
+ for ( entity, camera, bloom_settings) in & cameras {
494
529
if camera. is_active && camera. hdr {
495
530
commands. get_or_spawn ( entity) . insert ( bloom_settings. clone ( ) ) ;
496
531
}
0 commit comments