Sky / IBL Generation #753

Merged
SakulFlee merged 18 commits from feat_ibl_generation into main 2026-08-03 02:43:15 +02:00
Owner

This dynamically generates a fake sky to be used for IBL, SkyBox and the WorldEnvironment. It features transitions between day and night (sunset & sunrise) and a procedural generated Sun, Moon and Stars.

Various performance optimizations have already been included.

This dynamically generates a fake sky to be used for IBL, SkyBox and the WorldEnvironment. It features transitions between day and night (sunset & sunrise) and a procedural generated Sun, Moon and Stars. Various performance optimizations have already been included.
Add GeneratedSkyParameters struct with Earth-like atmospheric scattering
defaults (Rayleigh/Mie coefficients, planet radius, sun params). Add
WorldEnvironmentDescriptor::Generated for procedural sky IBL generation
and ::None for explicit environment opt-out. Both variants include
PartialEq and Hash for cache key computation.

Includes unit tests for equality, hashing consistency, and variant
discrimination.
WGSL compute shader implementing single-scattering Rayleigh + Mie
atmospheric ray marching. Produces an equirectangular HDR texture by:
- Converting pixel UV to world-space direction (matching existing
  equirectangular-to-cube conventions)
- Ray-marching 64 view samples through the atmosphere shell
- Computing per-sample optical depth to the sun (8 sun samples)
- Applying Rayleigh and Henyey-Greenstein phase functions
- Compositing a sun disk with angular falloff

Includes naga integration test ensuring the shader parses validly.
Add bind group layout, uniform buffer serialization, and
make_ibl_from_sky_parameters() that:
1. Creates an empty Rgba32Float equirectangular texture
2. Dispatches generate_sky.wgsl to fill it via ray-marched
   atmospheric scattering
3. Feeds the result through the existing diffuse/specular/mipmap
   generation pipeline (reusing make_ibl_diffuse, make_ibl_specular,
   generate_specular_mip_maps_incremental)

Also adds a unit test verifying the WGSL SkyParams buffer layout is
exactly 96 bytes (6 rows × 16 bytes).
realize_environment now automatically generates a default atmospheric
scattering sky (WorldEnvironmentDescriptor::Generated) when no
environment descriptor has ever been set. Supports three modes:
- No descriptor set → auto-default procedural sky (one-shot)
- Some(WorldEnvironmentDescriptor::None) → explicitly disable IBL
- Some(FromFile/FromData/Generated) → use the specified environment

Already-realized environments are skipped unless a fresh descriptor
is present (re-configuration support).
All 7 examples now automatically get a procedural atmospheric sky
via the auto-default behavior in realize_environment. Removed:
- use orbital::resources::WorldEnvironmentDescriptor imports
- EnvironmentDescriptorResource imports
- The 9-line env setup blocks in every example

Users who want custom environments (HDRI, generated with specific
params, or no IBL) can still explicitly insert
EnvironmentDescriptorResource in their Module::setup.
# Conflicts:
#	Crates/orbital_resources/src/world_environment/mod.rs
Replace the equirectangular intermediate + Monte Carlo convolution with a
direct-to-cube sky generator and a deterministic analytic diffuse (Fibonacci
sphere + closed-form sun/moon disks). Adds:

- SunPosition (TimeOfDay/Elevation) + SkyPalette to GeneratedSkyParameters
- star_density parameter and shared sky_common.wgsl sky_color function
- dynamic flag on Generated to bypass the disk cache for animated skies
- material_shader: ACES tone map the HDR sample directly (no clamp/gamma)
- make_ibl_specular: pixel-center and +Y/-Y face mapping fixes
The dynamic generated sky is now updated in place every frame via
WorldEnvironment::update_sky_parameters: it rewrites a single SkyParams
uniform and dispatches the analytic sky cube LoD 0, the analytic diffuse
(now at a fixed 128^2 for the dynamic path) and one specular mip per frame
round-robin — no texture rebuild, no pipeline recompile, no poll_wait.

The skybox is rendered analytically: material_shader_analytic.wgsl evaluates
sky_color per-pixel at full window resolution (binding 14 sky params uniform
added to the world bind group) instead of sampling the regenerated cube, so
the moon, stars and sun are no longer resolution-bound. Background and IBL
reflections stay consistent because both share sky_color.

Also: night lower hemisphere dims to 3% ground albedo, wider stars,
twilight gated off below the horizon, and a tighter moon disk + halo.
perf(app): use PresentMode::Immediate and ControlFlow::Poll for tighter frame loop
All checks were successful
ci/woodpecker/pr/linting Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
78f3231509
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
SakulFlee/Orbital!753
No description provided.