bevy/crates
HugoPeters1024 df26bc3387 bugfix(frustra of point lights were not recalculated when a camera changes) (#18519)
# Objective

- Fixes https://github.com/bevyengine/bevy/issues/11682

## Solution

- https://github.com/bevyengine/bevy/pull/4086 introduced an
optimization to not do redundant calculations, but did not take into
account changes to the resource `global_lights`. I believe that my patch
includes the optimization benefit but adds the required nuance to fix
said bug.

## Testing

The example originally given by
[@kirillsurkov](https://github.com/kirillsurkov) and then updated by me
to bevy 15.3 here:
https://github.com/bevyengine/bevy/issues/11682#issuecomment-2746287416
will not have shadows without this patch:

```rust
use bevy::prelude::*;

#[derive(Resource)]
struct State {
    x: f32,
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, update)
        .insert_resource(State { x: -40.0 })
        .run();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    commands.spawn((
        Mesh3d(meshes.add(Circle::new(4.0))),
        MeshMaterial3d(materials.add(Color::WHITE)),
    ));
    commands.spawn((
        Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
        MeshMaterial3d(materials.add(Color::linear_rgb(0.0, 1.0, 0.0))),
    ));
    commands.spawn((
        PointLight {
            shadows_enabled: true,
            ..default()
        },
        Transform::from_xyz(4.0, 8.0, 4.0),
    ));
    commands.spawn(Camera3d::default());
}

fn update(mut state: ResMut<State>, mut camera: Query<&mut Transform, With<Camera3d>>) {
    let mut camera = camera.single_mut().unwrap();

    let t = Vec3::new(state.x, 0.0, 10.0);
    camera.translation = t;
    camera.look_at(t - Vec3::Z, Vec3::Y);

    state.x = 0.0;
}
```

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com>
2025-03-25 22:59:04 +01:00
..
bevy_a11y Update accesskit and accesskit_winit requirements (#18285) 2025-03-25 22:44:01 +01:00
bevy_animation Reduce dependencies on bevy_render by preferring bevy_mesh imports (#18437) 2025-03-25 22:45:39 +01:00
bevy_app Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_asset Don't panic on temporary files in file watcher (#18462) 2025-03-25 22:45:41 +01:00
bevy_audio Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_color Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_core_pipeline Record bloom render commands in parallel (#18330) 2025-03-25 22:44:01 +01:00
bevy_derive Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_dev_tools Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_diagnostic Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_dylib Switch from OnceCell to LazyLock in bevy_tasks (#18506) 2025-03-25 22:41:01 +01:00
bevy_ecs Define system param validation on a per-system parameter basis (#18504) 2025-03-25 22:59:04 +01:00
bevy_encase_derive Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_gilrs Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_gizmos Define system param validation on a per-system parameter basis (#18504) 2025-03-25 22:59:04 +01:00
bevy_gltf Reduce dependencies on bevy_render by preferring bevy_mesh imports (#18437) 2025-03-25 22:45:39 +01:00
bevy_image Ensure dds enables bevy_core_pipeline/dds in bevy_anti_aliasing (#18484) 2025-03-24 00:11:37 +01:00
bevy_input Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_input_focus Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_internal enable x11 by default in bevy_winit (#18475) 2025-03-25 22:40:31 +01:00
bevy_log Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_macro_utils Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_math Add no_std compatible ceil method (#18498) 2025-03-25 22:59:04 +01:00
bevy_mesh Reduce dependencies on bevy_render by preferring bevy_mesh imports (#18437) 2025-03-25 22:45:39 +01:00
bevy_mikktspace Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_pbr bugfix(frustra of point lights were not recalculated when a camera changes) (#18519) 2025-03-25 22:59:04 +01:00
bevy_picking Reduce dependencies on bevy_render by preferring bevy_mesh imports (#18437) 2025-03-25 22:45:39 +01:00
bevy_platform_support Address lints in bevy_platform_support (#18477) 2025-03-24 00:09:30 +01:00
bevy_ptr Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_reflect Update bincode to 2.0 (#18396) 2025-03-25 22:44:01 +01:00
bevy_remote fix error and lints when building for wasm32 (#18500) 2025-03-24 00:14:22 +01:00
bevy_render Define system param validation on a per-system parameter basis (#18504) 2025-03-25 22:59:04 +01:00
bevy_scene Update bincode to 2.0 (#18396) 2025-03-25 22:44:01 +01:00
bevy_sprite ExtractedSprites slice buffer (#17041) 2025-03-25 22:43:58 +01:00
bevy_state Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_tasks Switch from OnceCell to LazyLock in bevy_tasks (#18506) 2025-03-25 22:41:01 +01:00
bevy_text ExtractedSprites slice buffer (#17041) 2025-03-25 22:43:58 +01:00
bevy_time Fix clippy::unnecessary-literal-unwrap in bevy_time (#18485) 2025-03-24 00:14:22 +01:00
bevy_transform Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_ui Update accesskit and accesskit_winit requirements (#18285) 2025-03-25 22:44:01 +01:00
bevy_utils Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_window Replace VisitEntities with MapEntities (#18432) 2025-03-24 00:09:29 +01:00
bevy_winit Update accesskit and accesskit_winit requirements (#18285) 2025-03-25 22:44:01 +01:00