Regression: RenderLayers do not work for Lights
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version and features
- 18.1 default
## What you did
Attempted to light a specific mesh in the scene using RenderLayers.
```
use bevy::prelude::*;
use bevy::camera::visibility::RenderLayers;
fn setup(
mut commands: Commands,
mut meshes: ResMut>,
mut materials: ResMut>,
) {
// Camera should see both layers
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0.0, 4.0, 12.0).looking_at(Vec3::ZERO, Vec3::Y),
RenderLayers::from_layers(&[0, 1]),
));
// Object 1: on layers 0 and 1
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(2.0, 2.0, 2.0))),
MeshMaterial3d(materials.add(Color::srgb(0.8, 0.2, 0.2))),
Transform::from_xyz(-2.5, 0.0, 0.0),
RenderLayers::from_layers(&[0, 1]),
));
// Object 2: only on layer 0
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(2.0, 2.0, 2.0))),
MeshMaterial3d(materials.add(Color::srgb(0.2, 0.2, 0.8))),
Transform::from_xyz(2.5, 0.0, 0.0),
RenderLayers::layer(0),
));
// Directional light A: only layer 1
// => affects only Object 1
commands.spawn((
DirectionalLight {
illuminance: 10_000.0,
..default()
},
Transform::from_rotation(Quat::from_euler(
EulerRot::XYZ,
-1.0,
-1.0,
0.0,
)),
RenderLayers::layer(1),
));
// Directional light B: only layer 0
// => affects both objects, because both are on layer 0
commands.spawn((
DirectionalLight {
illuminance: 20_000.0,
..default()
},
Transform::from_rotation(Quat::from_euler(
EulerRot::XYZ,
-0.6,
0.8,
0.0,
)),
RenderLayers::layer(0),
));
}
```
## What went wrong
The light affected all meshes in the camera/view regardless of RenderLayer settings.
## Additional information
This was previously working, and likely broke along the way:
https://github.com/bevyengine/bevy/pull/10742
Contributor guide
Assessment
This issue has not been assessed yet.