@@ -230,106 +230,75 @@ impl Node for BloomNode {
230
230
} ) ;
231
231
232
232
let view = & bloom_texture. view ( 0 ) ;
233
- let mut downsampling_first_pass =
234
- render_context. begin_tracked_render_pass ( RenderPassDescriptor {
235
- label : Some ( "bloom_downsampling_first_pass" ) ,
236
- color_attachments : & [ Some ( RenderPassColorAttachment {
237
- view,
238
- resolve_target : None ,
239
- ops : Operations :: default ( ) ,
240
- } ) ] ,
241
- depth_stencil_attachment : None ,
242
- } ) ;
243
- downsampling_first_pass. set_render_pipeline ( downsampling_first_pipeline) ;
244
- downsampling_first_pass. set_bind_group (
245
- 0 ,
246
- & downsampling_first_bind_group,
247
- & [ uniform_index. index ( ) ] ,
248
- ) ;
249
- downsampling_first_pass. draw ( 0 ..3 , 0 ..1 ) ;
233
+
234
+ render_context
235
+ . render_pass ( view_entity)
236
+ . set_label ( "bloom_downsampling_first_pass" )
237
+ . add_color_attachment ( view)
238
+ . begin ( )
239
+ . set_pipeline ( downsampling_first_pipeline)
240
+ . set_bind_group ( 0 , & downsampling_first_bind_group, & [ uniform_index. index ( ) ] )
241
+ . draw ( 0 ..3 , 0 ..1 ) ;
250
242
}
251
243
252
244
// Other downsample passes
253
245
for mip in 1 ..bloom_texture. mip_count {
246
+ let down_sampling_bind_group = & bind_groups. downsampling_bind_groups [ mip as usize - 1 ] ;
254
247
let view = & bloom_texture. view ( mip) ;
255
- let mut downsampling_pass =
256
- render_context. begin_tracked_render_pass ( RenderPassDescriptor {
257
- label : Some ( "bloom_downsampling_pass" ) ,
258
- color_attachments : & [ Some ( RenderPassColorAttachment {
259
- view,
260
- resolve_target : None ,
261
- ops : Operations :: default ( ) ,
262
- } ) ] ,
263
- depth_stencil_attachment : None ,
264
- } ) ;
265
- downsampling_pass. set_render_pipeline ( downsampling_pipeline) ;
266
- downsampling_pass. set_bind_group (
267
- 0 ,
268
- & bind_groups. downsampling_bind_groups [ mip as usize - 1 ] ,
269
- & [ uniform_index. index ( ) ] ,
270
- ) ;
271
- downsampling_pass. draw ( 0 ..3 , 0 ..1 ) ;
248
+
249
+ render_context
250
+ . render_pass ( view_entity)
251
+ . set_label ( "bloom_downsampling_pass" )
252
+ . add_color_attachment ( view)
253
+ . begin ( )
254
+ . set_pipeline ( downsampling_pipeline)
255
+ . set_bind_group ( 0 , down_sampling_bind_group, & [ uniform_index. index ( ) ] )
256
+ . draw ( 0 ..3 , 0 ..1 ) ;
272
257
}
273
258
274
259
// Upsample passes except the final one
275
260
for mip in ( 1 ..bloom_texture. mip_count ) . rev ( ) {
276
- let view = & bloom_texture. view ( mip - 1 ) ;
277
- let mut upsampling_pass =
278
- render_context. begin_tracked_render_pass ( RenderPassDescriptor {
279
- label : Some ( "bloom_upsampling_pass" ) ,
280
- color_attachments : & [ Some ( RenderPassColorAttachment {
281
- view,
282
- resolve_target : None ,
283
- ops : Operations {
284
- load : LoadOp :: Load ,
285
- store : true ,
286
- } ,
287
- } ) ] ,
288
- depth_stencil_attachment : None ,
289
- } ) ;
290
- upsampling_pass. set_render_pipeline ( upsampling_pipeline) ;
291
- upsampling_pass. set_bind_group (
292
- 0 ,
293
- & bind_groups. upsampling_bind_groups [ ( bloom_texture. mip_count - mip - 1 ) as usize ] ,
294
- & [ uniform_index. index ( ) ] ,
295
- ) ;
296
261
let blend = compute_blend_factor (
297
262
bloom_settings,
298
263
mip as f32 ,
299
264
( bloom_texture. mip_count - 1 ) as f32 ,
300
265
) ;
301
- upsampling_pass. set_blend_constant ( Color :: rgb_linear ( blend, blend, blend) ) ;
302
- upsampling_pass. draw ( 0 ..3 , 0 ..1 ) ;
266
+ let upsampling_bind_group =
267
+ & bind_groups. upsampling_bind_groups [ ( bloom_texture. mip_count - mip - 1 ) as usize ] ;
268
+ let view = & bloom_texture. view ( mip - 1 ) ;
269
+
270
+ render_context
271
+ . render_pass ( view_entity)
272
+ . set_label ( "bloom_upsampling_pass" )
273
+ . add_color_attachment ( view)
274
+ . set_color_ops ( LoadOp :: Load , true )
275
+ . begin ( )
276
+ . set_pipeline ( upsampling_pipeline)
277
+ . set_bind_group ( 0 , upsampling_bind_group, & [ uniform_index. index ( ) ] )
278
+ . set_blend_constant ( Color :: rgb_linear ( blend, blend, blend) )
279
+ . draw ( 0 ..3 , 0 ..1 ) ;
303
280
}
304
281
305
282
// Final upsample pass
306
283
// This is very similar to the above upsampling passes with the only difference
307
284
// being the pipeline (which itself is barely different) and the color attachment
308
285
{
309
- let mut upsampling_final_pass =
310
- render_context. begin_tracked_render_pass ( RenderPassDescriptor {
311
- label : Some ( "bloom_upsampling_final_pass" ) ,
312
- color_attachments : & [ Some ( view_target. get_unsampled_color_attachment (
313
- Operations {
314
- load : LoadOp :: Load ,
315
- store : true ,
316
- } ,
317
- ) ) ] ,
318
- depth_stencil_attachment : None ,
319
- } ) ;
320
- upsampling_final_pass. set_render_pipeline ( upsampling_final_pipeline) ;
321
- upsampling_final_pass. set_bind_group (
322
- 0 ,
323
- & bind_groups. upsampling_bind_groups [ ( bloom_texture. mip_count - 1 ) as usize ] ,
324
- & [ uniform_index. index ( ) ] ,
325
- ) ;
326
- if let Some ( viewport) = camera. viewport . as_ref ( ) {
327
- upsampling_final_pass. set_camera_viewport ( viewport) ;
328
- }
329
286
let blend =
330
287
compute_blend_factor ( bloom_settings, 0.0 , ( bloom_texture. mip_count - 1 ) as f32 ) ;
331
- upsampling_final_pass. set_blend_constant ( Color :: rgb_linear ( blend, blend, blend) ) ;
332
- upsampling_final_pass. draw ( 0 ..3 , 0 ..1 ) ;
288
+ let upsample_final_bind_group =
289
+ & bind_groups. upsampling_bind_groups [ ( bloom_texture. mip_count - 1 ) as usize ] ;
290
+
291
+ render_context
292
+ . render_pass ( view_entity)
293
+ . set_label ( "bloom_upsampling_final_pass" )
294
+ . add_view_target_unsampled ( view_target)
295
+ . set_color_ops ( LoadOp :: Load , true )
296
+ . begin ( )
297
+ . set_camera_viewport ( camera)
298
+ . set_pipeline ( upsampling_final_pipeline)
299
+ . set_bind_group ( 0 , upsample_final_bind_group, & [ uniform_index. index ( ) ] )
300
+ . set_blend_constant ( Color :: rgb_linear ( blend, blend, blend) )
301
+ . draw ( 0 ..3 , 0 ..1 ) ;
333
302
}
334
303
335
304
render_context. command_encoder ( ) . pop_debug_group ( ) ;
0 commit comments