From a2c60b7f47fc713fa922baf4d1fcba8d9b753ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 9 Sep 2023 11:59:22 +0200 Subject: [PATCH 1/3] fix locations for skinned meshes --- crates/bevy_pbr/src/render/wireframe.wgsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/render/wireframe.wgsl b/crates/bevy_pbr/src/render/wireframe.wgsl index 4cb2b4cfa037e..a4aed80cd71e5 100644 --- a/crates/bevy_pbr/src/render/wireframe.wgsl +++ b/crates/bevy_pbr/src/render/wireframe.wgsl @@ -9,8 +9,8 @@ struct Vertex { @builtin(instance_index) instance_index: u32, @location(0) position: vec3, #ifdef SKINNED - @location(4) joint_indexes: vec4, - @location(5) joint_weights: vec4, + @location(5) joint_indexes: vec4, + @location(6) joint_weights: vec4, #endif }; From d8dea2604bfe69dfba9edfc9fded94ef590a6929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 9 Sep 2023 13:25:51 +0200 Subject: [PATCH 2/3] add morph to wireframe specialization key --- crates/bevy_pbr/src/wireframe.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/wireframe.rs b/crates/bevy_pbr/src/wireframe.rs index 58dd5ada64251..a12649b616bb9 100644 --- a/crates/bevy_pbr/src/wireframe.rs +++ b/crates/bevy_pbr/src/wireframe.rs @@ -130,8 +130,11 @@ fn queue_wireframes( let add_render_phase = |(entity, mesh_handle, mesh_transforms): (Entity, &Handle, &MeshTransforms)| { if let Some(mesh) = render_meshes.get(mesh_handle) { - let key = view_key + let mut key = view_key | MeshPipelineKey::from_primitive_topology(mesh.primitive_topology); + if mesh.morph_targets.is_some() { + key |= MeshPipelineKey::MORPH_TARGETS; + } let pipeline_id = pipelines.specialize( &pipeline_cache, &wireframe_pipeline, From 7f29386b1ef86970de1975b39deef9d1d2f05a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 9 Sep 2023 13:30:07 +0200 Subject: [PATCH 3/3] transform vertex for morph --- crates/bevy_pbr/src/render/wireframe.wgsl | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/render/wireframe.wgsl b/crates/bevy_pbr/src/render/wireframe.wgsl index a4aed80cd71e5..453ee5f8c1446 100644 --- a/crates/bevy_pbr/src/render/wireframe.wgsl +++ b/crates/bevy_pbr/src/render/wireframe.wgsl @@ -1,5 +1,6 @@ #import bevy_pbr::mesh_bindings mesh #import bevy_pbr::mesh_functions get_model_matrix, mesh_position_local_to_clip +#import bevy_pbr::morph #ifdef SKINNED #import bevy_pbr::skinning @@ -12,14 +13,40 @@ struct Vertex { @location(5) joint_indexes: vec4, @location(6) joint_weights: vec4, #endif +#ifdef MORPH_TARGETS + @builtin(vertex_index) index: u32, +#endif }; struct VertexOutput { @builtin(position) clip_position: vec4, }; + +#ifdef MORPH_TARGETS +fn morph_vertex(vertex_in: Vertex) -> Vertex { + var vertex = vertex_in; + let weight_count = bevy_pbr::morph::layer_count(); + for (var i: u32 = 0u; i < weight_count; i ++) { + let weight = bevy_pbr::morph::weight_at(i); + if weight == 0.0 { + continue; + } + vertex.position += weight * bevy_pbr::morph::morph(vertex.index, bevy_pbr::morph::position_offset, i); + } + return vertex; +} +#endif + @vertex -fn vertex(vertex: Vertex) -> VertexOutput { +fn vertex(vertex_no_morph: Vertex) -> VertexOutput { + +#ifdef MORPH_TARGETS + var vertex = morph_vertex(vertex_no_morph); +#else + var vertex = vertex_no_morph; +#endif + #ifdef SKINNED let model = bevy_pbr::skinning::skin_model(vertex.joint_indexes, vertex.joint_weights); #else