Skip to content

Commit 419e733

Browse files
Fixed fog contribution for point and spotlights (#21387)
# Objective Fixes #21327 Volumetric fog contribution was not proportional to the light intensity for point and spotlights. ## Solution Take into account `exposure` value for Point and Spotlights to match the Directional light implementation. ## Testing - Run the updated `volumetric_fog` example. You can see the volumetric effect of point and spotlights now match the intensity of this light on the surfaces of the room. --- ## Showcase Point and spotlight intensities in the original `volumetric_fog` example were too low to light up the room despite having a very strong volumetric contribution. This update boosts the light intensity and lowers the volumetric contribution of point and spotlights Before this change `volumetric_fog` example with 10x light intensity for point and spotlights: <img width="1922" height="1126" alt="brightness_10x_on" src="https://github.com/user-attachments/assets/7562585c-bc1b-4cbf-9d52-4ffb083d65f4" /> After change: <img width="1922" height="1126" alt="brightness_10x_on_fix" src="https://github.com/user-attachments/assets/2a17fec8-0272-4c4e-9d88-d0916027a7c5" />
1 parent 4eabbb7 commit 419e733

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

crates/bevy_pbr/src/volumetric_fog/volumetric_fog.wgsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
#import bevy_pbr::mesh_functions::{get_world_from_local, mesh_position_local_to_clip}
1818
#import bevy_pbr::mesh_view_bindings::{globals, lights, view, clusterable_objects}
1919
#import bevy_pbr::mesh_view_types::{
20-
DIRECTIONAL_LIGHT_FLAGS_VOLUMETRIC_BIT,
21-
POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT,
20+
DIRECTIONAL_LIGHT_FLAGS_VOLUMETRIC_BIT,
21+
POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT,
2222
POINT_LIGHT_FLAGS_VOLUMETRIC_BIT,
2323
POINT_LIGHT_FLAGS_SPOT_LIGHT_Y_NEGATIVE,
2424
ClusterableObject
2525
}
2626
#import bevy_pbr::shadow_sampling::{
27-
sample_shadow_map_hardware,
27+
sample_shadow_map_hardware,
2828
sample_shadow_cubemap,
2929
sample_shadow_map,
3030
SPOT_SHADOW_TEXEL_SIZE
@@ -371,7 +371,7 @@ fn fragment(@builtin(position) position: vec4<f32>) -> @location(0) vec4<f32> {
371371
}
372372
local_light_attenuation *= spot_attenuation * shadow;
373373
}
374-
374+
375375
// Calculate absorption (amount of light absorbed by the fog) and
376376
// out-scattering (amount of light the fog scattered away).
377377
let sample_attenuation = exp(-step_size_world * density * (absorption + scattering));
@@ -381,7 +381,7 @@ fn fragment(@builtin(position) position: vec4<f32>) -> @location(0) vec4<f32> {
381381

382382
let light_attenuation = exp(-density * bounding_radius * (absorption + scattering));
383383
let light_factors_per_step = fog_color * light_tint * light_attenuation *
384-
scattering * density * step_size_world * light_intensity * 0.1;
384+
scattering * density * step_size_world * light_intensity * exposure;
385385

386386
// Modulate the factor we calculated above by the phase, fog color,
387387
// light color, light tint.

examples/3d/volumetric_fog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, app_settings: R
8989
shadows_enabled: true,
9090
range: 150.0,
9191
color: RED.into(),
92-
intensity: 1000.0,
92+
intensity: 10_000.0,
9393
..default()
9494
},
9595
VolumetricLight,
@@ -104,7 +104,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, app_settings: R
104104
commands.spawn((
105105
Transform::from_xyz(-1.8, 3.9, -2.7).looking_at(Vec3::ZERO, Vec3::Y),
106106
SpotLight {
107-
intensity: 5000.0, // lumens
107+
intensity: 50_000.0, // lumens
108108
color: Color::WHITE,
109109
shadows_enabled: true,
110110
inner_angle: 0.76,

0 commit comments

Comments
 (0)