From 262b3fc40d7c4171dd585f7127cfb54573edb170 Mon Sep 17 00:00:00 2001 From: ira Date: Thu, 3 Nov 2022 12:38:47 +0000 Subject: [PATCH] Fix `mesh.wgsl` error for meshes without normals (#6439) # Objective Split `model` assignment out of `#ifdef VERTEX_NORMALS`. Remove outdated code/comments talking about required mesh attributes. Co-authored-by: devil-ira --- crates/bevy_pbr/src/render/mesh.wgsl | 8 ++++++-- examples/3d/lines.rs | 9 --------- examples/animation/custom_skinned_mesh.rs | 3 --- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh.wgsl b/crates/bevy_pbr/src/render/mesh.wgsl index 266ff804b5..4945db8fbf 100644 --- a/crates/bevy_pbr/src/render/mesh.wgsl +++ b/crates/bevy_pbr/src/render/mesh.wgsl @@ -35,12 +35,16 @@ struct VertexOutput { fn vertex(vertex: Vertex) -> VertexOutput { var out: VertexOutput; -#ifdef VERTEX_NORMALS #ifdef SKINNED var model = skin_model(vertex.joint_indices, vertex.joint_weights); - out.world_normal = skin_normals(model, vertex.normal); #else var model = mesh.model; +#endif + +#ifdef VERTEX_NORMALS +#ifdef SKINNED + out.world_normal = skin_normals(model, vertex.normal); +#else out.world_normal = mesh_normal_local_to_world(vertex.normal); #endif #endif diff --git a/examples/3d/lines.rs b/examples/3d/lines.rs index a6d61c401b..2f80430573 100644 --- a/examples/3d/lines.rs +++ b/examples/3d/lines.rs @@ -95,12 +95,9 @@ pub struct LineList { impl From for Mesh { fn from(line: LineList) -> Self { let mut vertices = vec![]; - let mut normals = vec![]; for (start, end) in line.lines { vertices.push(start.to_array()); vertices.push(end.to_array()); - normals.push(Vec3::ZERO.to_array()); - normals.push(Vec3::ZERO.to_array()); } // This tells wgpu that the positions are list of lines @@ -108,8 +105,6 @@ impl From for Mesh { let mut mesh = Mesh::new(PrimitiveTopology::LineList); mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, vertices); - // Normals are currently required by bevy, but they aren't used by the [`LineMaterial`] - mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, normals); mesh } } @@ -123,10 +118,8 @@ pub struct LineStrip { impl From for Mesh { fn from(line: LineStrip) -> Self { let mut vertices = vec![]; - let mut normals = vec![]; for pos in line.points { vertices.push(pos.to_array()); - normals.push(Vec3::ZERO.to_array()); } // This tells wgpu that the positions are a list of points @@ -134,8 +127,6 @@ impl From for Mesh { let mut mesh = Mesh::new(PrimitiveTopology::LineStrip); mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, vertices); - // Normals are currently required by bevy, but they aren't used by the [`LineMaterial`] - mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, normals); mesh } } diff --git a/examples/animation/custom_skinned_mesh.rs b/examples/animation/custom_skinned_mesh.rs index 689c3a2e91..d1d924a278 100644 --- a/examples/animation/custom_skinned_mesh.rs +++ b/examples/animation/custom_skinned_mesh.rs @@ -71,9 +71,6 @@ fn setup( ); // Set mesh vertex normals mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, vec![[0.0, 0.0, 1.0]; 10]); - // Set mesh vertex UVs. Although the mesh doesn't have any texture applied, - // UVs are still required by the render pipeline. So these UVs are zeroed out. - mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, vec![[0.0, 0.0]; 10]); // Set mesh vertex joint indices for mesh skinning. // Each vertex gets 4 indices used to address the `JointTransforms` array in the vertex shader // as well as `SkinnedMeshJoint` array in the `SkinnedMesh` component.