Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions crates/bevy_light/src/spot_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ pub struct SpotLight {

/// Angle defining the distance from the spot light direction to the outer limit
/// of the light's cone of effect.
/// `outer_angle` should be < `PI / 2.0`.
/// `PI / 2.0` defines a hemispherical spot light, but shadows become very blocky as the angle

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not true anymore? Just wondering the reason for the removal

@dylansechet dylansechet Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like publicly documenting the behavior of an unsupported value sends a confusing message. To me this read as "pi/2 is possible, with the only downside that you might get weird shadows".

/// approaches this limit.
/// `outer_angle` must be < `PI / 2.0`.
pub outer_angle: f32,

/// Angle defining the distance from the spot light direction to the inner limit
Expand Down
21 changes: 18 additions & 3 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use bevy_light::{
Cascades, DirectionalLight, DirectionalLightShadowMap, GlobalAmbientLight, PointLight,
PointLightShadowMap, RectLight, ShadowFilteringMethod, SpotLight, VolumetricLight,
};
use bevy_log::warn_once;
use bevy_material::{
key::{ErasedMaterialPipelineKey, ErasedMeshPipelineKey},
MaterialProperties,
Expand Down Expand Up @@ -638,8 +639,22 @@ pub fn extract_lights(
));
}

let texel_size =
2.0 * ops::tan(spot_light.outer_angle) / directional_light_shadow_map.size as f32;
// `outer_angle` must be <π/2.
let (inner_angle, outer_angle) = {
let mut outer_angle = spot_light.outer_angle;
if outer_angle >= core::f32::consts::FRAC_PI_2 {
warn_once!(
"A `SpotLight` has `outer_angle` {} >= π/2 (~1.57079), clamping it to just below π/2. \
Spot lights require `outer_angle < π/2`",
outer_angle
);
outer_angle = core::f32::consts::FRAC_PI_2 - 1e-4;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 1e-4 is completely arbitrary

}
// Keep inner_angle <= outer_angle after clamping.
(spot_light.inner_angle.min(outer_angle), outer_angle)
};

let texel_size = 2.0 * ops::tan(outer_angle) / directional_light_shadow_map.size as f32;

let mut entity_commands = commands.entity(render_entity);
let extracted_spot_light = ExtractedPointLight {
Expand All @@ -662,7 +677,7 @@ pub fn extract_lights(
* texel_size
* core::f32::consts::SQRT_2,
shadow_map_near_z: spot_light.shadow_map_near_z,
spot_light_angles: Some((spot_light.inner_angle, spot_light.outer_angle)),
spot_light_angles: Some((inner_angle, outer_angle)),
volumetric: volumetric_light.is_some(),
affects_lightmapped_mesh_diffuse: spot_light.affects_lightmapped_mesh_diffuse,
#[cfg(feature = "experimental_pbr_pcss")]
Expand Down
Loading