@@ -42,8 +42,10 @@ use bevy_core_pipeline::core_3d::graph::Node3d;
42
42
use bevy_ecs:: {
43
43
component:: Component ,
44
44
query:: { Changed , QueryItem , With } ,
45
- schedule:: IntoScheduleConfigs ,
46
- system:: { lifetimeless:: Read , Query } ,
45
+ resource:: Resource ,
46
+ schedule:: { common_conditions:: resource_exists, IntoScheduleConfigs , SystemSet } ,
47
+ system:: { lifetimeless:: Read , Commands , Query , Res } ,
48
+ world:: World ,
47
49
} ;
48
50
use bevy_math:: { UVec2 , UVec3 , Vec3 } ;
49
51
use bevy_reflect:: { std_traits:: ReflectDefault , Reflect } ;
@@ -52,6 +54,7 @@ use bevy_render::{
52
54
load_shader_library,
53
55
render_resource:: { DownlevelFlags , ShaderType , SpecializedRenderPipelines } ,
54
56
view:: Hdr ,
57
+ RenderStartup ,
55
58
} ;
56
59
use bevy_render:: {
57
60
extract_component:: { ExtractComponent , ExtractComponentPlugin } ,
@@ -68,12 +71,14 @@ use resources::{
68
71
} ;
69
72
use tracing:: warn;
70
73
74
+ use crate :: resources:: {
75
+ init_atmosphere_bind_group_layouts, init_atmosphere_lut_pipelines, init_atmosphere_samplers,
76
+ init_render_sky_bind_group_layouts,
77
+ } ;
78
+
71
79
use self :: {
72
80
node:: { AtmosphereLutsNode , AtmosphereNode , RenderSkyNode } ,
73
- resources:: {
74
- prepare_atmosphere_bind_groups, prepare_atmosphere_textures, AtmosphereBindGroupLayouts ,
75
- AtmosphereLutPipelines , AtmosphereSamplers ,
76
- } ,
81
+ resources:: { prepare_atmosphere_bind_groups, prepare_atmosphere_textures} ,
77
82
} ;
78
83
79
84
#[ doc( hidden) ]
@@ -100,40 +105,39 @@ impl Plugin for AtmospherePlugin {
100
105
UniformComponentPlugin :: < Atmosphere > :: default ( ) ,
101
106
UniformComponentPlugin :: < AtmosphereSettings > :: default ( ) ,
102
107
) ) ;
103
- }
104
108
105
- fn finish ( & self , app : & mut App ) {
106
109
let Some ( render_app) = app. get_sub_app_mut ( RenderApp ) else {
107
110
return ;
108
111
} ;
109
112
110
- let render_adapter = render_app. world ( ) . resource :: < RenderAdapter > ( ) ;
111
-
112
- if !render_adapter
113
- . get_downlevel_capabilities ( )
114
- . flags
115
- . contains ( DownlevelFlags :: COMPUTE_SHADERS )
116
- {
117
- warn ! ( "AtmospherePlugin not loaded. GPU lacks support for compute shaders." ) ;
118
- return ;
119
- }
120
-
121
- if !render_adapter
122
- . get_texture_format_features ( TextureFormat :: Rgba16Float )
123
- . allowed_usages
124
- . contains ( TextureUsages :: STORAGE_BINDING )
125
- {
126
- warn ! ( "AtmospherePlugin not loaded. GPU lacks support: TextureFormat::Rgba16Float does not support TextureUsages::STORAGE_BINDING." ) ;
127
- return ;
128
- }
129
-
130
113
render_app
131
- . init_resource :: < AtmosphereBindGroupLayouts > ( )
132
- . init_resource :: < RenderSkyBindGroupLayouts > ( )
133
- . init_resource :: < AtmosphereSamplers > ( )
134
- . init_resource :: < AtmosphereLutPipelines > ( )
135
114
. init_resource :: < AtmosphereTransforms > ( )
136
115
. init_resource :: < SpecializedRenderPipelines < RenderSkyBindGroupLayouts > > ( )
116
+ . configure_sets (
117
+ RenderStartup ,
118
+ AtmosphereSystems
119
+ . after ( check_atmosphere_supported)
120
+ . run_if ( resource_exists :: < AtmosphereSupported > ) ,
121
+ )
122
+ . configure_sets (
123
+ Render ,
124
+ AtmosphereSystems . run_if ( resource_exists :: < AtmosphereSupported > ) ,
125
+ )
126
+ . add_systems ( RenderStartup , check_atmosphere_supported)
127
+ . add_systems (
128
+ RenderStartup ,
129
+ (
130
+ add_atmosphere_render_graph_nodes,
131
+ init_render_sky_bind_group_layouts,
132
+ init_atmosphere_samplers,
133
+ (
134
+ init_atmosphere_bind_group_layouts,
135
+ init_atmosphere_lut_pipelines,
136
+ )
137
+ . chain ( ) ,
138
+ )
139
+ . in_set ( AtmosphereSystems ) ,
140
+ )
137
141
. add_systems (
138
142
Render ,
139
143
(
@@ -142,36 +146,66 @@ impl Plugin for AtmospherePlugin {
142
146
prepare_atmosphere_textures. in_set ( RenderSystems :: PrepareResources ) ,
143
147
prepare_atmosphere_transforms. in_set ( RenderSystems :: PrepareResources ) ,
144
148
prepare_atmosphere_bind_groups. in_set ( RenderSystems :: PrepareBindGroups ) ,
145
- ) ,
146
- )
147
- . add_render_graph_node :: < ViewNodeRunner < AtmosphereLutsNode > > (
148
- Core3d ,
149
- AtmosphereNode :: RenderLuts ,
150
- )
151
- . add_render_graph_edges (
152
- Core3d ,
153
- (
154
- // END_PRE_PASSES -> RENDER_LUTS -> MAIN_PASS
155
- Node3d :: EndPrepasses ,
156
- AtmosphereNode :: RenderLuts ,
157
- Node3d :: StartMainPass ,
158
- ) ,
159
- )
160
- . add_render_graph_node :: < ViewNodeRunner < RenderSkyNode > > (
161
- Core3d ,
162
- AtmosphereNode :: RenderSky ,
163
- )
164
- . add_render_graph_edges (
165
- Core3d ,
166
- (
167
- Node3d :: MainOpaquePass ,
168
- AtmosphereNode :: RenderSky ,
169
- Node3d :: MainTransparentPass ,
170
- ) ,
149
+ )
150
+ . in_set ( AtmosphereSystems ) ,
171
151
) ;
172
152
}
173
153
}
174
154
155
+ #[ derive( SystemSet , Hash , PartialEq , Eq , Clone , Debug ) ]
156
+ struct AtmosphereSystems ;
157
+
158
+ #[ derive( Resource ) ]
159
+ struct AtmosphereSupported ;
160
+
161
+ fn check_atmosphere_supported ( mut commands : Commands , render_adapter : Res < RenderAdapter > ) {
162
+ if !render_adapter
163
+ . get_downlevel_capabilities ( )
164
+ . flags
165
+ . contains ( DownlevelFlags :: COMPUTE_SHADERS )
166
+ {
167
+ warn ! ( "AtmospherePlugin not loaded. GPU lacks support for compute shaders." ) ;
168
+ return ;
169
+ }
170
+
171
+ if !render_adapter
172
+ . get_texture_format_features ( TextureFormat :: Rgba16Float )
173
+ . allowed_usages
174
+ . contains ( TextureUsages :: STORAGE_BINDING )
175
+ {
176
+ warn ! ( "AtmospherePlugin not loaded. GPU lacks support: TextureFormat::Rgba16Float does not support TextureUsages::STORAGE_BINDING." ) ;
177
+ return ;
178
+ }
179
+
180
+ commands. insert_resource ( AtmosphereSupported ) ;
181
+ }
182
+
183
+ fn add_atmosphere_render_graph_nodes ( world : & mut World ) {
184
+ world
185
+ . add_render_graph_node :: < ViewNodeRunner < AtmosphereLutsNode > > (
186
+ Core3d ,
187
+ AtmosphereNode :: RenderLuts ,
188
+ )
189
+ . add_render_graph_edges (
190
+ Core3d ,
191
+ (
192
+ // END_PRE_PASSES -> RENDER_LUTS -> MAIN_PASS
193
+ Node3d :: EndPrepasses ,
194
+ AtmosphereNode :: RenderLuts ,
195
+ Node3d :: StartMainPass ,
196
+ ) ,
197
+ )
198
+ . add_render_graph_node :: < ViewNodeRunner < RenderSkyNode > > ( Core3d , AtmosphereNode :: RenderSky )
199
+ . add_render_graph_edges (
200
+ Core3d ,
201
+ (
202
+ Node3d :: MainOpaquePass ,
203
+ AtmosphereNode :: RenderSky ,
204
+ Node3d :: MainTransparentPass ,
205
+ ) ,
206
+ ) ;
207
+ }
208
+
175
209
/// This component describes the atmosphere of a planet, and when added to a camera
176
210
/// will enable atmospheric scattering for that camera. This is only compatible with
177
211
/// HDR cameras.
0 commit comments