Colors are dark when normals are missing
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.12.0
## What you did
Add two triangles to the scene. One of them with proper normals, and another without.
```rust
use bevy::app::App;
use bevy::app::Startup;
use bevy::prelude::*;
use bevy::render::mesh::Indices;
use bevy::render::mesh::PrimitiveTopology;
fn setup(
mut commands: Commands,
mut materials: ResMut>,
mut meshes: ResMut>,
) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(3.0, 3.0, 3.0).looking_at(Vec3::new(0., 0., 0.), Vec3::Z),
..default()
});
commands.spawn(DirectionalLightBundle {
transform: Transform::from_xyz(1., 1., 1.).looking_at(Vec3::ZERO, Vec3::Z),
..DirectionalLightBundle::default()
});
// Proper triangle with normals.
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
mesh.insert_attribute(
Mesh::ATTRIBUTE_POSITION,
vec![
Vec3::new(0., 0., 0.),
Vec3::new(1., 0., 0.),
Vec3::new(1., 1., 0.),
],
);
mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, vec![Vec3::Z, Vec3::Z, Vec3::Z]);
mesh.set_indices(Some(Indices::U32(vec![0, 1, 2])));
commands.spawn(PbrBundle {
mesh: meshes.add(mesh),
material: materials.add(Color::BLUE.into()),
..Default::default()
});
// Triangle without normals.
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
mesh.insert_attribute(
Mesh::ATTRIBUTE_POSITION,
vec![
Vec3::new(0., 0., 0.),
Vec3::new(-1., -1., 0.),
Vec3::new(0., -1., 0.),
],
);
// Skip normals.
mesh.set_indices(Some(Indices::U32(vec![0, 1, 2])));
commands.spawn(PbrBundle {
mesh: meshes.add(mesh),
material: materials.add(Color::GREEN.into()),
..Default::default()
});
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
```
## What went wrong
Triangle with normals is shown lit, and triangle without normals is very dark.
I'm not sure if this is a bug or not, but this is somewhat non-trivial to deal with when learning bevy. Not sure what should be proper fix:
* show triangle without normals as fully lit
* show a warning in console
* compute default normals
* render something over the triangle like checkerboard to highlight the possible error
* close this issue because it works as expected (and maybe explain it somewhere in the documentation)
## Additional information
Contributor guide
Assessment
This issue has not been assessed yet.