-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Merged by Bors] - perf: only recalculate frusta of changed lights #4086
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
james7132
approved these changes
Mar 3, 2022
alice-i-cecile
approved these changes
Mar 3, 2022
superdump
approved these changes
Mar 3, 2022
mockersf
approved these changes
Mar 7, 2022
e07fd6e
to
516b2ef
Compare
bors r+ |
bors bot
pushed a commit
that referenced
this pull request
Mar 8, 2022
## Objective Currently, all directional and point lights have their viewing frusta recalculated every frame, even if they have not moved or been disabled/enabled. ## Solution The relevant systems now make use of change detection to only update those lights whose viewing frusta may have changed.
aevyrie
pushed a commit
to aevyrie/bevy
that referenced
this pull request
Jun 7, 2022
## Objective Currently, all directional and point lights have their viewing frusta recalculated every frame, even if they have not moved or been disabled/enabled. ## Solution The relevant systems now make use of change detection to only update those lights whose viewing frusta may have changed.
ItsDoot
pushed a commit
to ItsDoot/bevy
that referenced
this pull request
Feb 1, 2023
## Objective Currently, all directional and point lights have their viewing frusta recalculated every frame, even if they have not moved or been disabled/enabled. ## Solution The relevant systems now make use of change detection to only update those lights whose viewing frusta may have changed.
I believe this optimization was wrong for not considering that changes to @dataphract do you remember how much extra performance this actually gives? Can you help me think of a potential solution perhaps? EDIT: I believe I found a compromise that fixes the bug but keeps the performance benefit: #18519 |
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 25, 2025
…anges) (#18519) # Objective - Fixes #11682 ## Solution - #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: #11682 (comment) 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>
mockersf
pushed a commit
that referenced
this pull request
Mar 25, 2025
…anges) (#18519) # Objective - Fixes #11682 ## Solution - #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: #11682 (comment) 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>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-Rendering
Drawing game state to the screen
C-Performance
A change motivated by improving speed, memory usage or compile times
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Currently, all directional and point lights have their viewing frusta recalculated every frame, even if they have not moved or been disabled/enabled.
Solution
The relevant systems now make use of change detection to only update those lights whose viewing frusta may have changed.