Fix panic with multiple fog volumes (#18119)
# Objective Fixes https://github.com/bevyengine/bevy/issues/17590. ## Solution `prepare_volumetric_fog_uniforms` adds a uniform for each combination of fog volume and view. But it only allocated enough uniforms for one fog volume per view. ## Testing Ran the `volumetric_fog` example with 1/2/3/4 fog volumes. Also checked the `fog_volumes` and `scrolling_fog` examples (without multiple volumes). Win10/Vulkan/Nvidia. To test multiple views I tried adding fog volumes to the `split_screen` example. This doesn't quite work - the fog should be centred on the fox, but instead it's centred on the window. Same result with and without the PR, so I'm assuming it's a separate bug. 
This commit is contained in:
parent
bfdd018d21
commit
f42ecc44f8
@ -694,20 +694,20 @@ pub fn prepare_volumetric_fog_uniforms(
|
|||||||
render_queue: Res<RenderQueue>,
|
render_queue: Res<RenderQueue>,
|
||||||
mut local_from_world_matrices: Local<Vec<Mat4>>,
|
mut local_from_world_matrices: Local<Vec<Mat4>>,
|
||||||
) {
|
) {
|
||||||
let Some(mut writer) = volumetric_lighting_uniform_buffer.get_writer(
|
|
||||||
view_targets.iter().len(),
|
|
||||||
&render_device,
|
|
||||||
&render_queue,
|
|
||||||
) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Do this up front to avoid O(n^2) matrix inversion.
|
// Do this up front to avoid O(n^2) matrix inversion.
|
||||||
local_from_world_matrices.clear();
|
local_from_world_matrices.clear();
|
||||||
for (_, _, fog_transform) in fog_volumes.iter() {
|
for (_, _, fog_transform) in fog_volumes.iter() {
|
||||||
local_from_world_matrices.push(fog_transform.compute_matrix().inverse());
|
local_from_world_matrices.push(fog_transform.compute_matrix().inverse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let uniform_count = view_targets.iter().len() * local_from_world_matrices.len();
|
||||||
|
|
||||||
|
let Some(mut writer) =
|
||||||
|
volumetric_lighting_uniform_buffer.get_writer(uniform_count, &render_device, &render_queue)
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
for (view_entity, extracted_view, volumetric_fog) in view_targets.iter() {
|
for (view_entity, extracted_view, volumetric_fog) in view_targets.iter() {
|
||||||
let world_from_view = extracted_view.world_from_view.compute_matrix();
|
let world_from_view = extracted_view.world_from_view.compute_matrix();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user