Skip to content

Commit 5da64dd

Browse files
authored
Fix motion blur on skinned meshes (#18712)
## Objective Fix motion blur not working on skinned meshes. ## Solution `set_mesh_motion_vector_flags` can set `RenderMeshInstanceFlags::HAS_PREVIOUS_SKIN` after specialization has already cached the material. This can lead to `MeshPipelineKey::HAS_PREVIOUS_SKIN` never getting set, disabling motion blur. The fix is to make sure `set_mesh_motion_vector_flags` happens before specialization. Note that the bug is fixed in a different way by #18074, which includes other fixes but is a much larger change. ## Testing Open the `animated_mesh` example and add these components to the `Camera3d` entity: ```rust MotionBlur { shutter_angle: 5.0, samples: 2, #[cfg(all(feature = "webgl2", target_arch = "wasm32", not(feature = "webgpu")))] _webgl2_padding: Default::default(), }, #[cfg(all(feature = "webgl2", target_arch = "wasm32", not(feature = "webgpu")))] Msaa::Off, ``` Tested on `animated_mesh`, `many_foxes`, `custom_skinned_mesh`, Win10/Nvidia with Vulkan, WebGL/Chrome, WebGPU/Chrome. Note that testing `many_foxes` WebGL requires #18715.
1 parent 78d5c50 commit 5da64dd

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

crates/bevy_pbr/src/material.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ where
327327
.in_set(RenderSet::PrepareMeshes)
328328
.after(prepare_assets::<PreparedMaterial<M>>)
329329
.after(prepare_assets::<RenderMesh>)
330-
.after(collect_meshes_for_gpu_building),
330+
.after(collect_meshes_for_gpu_building)
331+
.after(set_mesh_motion_vector_flags),
331332
queue_material_meshes::<M>
332333
.in_set(RenderSet::QueueMeshes)
333334
.after(prepare_assets::<PreparedMaterial<M>>),

crates/bevy_pbr/src/prepass/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ mod prepass_bindings;
33
use crate::{
44
alpha_mode_pipeline_key, binding_arrays_are_usable, buffer_layout,
55
collect_meshes_for_gpu_building, material_bind_groups::MaterialBindGroupAllocator,
6-
queue_material_meshes, setup_morph_and_skinning_defs, skin, DrawMesh,
7-
EntitySpecializationTicks, Material, MaterialPipeline, MaterialPipelineKey, MeshLayouts,
8-
MeshPipeline, MeshPipelineKey, OpaqueRendererMethod, PreparedMaterial, RenderLightmaps,
9-
RenderMaterialInstances, RenderMeshInstanceFlags, RenderMeshInstances, RenderPhaseType,
10-
SetMaterialBindGroup, SetMeshBindGroup, ShadowView, StandardMaterial,
6+
queue_material_meshes, set_mesh_motion_vector_flags, setup_morph_and_skinning_defs, skin,
7+
DrawMesh, EntitySpecializationTicks, Material, MaterialPipeline, MaterialPipelineKey,
8+
MeshLayouts, MeshPipeline, MeshPipelineKey, OpaqueRendererMethod, PreparedMaterial,
9+
RenderLightmaps, RenderMaterialInstances, RenderMeshInstanceFlags, RenderMeshInstances,
10+
RenderPhaseType, SetMaterialBindGroup, SetMeshBindGroup, ShadowView, StandardMaterial,
1111
};
1212
use bevy_app::{App, Plugin, PreUpdate};
1313
use bevy_render::{
@@ -219,7 +219,8 @@ where
219219
.in_set(RenderSet::PrepareMeshes)
220220
.after(prepare_assets::<PreparedMaterial<M>>)
221221
.after(prepare_assets::<RenderMesh>)
222-
.after(collect_meshes_for_gpu_building),
222+
.after(collect_meshes_for_gpu_building)
223+
.after(set_mesh_motion_vector_flags),
223224
queue_prepass_material_meshes::<M>
224225
.in_set(RenderSet::QueueMeshes)
225226
.after(prepare_assets::<PreparedMaterial<M>>)

crates/bevy_pbr/src/render/mesh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ fn extract_mesh_for_gpu_building(
16481648
/// [`crate::material::queue_material_meshes`] check the skin and morph target
16491649
/// tables for each mesh, but that would be too slow in the hot mesh queuing
16501650
/// loop.
1651-
fn set_mesh_motion_vector_flags(
1651+
pub(crate) fn set_mesh_motion_vector_flags(
16521652
mut render_mesh_instances: ResMut<RenderMeshInstances>,
16531653
skin_uniforms: Res<SkinUniforms>,
16541654
morph_indices: Res<MorphIndices>,

0 commit comments

Comments
 (0)