diff --git a/crates/bevy_gltf/src/vertex_attributes.rs b/crates/bevy_gltf/src/vertex_attributes.rs index 7c3e9b3651..49f9924187 100644 --- a/crates/bevy_gltf/src/vertex_attributes.rs +++ b/crates/bevy_gltf/src/vertex_attributes.rs @@ -263,6 +263,7 @@ pub(crate) fn convert_attribute( gltf::Semantic::Tangents => Some((Mesh::ATTRIBUTE_TANGENT, ConversionMode::Any)), gltf::Semantic::Colors(0) => Some((Mesh::ATTRIBUTE_COLOR, ConversionMode::Rgba)), gltf::Semantic::TexCoords(0) => Some((Mesh::ATTRIBUTE_UV_0, ConversionMode::TexCoord)), + gltf::Semantic::TexCoords(1) => Some((Mesh::ATTRIBUTE_UV_1, ConversionMode::TexCoord)), gltf::Semantic::Joints(0) => { Some((Mesh::ATTRIBUTE_JOINT_INDEX, ConversionMode::JointIndex)) } diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 6e2112d5d8..dc7a115df5 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -779,14 +779,19 @@ impl SpecializedMeshPipeline for MeshPipeline { vertex_attributes.push(Mesh::ATTRIBUTE_UV_0.at_shader_location(2)); } + if layout.contains(Mesh::ATTRIBUTE_UV_1) { + shader_defs.push("VERTEX_UVS_1".into()); + vertex_attributes.push(Mesh::ATTRIBUTE_UV_1.at_shader_location(3)); + } + if layout.contains(Mesh::ATTRIBUTE_TANGENT) { shader_defs.push("VERTEX_TANGENTS".into()); - vertex_attributes.push(Mesh::ATTRIBUTE_TANGENT.at_shader_location(3)); + vertex_attributes.push(Mesh::ATTRIBUTE_TANGENT.at_shader_location(4)); } if layout.contains(Mesh::ATTRIBUTE_COLOR) { shader_defs.push("VERTEX_COLORS".into()); - vertex_attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(4)); + vertex_attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(5)); } let mut bind_group_layout = match key.msaa_samples() { @@ -800,7 +805,7 @@ impl SpecializedMeshPipeline for MeshPipeline { bind_group_layout.push(setup_morph_and_skinning_defs( &self.mesh_layouts, layout, - 5, + 6, &key, &mut shader_defs, &mut vertex_attributes, diff --git a/crates/bevy_pbr/src/render/mesh.wgsl b/crates/bevy_pbr/src/render/mesh.wgsl index 0755c6859e..84ad95dd36 100644 --- a/crates/bevy_pbr/src/render/mesh.wgsl +++ b/crates/bevy_pbr/src/render/mesh.wgsl @@ -16,15 +16,16 @@ struct Vertex { #ifdef VERTEX_UVS @location(2) uv: vec2, #endif +// (Alternate UVs are at location 3, but they're currently unused here.) #ifdef VERTEX_TANGENTS - @location(3) tangent: vec4, + @location(4) tangent: vec4, #endif #ifdef VERTEX_COLORS - @location(4) color: vec4, + @location(5) color: vec4, #endif #ifdef SKINNED - @location(5) joint_indices: vec4, - @location(6) joint_weights: vec4, + @location(6) joint_indices: vec4, + @location(7) joint_weights: vec4, #endif #ifdef MORPH_TARGETS @builtin(vertex_index) index: u32, diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs index 5830e26cb0..f40318e15d 100644 --- a/crates/bevy_render/src/mesh/mesh/mod.rs +++ b/crates/bevy_render/src/mesh/mesh/mod.rs @@ -146,22 +146,30 @@ impl Mesh { pub const ATTRIBUTE_UV_0: MeshVertexAttribute = MeshVertexAttribute::new("Vertex_Uv", 2, VertexFormat::Float32x2); + /// Alternate texture coordinates for the vertex. Use in conjunction with + /// [`Mesh::insert_attribute`]. + /// + /// Typically, these are used for lightmaps, textures that provide + /// precomputed illumination. + pub const ATTRIBUTE_UV_1: MeshVertexAttribute = + MeshVertexAttribute::new("Vertex_Uv_1", 3, VertexFormat::Float32x2); + /// The direction of the vertex tangent. Used for normal mapping. /// Usually generated with [`generate_tangents`](Mesh::generate_tangents). pub const ATTRIBUTE_TANGENT: MeshVertexAttribute = - MeshVertexAttribute::new("Vertex_Tangent", 3, VertexFormat::Float32x4); + MeshVertexAttribute::new("Vertex_Tangent", 4, VertexFormat::Float32x4); /// Per vertex coloring. Use in conjunction with [`Mesh::insert_attribute`]. pub const ATTRIBUTE_COLOR: MeshVertexAttribute = - MeshVertexAttribute::new("Vertex_Color", 4, VertexFormat::Float32x4); + MeshVertexAttribute::new("Vertex_Color", 5, VertexFormat::Float32x4); /// Per vertex joint transform matrix weight. Use in conjunction with [`Mesh::insert_attribute`]. pub const ATTRIBUTE_JOINT_WEIGHT: MeshVertexAttribute = - MeshVertexAttribute::new("Vertex_JointWeight", 5, VertexFormat::Float32x4); + MeshVertexAttribute::new("Vertex_JointWeight", 6, VertexFormat::Float32x4); /// Per vertex joint transform matrix index. Use in conjunction with [`Mesh::insert_attribute`]. pub const ATTRIBUTE_JOINT_INDEX: MeshVertexAttribute = - MeshVertexAttribute::new("Vertex_JointIndex", 6, VertexFormat::Uint16x4); + MeshVertexAttribute::new("Vertex_JointIndex", 7, VertexFormat::Uint16x4); /// Construct a new mesh. You need to provide a [`PrimitiveTopology`] so that the /// renderer knows how to treat the vertex data. Most of the time this will be