Skip to content

Raymarched rendering for atmosphere and spherical coordinates#20766

Merged
alice-i-cecile merged 12 commits into
bevyengine:mainfrom
mate-h:m/spherical-atmosphere
Sep 3, 2025
Merged

Raymarched rendering for atmosphere and spherical coordinates#20766
alice-i-cecile merged 12 commits into
bevyengine:mainfrom
mate-h:m/spherical-atmosphere

Conversation

@mate-h

@mate-h mate-h commented Aug 26, 2025

Copy link
Copy Markdown
Contributor

Objective

Solution

  • Added spherical coordinate system alongside the sky-view lut parameterization
  • Added ray-marched rendering method to support space views and accurate lighting
  • This is setting the stage for PBR integration, volumetric shadows
  • Could maybe re-use the ray-marching function in the aerial view LUT as well, but I didn't bother for this PR (future improvement)

Testing

  • Ran the atmosphere example to ensure it still works fine with both rendering methods
  • Created a freecam version of the atmosphere example and put the camera in space, below ground.

Showcase

Screen.Recording.2025-09-02.at.12.28.35.AM.mov

@mate-h mate-h requested review from atlv24 and ecoskey August 26, 2025 17:01
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen M-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 26, 2025
@github-actions

Copy link
Copy Markdown
Contributor

It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note.

Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes.

@mate-h mate-h added M-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed M-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 26, 2025
@github-actions

Copy link
Copy Markdown
Contributor

It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note.

Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes.

@JMS55

JMS55 commented Aug 26, 2025

Copy link
Copy Markdown
Contributor

Fix bug where sky turns black below y = 0

Which part fixes that?

Also this is #19131

Comment thread crates/bevy_pbr/src/atmosphere/functions.wgsl Outdated
Comment thread crates/bevy_pbr/src/atmosphere/functions.wgsl Outdated
Comment thread crates/bevy_pbr/src/atmosphere/mod.rs Outdated
Comment thread crates/bevy_pbr/src/atmosphere/mod.rs Outdated
Comment thread crates/bevy_pbr/src/atmosphere/resources.rs
Comment thread crates/bevy_pbr/src/atmosphere/types.wgsl Outdated
@mate-h mate-h added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 27, 2025
@mate-h mate-h removed the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label Aug 31, 2025
Comment thread crates/bevy_pbr/src/atmosphere/mod.rs
Co-authored-by: atlv <email@atlasdostal.com>
Comment thread crates/bevy_pbr/src/atmosphere/mod.rs Outdated
Comment thread crates/bevy_pbr/src/atmosphere/mod.rs Outdated
Comment thread crates/bevy_pbr/src/atmosphere/mod.rs Outdated
Comment thread crates/bevy_pbr/src/atmosphere/sky_view_lut.wgsl Outdated
Comment thread release-content/release-notes/raymarched-atmosphere-space-views.md Outdated
@mate-h

mate-h commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for the comments! I think everything has been addressed, including what to do for when the camera is inside of the earth. I update the atmosphere example here for testing but decided not to include it in this PR to avoid more scope. I would say at this stage it's ready for a final review. I updated the PR description with a new demo video.
https://github.com/mate-h/bevy/pull/13/files

@mate-h mate-h 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 Sep 2, 2025
Comment thread crates/bevy_pbr/src/atmosphere/mod.rs Outdated
Comment thread crates/bevy_pbr/src/atmosphere/functions.wgsl Outdated
Comment thread crates/bevy_pbr/src/atmosphere/functions.wgsl Outdated
Comment thread release-content/release-notes/raymarched-atmosphere-space-views.md Outdated
Comment thread release-content/release-notes/raymarched-atmosphere-space-views.md Outdated
Comment thread release-content/release-notes/raymarched-atmosphere-space-views.md Outdated

@atlv24 atlv24 left a comment

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.

Fully happy with these changes now. Thanks for being patient :)

One last thing i'd consider is if view_pos never gets used directly (always immediately fed to length+normalize to get r and up) then maybe having get_view_position return a struct that has an up and radius field would make sense. Happy with it as is though, thanks for all the work!

@mate-h

mate-h commented Sep 3, 2025

Copy link
Copy Markdown
Contributor Author

@alice-i-cecile this one is ready for a final review and merge!
Also note that once this is merged, the PR #20838 by @ecoskey will have to be rebased.

@mate-h mate-h removed the request for review from ecoskey September 3, 2025 18:13

@alice-i-cecile alice-i-cecile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm happy with this too :) Quite clear, and a feature that a lot of our devs will love.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 3, 2025
Merged via the queue into bevyengine:main with commit df74f98 Sep 3, 2025
32 checks passed
github-merge-queue Bot pushed a commit that referenced this pull request Mar 4, 2026
# Objective

Since introducing spherical coordinate systems and space views for
Bevy's atmosphere in PR #20766, the LUT-based rendering had a remaining
bug: when tilting the camera and viewing Earth from space, the lit/dark
terminator rotated with the view instead of staying fixed. Raymarched
rendering was correct, only the LUT path was affected. This PR fixes
that by using an atmosphere frame that keeps the terminator stable while
still concentrating texel density toward the horizon as in the Hillaire
paper.

This is what the bug reproduction looks like on main: 


https://github.com/user-attachments/assets/e3488e41-d663-4b19-90c5-65b1fdb77b4c

With this change, the atmosphere rendering from space is officially
supported using the LUT based method. That can be taken advantage of in
lower end devices, or on a tight performance budget.

## Solution

- Compute the atmosphere frame with local up for zenith and a
world-fixed azimuth
- Use the atmosphere transform for both LUT generation and sampling via
`direction_world_to_atmosphere`, effectively reverting this code block
to the previous state before PR #20766
- Raymarch the sky view LUT from the actual camera position.

## Testing

- Ran the atmosphere example by increasing the scene's scale
```rs
AtmosphereSettings {
    scene_units_to_m: 10e4,
    aerial_view_lut_max_distance: 3.2e4 * 128.0,
    ..default()
},
```

---

## Showcase

new LUT based rendering:
<img width="1278" height="754" alt="lutbased"
src="https://github.com/user-attachments/assets/d4792c8e-43a2-4b03-a21d-330ce26c3474"
/>

raymarched rendering for reference "ground truth":
<img width="1280" height="753" alt="raymarched"
src="https://github.com/user-attachments/assets/909bfaf8-6abd-4338-bcfd-f94f7b3a6de2"
/>
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-Feature A new feature, making something new possible M-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants