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] - Spotlights #4715

Closed
wants to merge 53 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
63b91a8
spotlights
robtfm May 4, 2022
fc0a685
update demos
robtfm May 6, 2022
d85cfa2
spotlight cluster culling
robtfm May 10, 2022
19aa631
vary angle in example
robtfm May 10, 2022
61120b5
optimise
robtfm May 10, 2022
f300809
format
robtfm May 10, 2022
c2db39b
use const Vec2 in lights cluster and bounding box when possible (#4602)
mockersf May 6, 2022
2756a8c
spotlight cluster culling
robtfm May 10, 2022
585d101
optimise
robtfm May 10, 2022
c0c5437
format
robtfm May 10, 2022
0cb0544
format
robtfm May 10, 2022
cadcad0
remove debug output
robtfm May 10, 2022
55fb290
fix rebase
robtfm May 10, 2022
91ec7ff
add front_cull test
robtfm May 12, 2022
47fe2ea
shadow maps
robtfm May 13, 2022
8464d7b
fix frustum for culling light entities
robtfm May 13, 2022
87ffc6f
fix spot map offset
robtfm May 14, 2022
6c39cd1
format
robtfm May 14, 2022
5f97f1e
reduce pointlight struct size
robtfm May 16, 2022
2d8a8ed
ci
robtfm May 16, 2022
6f8c9f9
ci?
robtfm May 16, 2022
3de7c9a
clean up maths
robtfm May 17, 2022
f562869
fmt
robtfm May 17, 2022
9357a5e
Merge branch 'main' into spotlight
robtfm May 17, 2022
5f66f57
remove near/far
robtfm May 17, 2022
695bdc5
compress light direction
robtfm Jun 6, 2022
00d3cc2
filament
robtfm Jun 6, 2022
eccfa1b
apply suggestions from code review
robtfm Jun 6, 2022
fb28014
add SpotlightBundle
robtfm Jun 6, 2022
d9b20f4
use xz for direction, revert sign() change
robtfm Jun 7, 2022
e241daa
format
robtfm Jun 7, 2022
109077e
lift condition
robtfm Jun 17, 2022
d3ccb12
fix webgl mipmap sample
robtfm Jun 17, 2022
5968759
remove println
robtfm Jun 21, 2022
b0f651f
Squashed commit of the following:
robtfm Jun 21, 2022
e8e6f1b
reapply to main
robtfm Jun 21, 2022
b1a82d3
Merge branch 'main' into spotlight
robtfm Jun 22, 2022
970a3cc
Merge branch 'main' into spotlight
robtfm Jun 22, 2022
8fd40b2
fmt
robtfm Jun 22, 2022
612813a
fix point light sort order comment
robtfm Jun 25, 2022
d8c362c
add comment on spotlight intensity divisor
robtfm Jun 26, 2022
42cb994
Merge branch 'main' into spotlight
robtfm Jun 26, 2022
68b8ebb
Update Cargo.toml
robtfm Jun 26, 2022
6c8ec1c
build-example-pages
robtfm Jun 26, 2022
723bfeb
spotlight / Spotlight -> spot_light / SpotLight
robtfm Jun 26, 2022
a3809f7
bevy_gltf: Support loading spotlights
superdump Jun 26, 2022
ea909d0
spotlight / Spotlight -> spot_light / SpotLight
robtfm Jun 26, 2022
974fd52
remove unused SPOT_LIGHT flag
robtfm Jun 27, 2022
32a72f2
separate using-facing SpotLight struct
robtfm Jul 8, 2022
8a81014
Merge branch 'main' into spotlight
robtfm Jul 8, 2022
1617119
doc comment
robtfm Jul 8, 2022
45f68ad
ci
robtfm Jul 8, 2022
ab4d91c
ci ci
robtfm Jul 8, 2022
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
Prev Previous commit
Next Next commit
optimise
  • Loading branch information
robtfm committed May 10, 2022
commit 61120b50fbbf83ab807ff260944d7b0adce036ed
18 changes: 9 additions & 9 deletions crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashSet;
use bevy_asset::Assets;
use bevy_ecs::prelude::*;
use bevy_math::{
const_vec2, Mat4, UVec2, UVec3, Vec2, Vec3, Vec3A, Vec3Swizzles, Vec4, Vec4Swizzles,
const_vec2, Mat4, UVec2, UVec3, Vec2, Vec3, Vec3A, Vec3Swizzles, Vec4, Vec4Swizzles, Quat
};
use bevy_reflect::prelude::*;
use bevy_render::{
Expand All @@ -15,7 +15,7 @@ use bevy_render::{
renderer::RenderDevice,
view::{ComputedVisibility, RenderLayers, Visibility, VisibleEntities},
};
use bevy_transform::components::GlobalTransform;
use bevy_transform::{components::GlobalTransform};
use bevy_utils::tracing::warn;
use bevy_window::Windows;

Expand Down Expand Up @@ -706,10 +706,10 @@ pub(crate) fn point_light_order(
pub(crate) struct PointLightAssignmentData {
entity: Entity,
translation: Vec3,
spotlight_direction: Vec3,
rotation: Quat,
range: f32,
shadows_enabled: bool,
spotlight_angle_cos_sin: Option<(f32, f32)>,
spotlight_angle: Option<f32>,
}

#[derive(Default)]
Expand Down Expand Up @@ -767,10 +767,10 @@ pub(crate) fn assign_lights_to_clusters(
|(entity, transform, light, _visibility)| PointLightAssignmentData {
entity,
translation: transform.translation,
spotlight_direction: (transform.rotation * Vec3::Z).normalize(),
rotation: transform.rotation,
shadows_enabled: light.shadows_enabled,
range: light.range,
spotlight_angle_cos_sin: light.spotlight_angles.map(|(_inner, outer)| (outer.cos(), outer.sin())),
spotlight_angle: light.spotlight_angles.map(|(_inner, outer)| outer),
},
),
);
Expand Down Expand Up @@ -1092,7 +1092,7 @@ pub(crate) fn assign_lights_to_clusters(
center: Vec3A::from(inverse_view_transform * light_sphere.center.extend(1.0)),
radius: light_sphere.radius,
};
let view_light_direction = (inverse_view_transform * light.spotlight_direction.extend(0.0)).truncate();
let spotlight_dir_sin_cos = light.spotlight_angle.map(|angle| ((inverse_view_transform * (light.rotation * Vec3::Z).extend(0.0)).truncate(), angle.sin(), angle.cos()));
let light_center_clip =
camera.projection_matrix * view_light_sphere.center.extend(1.0);
let light_center_ndc = light_center_clip.xyz() / light_center_clip.w;
Expand Down Expand Up @@ -1187,9 +1187,9 @@ pub(crate) fn assign_lights_to_clusters(
* clusters.dimensions.z
+ z) as usize;

// Mark all clusters in the range as affected
for x in min_x..=max_x {
if let Some((angle_cos, angle_sin)) = light.spotlight_angle_cos_sin {
// further culling for spotlights
if let Some((view_light_direction, angle_sin, angle_cos)) = spotlight_dir_sin_cos {
// get or initialize cluster bounding sphere
let cluster_aabb_sphere = &mut cluster_aabb_spheres[cluster_index];
let cluster_aabb_sphere = if let Some(sphere) = cluster_aabb_sphere {
Expand Down