Skip to content

Commit

Permalink
mvectors -> motion_vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
nicopap committed Oct 2, 2023
1 parent b056e42 commit 6f71fd2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
16 changes: 8 additions & 8 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ pub fn setup_morph_and_skinning_defs(
shader_defs: &mut Vec<ShaderDefVal>,
vertex_attributes: &mut Vec<VertexAttributeDescriptor>,
) -> BindGroupLayout {
let mvectors = key.contains(MeshPipelineKey::MOTION_VECTOR_PREPASS);
let motion_vectors = key.contains(MeshPipelineKey::MOTION_VECTOR_PREPASS);
let morph = key.contains(MeshPipelineKey::MORPH_TARGETS);
let skin = is_skinned(layout);

Expand All @@ -738,7 +738,7 @@ pub fn setup_morph_and_skinning_defs(
if morph {
shader_defs.push("MORPH_TARGETS".into());
}
mesh_layouts.get(morph, skin, mvectors).clone()
mesh_layouts.get(morph, skin, motion_vectors).clone()
}

impl SpecializedMeshPipeline for MeshPipeline {
Expand Down Expand Up @@ -982,7 +982,7 @@ pub fn prepare_mesh_bind_group(
let layouts = &mesh_pipeline.mesh_layouts;
let mut bind_groups = layouts.bind_group_maker(&render_device, model, &mut groups);

// no morph + maybe(skin) * mvectors + no mvectors
// no morph + maybe(skin) * motion_vectors + no motion_vectors
let skin = skins_uniform.buffer.current();
let previous_skin = skins_uniform.buffer.previous();
bind_groups.add(None, None, None, None);
Expand All @@ -1001,7 +1001,7 @@ pub fn prepare_mesh_bind_group(
let Some(targets) = gpu_mesh.morph_targets.as_ref() else {
continue;
};
// morph + maybe(skin) * mvectors + no mvectors
// morph + maybe(skin) * motion_vectors + no motion_vectors
let morph = Some((id, weights, targets));
bind_groups.add(morph, skin, previous_weights, previous_skin);
bind_groups.add(morph, skin, None, previous_skin);
Expand Down Expand Up @@ -1219,7 +1219,7 @@ impl<P: PhaseItem, const I: usize, const PREPASS: bool> RenderCommand<P>
#[inline]
fn render<'w>(
item: &P,
has_mvectors: bool,
has_motion_vectors: bool,
_item_query: (),
(bind_groups, mesh_instances, skin_indices, morph_indices): SystemParamItem<
'w,
Expand All @@ -1243,10 +1243,10 @@ impl<P: PhaseItem, const I: usize, const PREPASS: bool> RenderCommand<P>

let is_skinned = skin_index.is_some();
let is_morphed = morph_index.is_some();
let is_mvectors = PREPASS && has_mvectors;
let is_motion_vectors = PREPASS && has_motion_vectors;
let morph_id = is_morphed.then_some(mesh.mesh_asset_id);

let Some(bind_group) = bind_groups.get(morph_id, is_skinned, is_mvectors) else {
let Some(bind_group) = bind_groups.get(morph_id, is_skinned, is_motion_vectors) else {
error!(
"The MeshBindGroups resource wasn't set in the render phase. \
It should be set by the prepare_mesh_bind_group system.\n\
Expand All @@ -1269,7 +1269,7 @@ impl<P: PhaseItem, const I: usize, const PREPASS: bool> RenderCommand<P>
dynamic_offsets[offset_count] = morph_index.index;
offset_count += 1;
}
if is_mvectors {
if is_motion_vectors {
if let Some(skin_index) = skin_index {
dynamic_offsets[offset_count] = skin_index.index;
offset_count += 1;
Expand Down
102 changes: 51 additions & 51 deletions crates/bevy_pbr/src/render/mesh_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn targets_entry(binding: u32, texture: &TextureView) -> BindGroupEntry {

// --- Layout entry lists & bind group entry lists ---

const MVECTORS_OFFSET: u32 = 3;
const MOTION_VECTORS_OFFSET: u32 = 3;

fn model_layout_entries(device: &RenderDevice) -> [BindGroupLayoutEntry; 1] {
[model_layout(device, 0)]
Expand All @@ -110,18 +110,18 @@ fn skin_entries(skin: &Buffer) -> [BindGroupEntry; 1] {
[skinning_entry(1, skin)]
}

fn mvectors_morph_layout_entries() -> [BindGroupLayoutEntry; 1] {
[weights_layout(2 + MVECTORS_OFFSET)]
fn motion_vectors_morph_layout_entries() -> [BindGroupLayoutEntry; 1] {
[weights_layout(2 + MOTION_VECTORS_OFFSET)]
}
fn mvectors_morph_entries(weights: &Buffer) -> [BindGroupEntry; 1] {
[weights_entry(2 + MVECTORS_OFFSET, weights)]
fn motion_vectors_morph_entries(weights: &Buffer) -> [BindGroupEntry; 1] {
[weights_entry(2 + MOTION_VECTORS_OFFSET, weights)]
}

fn mvectors_skin_layout_entries() -> [BindGroupLayoutEntry; 1] {
[skinning_layout(1 + MVECTORS_OFFSET)]
fn motion_vectors_skin_layout_entries() -> [BindGroupLayoutEntry; 1] {
[skinning_layout(1 + MOTION_VECTORS_OFFSET)]
}
fn mvectors_skin_entries(skin: &Buffer) -> [BindGroupEntry; 1] {
[skinning_entry(1 + MVECTORS_OFFSET, skin)]
fn motion_vectors_skin_entries(skin: &Buffer) -> [BindGroupEntry; 1] {
[skinning_entry(1 + MOTION_VECTORS_OFFSET, skin)]
}

/// All possible [`BindGroupLayout`]s in bevy's default mesh shader (`mesh.wgsl`).
Expand All @@ -131,20 +131,20 @@ pub struct MeshBindings<T> {
pub morphed: T,
pub skinned: T,
pub morphed_skinned: T,
pub morphed_mvectors: T,
pub skinned_mvectors: T,
pub morphed_skinned_mvectors: T,
pub morphed_motion_vectors: T,
pub skinned_motion_vectors: T,
pub morphed_skinned_motion_vectors: T,
}
impl<T> MeshBindings<T> {
fn get_binding(&self, binding: Binding) -> &T {
match (binding.morph, binding.skin, binding.mvectors) {
match (binding.morph, binding.skin, binding.motion_vectors) {
(false, false, _) => &self.model_only,
(true, false, false) => &self.morphed,
(false, true, false) => &self.skinned,
(true, true, false) => &self.morphed_skinned,
(true, false, true) => &self.morphed_mvectors,
(false, true, true) => &self.skinned_mvectors,
(true, true, true) => &self.morphed_skinned_mvectors,
(true, false, true) => &self.morphed_motion_vectors,
(false, true, true) => &self.skinned_motion_vectors,
(true, true, true) => &self.morphed_skinned_motion_vectors,
}
}
}
Expand All @@ -154,8 +154,8 @@ pub struct MeshBindGroups {
pub model_only: Option<BindGroup>,
pub morphed: HashMap<AssetId<Mesh>, BindGroup>,
pub skinned: Option<BindGroup>,
pub morphed_mvectors: HashMap<AssetId<Mesh>, BindGroup>,
pub skinned_mvectors: Option<BindGroup>,
pub morphed_motion_vectors: HashMap<AssetId<Mesh>, BindGroup>,
pub skinned_motion_vectors: Option<BindGroup>,
}

impl MeshBindGroups {
Expand All @@ -166,41 +166,41 @@ impl MeshBindGroups {
&self,
morph_id: Option<AssetId<Mesh>>,
skin: bool,
mvectors: bool,
motion_vectors: bool,
) -> Option<&BindGroup> {
match (morph_id, skin, mvectors) {
(Some(id), _, true) => self.morphed_mvectors.get(&id),
match (morph_id, skin, motion_vectors) {
(Some(id), _, true) => self.morphed_motion_vectors.get(&id),
(Some(id), _, false) => self.morphed.get(&id),
(None, false, _) => self.model_only.as_ref(),
(None, true, true) => self.skinned_mvectors.as_ref(),
(None, true, true) => self.skinned_motion_vectors.as_ref(),
(None, true, false) => self.skinned.as_ref(),
}
}
fn insert(
&mut self,
morph_id: Option<AssetId<Mesh>>,
skin: bool,
mvectors: bool,
motion_vectors: bool,
bind_group: BindGroup,
) {
match (morph_id, skin, mvectors) {
match (morph_id, skin, motion_vectors) {
(Some(id), _, true) => {
self.morphed_mvectors.insert(id, bind_group);
self.morphed_motion_vectors.insert(id, bind_group);
}
(Some(id), _, false) => {
self.morphed.insert(id, bind_group);
}
(None, false, _) => self.model_only = Some(bind_group),
(None, true, true) => self.skinned_mvectors = Some(bind_group),
(None, true, true) => self.skinned_motion_vectors = Some(bind_group),
(None, true, false) => self.skinned = Some(bind_group),
}
}
pub fn clear(&mut self) {
self.model_only = None;
self.morphed.clear();
self.morphed_mvectors.clear();
self.morphed_motion_vectors.clear();
self.skinned = None;
self.skinned_mvectors = None;
self.skinned_motion_vectors = None;
}
}

Expand All @@ -216,13 +216,13 @@ impl MeshLayouts {
morphed: Binding::new(true, false, false).layout(device),
skinned: Binding::new(false, true, false).layout(device),
morphed_skinned: Binding::new(true, true, false).layout(device),
morphed_mvectors: Binding::new(true, false, true).layout(device),
skinned_mvectors: Binding::new(false, true, true).layout(device),
morphed_skinned_mvectors: Binding::new(true, true, true).layout(device),
morphed_motion_vectors: Binding::new(true, false, true).layout(device),
skinned_motion_vectors: Binding::new(false, true, true).layout(device),
morphed_skinned_motion_vectors: Binding::new(true, true, true).layout(device),
}
}
pub fn get(&self, morph: bool, skin: bool, mvectors: bool) -> &BindGroupLayout {
self.get_binding(Binding::new(morph, skin, mvectors))
pub fn get(&self, morph: bool, skin: bool, motion_vectors: bool) -> &BindGroupLayout {
self.get_binding(Binding::new(morph, skin, motion_vectors))
}
/// Clears `bind_groups` and returns a [`MeshBindGroupMaker`], used to add
/// bind groups to `bind_groups`.
Expand All @@ -246,14 +246,14 @@ impl MeshLayouts {
pub struct Binding {
pub morph: bool,
pub skin: bool,
pub mvectors: bool,
pub motion_vectors: bool,
}
impl Binding {
pub fn new(morph: bool, skin: bool, mvectors: bool) -> Self {
pub fn new(morph: bool, skin: bool, motion_vectors: bool) -> Self {
Self {
morph,
skin,
mvectors,
motion_vectors,
}
}

Expand All @@ -263,9 +263,9 @@ impl Binding {
morphed: "morphed_mesh_layout",
skinned: "skinned_mesh_layout",
morphed_skinned: "morphed_skinned_mesh_layout",
morphed_mvectors: "morphed_mvectors_mesh_layout",
skinned_mvectors: "skinned_mvectors_mesh_layout",
morphed_skinned_mvectors: "morphed_skinned_mvectors_mesh_layout",
morphed_motion_vectors: "morphed_motion_vectors_mesh_layout",
skinned_motion_vectors: "skinned_motion_vectors_mesh_layout",
morphed_skinned_motion_vectors: "morphed_skinned_motion_vectors_mesh_layout",
};
labels.get_binding(self)
}
Expand All @@ -275,9 +275,9 @@ impl Binding {
morphed: "morphed_mesh_bind_group",
skinned: "skinned_mesh_bind_group",
morphed_skinned: "morphed_skinned_mesh_bind_group",
morphed_mvectors: "morphed_mvectors_mesh_bind_group",
skinned_mvectors: "skinned_mvectors_mesh_bind_group",
morphed_skinned_mvectors: "morphed_skinned_mvectors_mesh_bind_group",
morphed_motion_vectors: "morphed_motion_vectors_mesh_bind_group",
skinned_motion_vectors: "skinned_motion_vectors_mesh_bind_group",
morphed_skinned_motion_vectors: "morphed_skinned_motion_vectors_mesh_bind_group",
};
labels.get_binding(self)
}
Expand All @@ -291,11 +291,11 @@ impl Binding {
if self.skin {
entries.extend(skin_layout_entries());
}
if self.morph && self.mvectors {
entries.extend(mvectors_morph_layout_entries());
if self.morph && self.motion_vectors {
entries.extend(motion_vectors_morph_layout_entries());
}
if self.skin && self.mvectors {
entries.extend(mvectors_skin_layout_entries());
if self.skin && self.motion_vectors {
entries.extend(motion_vectors_skin_layout_entries());
}
device.create_bind_group_layout(&BindGroupLayoutDescriptor {
entries: &entries,
Expand Down Expand Up @@ -327,22 +327,22 @@ impl<'a> MeshBindGroupMaker<'a> {
entries.extend(skin_entries(skin));
}
if let Some(previous_weights) = previous_weights {
entries.extend(mvectors_morph_entries(previous_weights));
entries.extend(motion_vectors_morph_entries(previous_weights));
}
if let Some(previous_skin) = previous_skin {
entries.extend(mvectors_skin_entries(previous_skin));
entries.extend(motion_vectors_skin_entries(previous_skin));
}
let skin = skin.is_some();
let mvectors = previous_weights.is_some() || previous_skin.is_some();
let motion_vectors = previous_weights.is_some() || previous_skin.is_some();

let binding = Binding::new(morph.is_some(), skin, mvectors);
let binding = Binding::new(morph.is_some(), skin, motion_vectors);

let bind_group = self.device.create_bind_group(&BindGroupDescriptor {
entries: &entries,
label: Some(binding.bind_group_label()),
layout: self.layouts.get_binding(binding),
});
self.bind_groups
.insert(morph.map(|m| m.0), skin, mvectors, bind_group);
.insert(morph.map(|m| m.0), skin, motion_vectors, bind_group);
}
}

0 comments on commit 6f71fd2

Please sign in to comment.