@@ -4,15 +4,15 @@ mod upsampling_pipeline;
44
55pub use settings:: { BloomCompositeMode , BloomPrefilterSettings , BloomSettings } ;
66
7- use crate :: { core_2d, core_3d} ;
7+ use crate :: { add_node , core_2d, core_3d} ;
88use bevy_app:: { App , Plugin } ;
99use bevy_asset:: { load_internal_asset, HandleUntyped } ;
1010use bevy_ecs:: {
1111 prelude:: { Component , Entity } ,
1212 query:: { QueryState , With } ,
1313 schedule:: IntoSystemConfig ,
1414 system:: { Commands , Query , Res , ResMut } ,
15- world:: World ,
15+ world:: { FromWorld , World } ,
1616} ;
1717use bevy_math:: UVec2 ;
1818use bevy_reflect:: TypeUuid ;
@@ -22,7 +22,7 @@ use bevy_render::{
2222 ComponentUniforms , DynamicUniformIndex , ExtractComponentPlugin , UniformComponentPlugin ,
2323 } ,
2424 prelude:: Color ,
25- render_graph:: { Node , NodeRunError , RenderGraph , RenderGraphContext , SlotInfo , SlotType } ,
25+ render_graph:: { Node , NodeRunError , RenderGraphContext , SlotInfo , SlotType } ,
2626 render_resource:: * ,
2727 renderer:: { RenderContext , RenderDevice } ,
2828 texture:: { CachedTexture , TextureCache } ,
@@ -79,54 +79,32 @@ impl Plugin for BloomPlugin {
7979 ) ) ;
8080
8181 // Add bloom to the 3d render graph
82- {
83- let bloom_node = BloomNode :: new ( & mut render_app. world ) ;
84- let mut graph = render_app. world . resource_mut :: < RenderGraph > ( ) ;
85- let draw_3d_graph = graph
86- . get_sub_graph_mut ( crate :: core_3d:: graph:: NAME )
87- . unwrap ( ) ;
88- draw_3d_graph. add_node ( core_3d:: graph:: node:: BLOOM , bloom_node) ;
89- draw_3d_graph. add_slot_edge (
90- draw_3d_graph. input_node ( ) . id ,
91- crate :: core_3d:: graph:: input:: VIEW_ENTITY ,
92- core_3d:: graph:: node:: BLOOM ,
93- BloomNode :: IN_VIEW ,
94- ) ;
95- // MAIN_PASS -> BLOOM -> TONEMAPPING
96- draw_3d_graph. add_node_edge (
97- crate :: core_3d:: graph:: node:: MAIN_PASS ,
98- core_3d:: graph:: node:: BLOOM ,
99- ) ;
100- draw_3d_graph. add_node_edge (
82+ add_node :: < BloomNode > (
83+ render_app,
84+ core_3d:: graph:: NAME ,
85+ core_3d:: graph:: node:: BLOOM ,
86+ core_3d:: graph:: input:: VIEW_ENTITY ,
87+ BloomNode :: IN_VIEW ,
88+ & [
89+ core_3d:: graph:: node:: MAIN_PASS ,
10190 core_3d:: graph:: node:: BLOOM ,
102- crate :: core_3d:: graph:: node:: TONEMAPPING ,
103- ) ;
104- }
91+ core_3d:: graph:: node:: TONEMAPPING ,
92+ ] ,
93+ ) ;
10594
10695 // Add bloom to the 2d render graph
107- {
108- let bloom_node = BloomNode :: new ( & mut render_app. world ) ;
109- let mut graph = render_app. world . resource_mut :: < RenderGraph > ( ) ;
110- let draw_2d_graph = graph
111- . get_sub_graph_mut ( crate :: core_2d:: graph:: NAME )
112- . unwrap ( ) ;
113- draw_2d_graph. add_node ( core_2d:: graph:: node:: BLOOM , bloom_node) ;
114- draw_2d_graph. add_slot_edge (
115- draw_2d_graph. input_node ( ) . id ,
116- crate :: core_2d:: graph:: input:: VIEW_ENTITY ,
96+ add_node :: < BloomNode > (
97+ render_app,
98+ core_2d:: graph:: NAME ,
99+ core_2d:: graph:: node:: BLOOM ,
100+ core_2d:: graph:: input:: VIEW_ENTITY ,
101+ BloomNode :: IN_VIEW ,
102+ & [
103+ core_2d:: graph:: node:: MAIN_PASS ,
117104 core_2d:: graph:: node:: BLOOM ,
118- BloomNode :: IN_VIEW ,
119- ) ;
120- // MAIN_PASS -> BLOOM -> TONEMAPPING
121- draw_2d_graph. add_node_edge (
122- crate :: core_2d:: graph:: node:: MAIN_PASS ,
123- core_2d:: graph:: node:: BLOOM ,
124- ) ;
125- draw_2d_graph. add_node_edge (
126- core_2d:: graph:: node:: BLOOM ,
127- crate :: core_2d:: graph:: node:: TONEMAPPING ,
128- ) ;
129- }
105+ core_2d:: graph:: node:: TONEMAPPING ,
106+ ] ,
107+ ) ;
130108 }
131109}
132110
@@ -145,8 +123,10 @@ pub struct BloomNode {
145123
146124impl BloomNode {
147125 pub const IN_VIEW : & ' static str = "view" ;
126+ }
148127
149- pub fn new ( world : & mut World ) -> Self {
128+ impl FromWorld for BloomNode {
129+ fn from_world ( world : & mut World ) -> Self {
150130 Self {
151131 view_query : QueryState :: new ( world) ,
152132 }
0 commit comments