Skip to content

Commit d048d3e

Browse files
authored
Allow negative value for camera elevation in atmosphere (#20769)
# Objective - Fix bug where sky turns black below y = 0 - Fixes #19131 ## Solution - Allow negative value for camera elevation in atmosphere ## Testing - Ran atmosphere example, set the camera's Y position to be negative, sky still renders fine. ## Showcase <img width="1282" height="746" alt="Screenshot 2025-08-26 at 3 38 22 PM" src="https://github.com/user-attachments/assets/9b5a4307-9c97-42f2-8e81-8a71f8c063f2" />
1 parent 16ffdae commit d048d3e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crates/bevy_pbr/src/atmosphere/functions.wgsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const FRAC_2_PI: f32 = 0.15915494309; // 1 / (2π)
4141
const FRAC_3_16_PI: f32 = 0.0596831036594607509; // 3 / (16π)
4242
const FRAC_4_PI: f32 = 0.07957747154594767; // 1 / (4π)
4343
const ROOT_2: f32 = 1.41421356; // √2
44+
const EPSILON: f32 = 1.0; // 1 meter
4445

4546
// During raymarching, each segment is sampled at a single point. This constant determines
4647
// where in the segment that sample is taken (0.0 = start, 0.5 = middle, 1.0 = end).
@@ -306,7 +307,7 @@ fn max_atmosphere_distance(r: f32, mu: f32) -> f32 {
306307

307308
/// Assuming y=0 is the planet ground, returns the view radius in meters
308309
fn view_radius() -> f32 {
309-
return view.world_position.y * settings.scene_units_to_m + atmosphere.bottom_radius;
310+
return max(view.world_position.y * settings.scene_units_to_m, EPSILON) + atmosphere.bottom_radius;
310311
}
311312

312313
// We assume the `up` vector at the view position is the y axis, since the world is locally flat/level.

0 commit comments

Comments
 (0)