Skip to content

Conversation

@mate-h
Copy link
Contributor

@mate-h mate-h commented Dec 17, 2025

Objective

  • Fix atmosphere lighting issue for below ground geo

Issue reported in discord channel for rendering-dev by Jondolf@

image

Repro on f8a9f29

use bevy::{pbr::EarthlikeAtmosphere, prelude::*};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
    earthlike_atmosphere: Res<EarthlikeAtmosphere>,
) {
    commands.spawn((
        Mesh3d(meshes.add(Capsule3d::new(0.5, 1.0))),
        MeshMaterial3d(materials.add(Color::WHITE)),
    ));

    // Directional light
    commands.spawn((
        DirectionalLight {
            illuminance: 5000.0,
            shadows_enabled: true,
            ..default()
        },
        Transform::from_xyz(1.0, 2.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y),
    ));

    // Camera and atmosphere
    commands.spawn((
        Camera3d::default(),
        earthlike_atmosphere.get(),
        Transform::from_xyz(10.0, 2.0, 15.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
    ));
}

Solution

  • Clamp the position to the ground surface with a small epsilon before calculating occlusion from the planet

Testing

  • Ran the atmosphere example with local changes to put geo below-ground

Showcase

Before
Screenshot 2025-12-17 at 1 58 21 PM

After

Screenshot 2025-12-17 at 1 57 56 PM

@mate-h mate-h requested a review from Jondolf December 17, 2025 22:03
@mate-h mate-h added C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 17, 2025
@JMS55 JMS55 added this to the 0.18 milestone Dec 17, 2025
Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

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

Thank you!

@Zeophlite Zeophlite added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 17, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 17, 2025
@alice-i-cecile alice-i-cecile added the A-Rendering Drawing game state to the screen label Dec 17, 2025
Merged via the queue into bevyengine:main with commit 2043484 Dec 17, 2025
47 checks passed
mockersf pushed a commit that referenced this pull request Dec 30, 2025
# Objective

- Fix atmosphere lighting issue for below ground geo

Issue reported in discord channel for `rendering-dev` by Jondolf@

<img width="3840" height="2111" alt="image"
src="https://github.com/user-attachments/assets/f2768fd5-2e70-46cb-b0f3-b078d115fd33"
/>

Repro on
[f8a9f29](f8a9f29)

```rs
use bevy::{pbr::EarthlikeAtmosphere, prelude::*};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
    earthlike_atmosphere: Res<EarthlikeAtmosphere>,
) {
    commands.spawn((
        Mesh3d(meshes.add(Capsule3d::new(0.5, 1.0))),
        MeshMaterial3d(materials.add(Color::WHITE)),
    ));

    // Directional light
    commands.spawn((
        DirectionalLight {
            illuminance: 5000.0,
            shadows_enabled: true,
            ..default()
        },
        Transform::from_xyz(1.0, 2.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y),
    ));

    // Camera and atmosphere
    commands.spawn((
        Camera3d::default(),
        earthlike_atmosphere.get(),
        Transform::from_xyz(10.0, 2.0, 15.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y),
    ));
}
```

## Solution

- Clamp the position to the ground surface with a small epsilon before
calculating occlusion from the planet

## Testing

- Ran the atmosphere example with local changes to put geo below-ground

---

## Showcase

Before
<img width="1283" height="720" alt="Screenshot 2025-12-17 at 1 58 21 PM"
src="https://github.com/user-attachments/assets/f442e0f9-b688-4d16-ad08-d9b3414c8b0f"
/>

After

<img width="1275" height="719" alt="Screenshot 2025-12-17 at 1 57 56 PM"
src="https://github.com/user-attachments/assets/557ea595-3b9d-4fbf-8c94-10377deb046a"
/>
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-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants