Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Fix mesh.wgsl error for meshes without normals #6439

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/bevy_pbr/src/render/mesh.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions examples/3d/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,16 @@ pub struct LineList {
impl From<LineList> 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
// where every pair is a start and end point
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
}
}
Expand All @@ -123,19 +118,15 @@ pub struct LineStrip {
impl From<LineStrip> 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
// where a line will be drawn between each consecutive point
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
}
}
3 changes: 0 additions & 3 deletions examples/animation/custom_skinned_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down