@@ -7,7 +7,7 @@ use bevy_ecs::{
7
7
system:: { Commands , Query , Res , ResMut , Resource } ,
8
8
world:: { FromWorld , World } ,
9
9
} ;
10
- use bevy_math:: UVec2 ;
10
+ use bevy_math:: { UVec2 , UVec4 , Vec4 } ;
11
11
use bevy_reflect:: { Reflect , TypeUuid } ;
12
12
use bevy_render:: {
13
13
camera:: ExtractedCamera ,
@@ -152,18 +152,27 @@ impl ExtractComponent for BloomSettings {
152
152
return None ;
153
153
}
154
154
155
- camera. physical_viewport_size ( ) . map ( |size| {
155
+ if let ( Some ( ( origin, _) ) , Some ( size) , Some ( target_size) ) = (
156
+ camera. physical_viewport_rect ( ) ,
157
+ camera. physical_viewport_size ( ) ,
158
+ camera. physical_target_size ( ) ,
159
+ ) {
156
160
let min_view = size. x . min ( size. y ) / 2 ;
157
161
let mip_count = calculate_mip_count ( min_view) ;
158
162
let scale = ( min_view / 2u32 . pow ( mip_count) ) as f32 / 8.0 ;
159
163
160
- BloomUniform {
164
+ Some ( BloomUniform {
161
165
threshold : settings. threshold ,
162
166
knee : settings. knee ,
163
167
scale : settings. scale * scale,
164
168
intensity : settings. intensity ,
165
- }
166
- } )
169
+ viewport : UVec4 :: new ( origin. x , origin. y , size. x , size. y ) . as_vec4 ( )
170
+ / UVec4 :: new ( target_size. x , target_size. y , target_size. x , target_size. y )
171
+ . as_vec4 ( ) ,
172
+ } )
173
+ } else {
174
+ None
175
+ }
167
176
}
168
177
}
169
178
@@ -246,9 +255,6 @@ impl Node for BloomNode {
246
255
& bind_groups. prefilter_bind_group ,
247
256
& [ uniform_index. index ( ) ] ,
248
257
) ;
249
- if let Some ( viewport) = camera. viewport . as_ref ( ) {
250
- prefilter_pass. set_camera_viewport ( viewport) ;
251
- }
252
258
prefilter_pass. draw ( 0 ..3 , 0 ..1 ) ;
253
259
}
254
260
@@ -270,9 +276,6 @@ impl Node for BloomNode {
270
276
& bind_groups. downsampling_bind_groups [ mip as usize - 1 ] ,
271
277
& [ uniform_index. index ( ) ] ,
272
278
) ;
273
- if let Some ( viewport) = camera. viewport . as_ref ( ) {
274
- downsampling_pass. set_camera_viewport ( viewport) ;
275
- }
276
279
downsampling_pass. draw ( 0 ..3 , 0 ..1 ) ;
277
280
}
278
281
@@ -294,9 +297,6 @@ impl Node for BloomNode {
294
297
& bind_groups. upsampling_bind_groups [ mip as usize - 1 ] ,
295
298
& [ uniform_index. index ( ) ] ,
296
299
) ;
297
- if let Some ( viewport) = camera. viewport . as_ref ( ) {
298
- upsampling_pass. set_camera_viewport ( viewport) ;
299
- }
300
300
upsampling_pass. draw ( 0 ..3 , 0 ..1 ) ;
301
301
}
302
302
@@ -612,6 +612,7 @@ pub struct BloomUniform {
612
612
knee : f32 ,
613
613
scale : f32 ,
614
614
intensity : f32 ,
615
+ viewport : Vec4 ,
615
616
}
616
617
617
618
#[ derive( Component ) ]
0 commit comments