diff --git a/crates/bevy_pbr/src/render/wireframe.wgsl b/crates/bevy_pbr/src/render/wireframe.wgsl index 4cb2b4cfa0..453ee5f8c1 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 @@ -9,8 +10,11 @@ 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 +#ifdef MORPH_TARGETS + @builtin(vertex_index) index: u32, #endif }; @@ -18,8 +22,31 @@ 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 diff --git a/crates/bevy_pbr/src/wireframe.rs b/crates/bevy_pbr/src/wireframe.rs index 58dd5ada64..a12649b616 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,