Skip to content

Commit f198bd6

Browse files
authored
increase morph targets to 256 (#21421)
# Objective our current morph target / blend shape limit is 64 per model, documented as "to support all hardware". many assets use more than this ("over a hundred" is common), so i'd like to increase this limit. the relevant hardware constraint is uniform buffer size (usage in morph.wgsl). morph targets use 4 bytes per entry, and wgpu's downlevel uniform buffer size limit is 16k so we have a lot of room from the 256 bytes we are currently limiting to, while still supporting the vast majority of hardware. ## Solution increase the limit to 256 targets / 1k. we also increase the input to the buffer to this 1k size: this was not done previously but worked as long as the min buffer alignment was 256 (which it probably always is at the moment) as it was sized up to match alignment previously. there may be a slight performance impact from using a larger size in all cases but it should be negligible.
1 parent 176d5a3 commit f198bd6

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

crates/bevy_mesh/src/morph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const MAX_TEXTURE_WIDTH: u32 = 2048;
1414
const MAX_COMPONENTS: u32 = MAX_TEXTURE_WIDTH * MAX_TEXTURE_WIDTH;
1515

1616
/// Max target count available for [morph targets](MorphWeights).
17-
pub const MAX_MORPH_WEIGHTS: usize = 64;
17+
pub const MAX_MORPH_WEIGHTS: usize = 256;
1818

1919
#[derive(Error, Clone, Debug)]
2020
pub enum MorphBuildError {

crates/bevy_pbr/src/render/mesh_types.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct SkinnedMesh {
3434

3535
#ifdef MORPH_TARGETS
3636
struct MorphWeights {
37-
weights: array<vec4<f32>, 16u>, // 16 = 64 / 4 (64 = MAX_MORPH_WEIGHTS)
37+
weights: array<vec4<f32>, 64u>, // 64 = 256 / 4 (256 = MAX_MORPH_WEIGHTS)
3838
};
3939
#endif
4040

crates/bevy_pbr/src/render/morph.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ pub fn extract_morphs(
127127
}
128128
let start = uniform.current_buffer.len();
129129
let weights = morph_weights.weights();
130-
let legal_weights = weights.iter().take(MAX_MORPH_WEIGHTS).copied();
130+
let legal_weights = weights
131+
.iter()
132+
.chain(iter::repeat(&0.0))
133+
.take(MAX_MORPH_WEIGHTS)
134+
.copied();
131135
uniform.current_buffer.extend(legal_weights);
132136
add_to_alignment::<f32>(&mut uniform.current_buffer);
133137

0 commit comments

Comments
 (0)