Sky and Atmosphere
The outdoor sky is built from a contract crate and five engine crates, each a statically linked runtime plugin with its inspector in a nested editor crate:
| Crate | Plugin | What it owns |
|---|---|---|
renzora_world_api | (contract) | Sun, WorldEnvironment, WorldEnvironmentSpawned, WindState |
renzora_lighting | LightingPlugin | Turns a Sun into the scene's one DirectionalLight and its SunDisk |
renzora_atmosphere | AtmospherePlugin | Bevy's physical sky, the sun glare pass, the moon |
renzora_clouds | CloudsPlugin | Volumetric cloud deck, and its copy in the environment cubemap |
renzora_skybox | SkyboxPlugin | Non-physical backgrounds: colour, gradient, HDR panorama, tiled |
renzora_distance_fog | DistanceFogPlugin | The World Environment's fog section, applied to Bevy's DistanceFog |
Everything here reads its settings from a World Environment entity and applies them to cameras. Fog with light shafts is separate: see Volumetric Fog.
Routing: settings live on entities, effects live on cameras
None of these crates queries "the camera". They read
renzora_scene_api::EffectRouting, a resource of (target_camera, [source_entities]) pairs that the viewport (editor) or renzora_engine
(runtime) rewrites each frame. For each settings type the first source in
a camera's list that carries it wins. That is what lets one World Environment
drive the editor viewport, a second viewport and the game camera alike, and it
is why a sync system that finds no routed source tears its effect down rather
than leaving the last value in place.
All of them also honour renzora_render_api::EnvironmentSuppressed: while
active (a viewport shading mode with no environment, such as wireframe), the
atmosphere is switched off and the skybox removed, and cameras clear to the
colour the resource carries.
When the editor spawns a World Environment (the preset, or the New Environment
starter) it triggers WorldEnvironmentSpawned { entity, outdoor_daylight }
after the engine's own sky components are on it. A crate that contributes to
the sky observes that event instead of the preset naming its type: clouds are
added this way, so a build without renzora_clouds builds the same sky with
none. A scene being loaded does not fire it; it already carries what it was
saved with.
Sun
Sun (in renzora_world_api, re-exported as renzora_lighting::Sun) is a
directional light described by angles. It lives in the contract because
crates on both sides of the plugin boundary read it.
sync_sun rewrites the entity's DirectionalLight, Transform and SunDisk
whenever the Sun changes. The authored illuminance is never touched; the
light carries the effective value, which is the sun's while it is up and the
moon's once it has set (renzora_lighting::sun_light). One light rather than a
second moon entity means every scene with a sun already has a moonlit night,
and nothing new is saved into it.
| Field | Default | Notes |
|---|---|---|
azimuth | 245.5 | Compass direction in degrees |
elevation | 38.5 | Degrees above the horizon, -90 to 90 |
color | (1.0, 0.95, 0.88) | Linear RGB |
illuminance | 120,000 | Lux |
shadows_enabled | true | Cleared on the light while nothing is lit |
contact_shadows | true | See Shadows |
contact_shadow_length | 0.8 | Metres |
contact_shadow_thickness | 0.1 | Metres |
contact_shadow_steps | 32 | Clamped to CONTACT_SHADOW_STEPS (4..=64) on the GPU side |
angular_diameter | 0.53 | Degrees; becomes SunDisk::angular_size |
sun_disk_intensity | 1.0 | 0 hides the disc |
glare_intensity | 1.5 | 0 turns the glare off |
glare_size | 6.0 | Degrees from the sun's centre |
moon_illuminance | 150 | Lux; 0 keeps nights unlit |
moon_color | (0.62, 0.72, 1.0) | Colour of the moonlight |
moon_follows_calendar | true | Phase from the system date |
moon_day | 14.77 (half of SYNODIC_MONTH_DAYS) | Used when the calendar is not followed |
moon_tint | (1.0, 0.97, 0.92) | Colour of the moon's face |
moon_eclipse | 0.0 | 0 to 1; 1 is a total lunar eclipse |
moon_glow | 1.0 | Halo strength |
moon_size | 1.6 | Apparent diameter in degrees |
Every field added after the first release carries #[serde(default)] and
#[reflect(default)], so a Sun saved before it existed still loads (a test,
a_sun_saved_before_the_glare_still_loads, holds that line).
Day, night and the handover
Two free functions decide which body lights the scene, both from elevation alone:
horizon_factor(Sun::daylight): 1 above +5 degrees, 0 below -1 degree. The sun's light, disc and glare fade together over that band.moon_factor(Sun::moonrise): 0 while any of the sun is up, 1 once the sun is 7 degrees down.
They meet at -1 degree, so the sun and the moon never light the scene at the
same time. At night sun_light points the light along Sun::moon_direction
(opposite azimuth, elevation clamped to 15..75 degrees so the moon neither
skims the ground nor stands overhead) and scales it by phase (never below 15%
of full, so a new-moon night is still readable) and eclipse (dimmed and
reddened).
The default 150 lux is far brighter than a real full moon on purpose: auto exposure cannot open far enough to make physical moonlight readable.
Scripts can set the angles through the set_sun_angles action (arguments
azimuth, elevation), which renzora_lighting observes and applies to every
Sun.
Atmosphere
AtmosphereComponentSettings is the authored half, on the World Environment:
| Field | Default | Notes |
|---|---|---|
bottom_radius | 6,360,000 | Planet radius in metres; Bevy's inner_radius |
top_radius | 6,460,000 | Top of the atmosphere; Bevy's outer_radius |
ground_albedo | 0.3 | Splat into Bevy's Vec3 |
mode | 1 | 0 = LookupTexture, 1 = Raymarched |
scene_units_to_m | 1.0 | Editable, but not read by the sync today |
enabled | true |
Why the real Atmosphere lives on its own entity
Bevy treats the Atmosphere entity's GlobalTransform as the planet
centre, and its on-add hook drops a fresh atmosphere to (0, -inner_radius, 0) so world Y = 0 is the surface. The host entity therefore has to be
stationary and must not have a Transform, or propagation would pull the
planet centre back to the origin and put the camera 6,360 km underground with
no sky. The World Environment fails both (its rotation aims the sun's light).
So sync_atmosphere keeps one hidden AtmospherePlanet entity, named "Sky
Atmosphere" and marked HideInHierarchy, with the Atmosphere and an explicit
planet-centre GlobalTransform and no Transform. It reconciles from scratch
each frame: the first routed source carrying AtmosphereComponentSettings
decides, and a disabled source, a deleted source, or an active
EnvironmentSuppressed all mean "no sky".
The one ScatteringMedium is created once and held in a Local for the
app's life. The render world runs a frame behind, so a medium freed together
with the component that pointed at it was still being read there.
Turning the sky off
Off removes the atmosphere from the renderer completely, so its lookup tables, sky draw and sky bake cost nothing:
Atmosphereis removed from the planet entity (the entity stays, so turning it back on is an insert, not a respawn).- Each camera's
AtmosphereSettingsandAtmosphereEnvironmentMapLightare removed and parked in aParkedSkycomponent.
Turning it back on restores what was parked, in the current render mode. A
parked sky probe comes back at the graphics tier's ibl_face_size, not the
size it was parked at, because resizing a probe in place is what crashes
Bevy's filtered environment map generator. Cameras marked IsolatedCamera keep
their own size.
The graphics tier can also lower the sky: below High, renzora_engine's
graphics quality pass switches a Raymarched camera to LookupTexture
(roughly 40 times cheaper per pixel and near-identical for a static sky).
Black behind the sky
Bevy composites the sky as framebuffer * transmittance + inscattering, so the
clear colour shows through wherever the air scatters little. At night that
turned the default editor grey into a flat overcast. sync_space_backdrop
sets every camera with an enabled sky to clear to black, but only a camera on
ClearColorConfig::Default; it marks those with SpaceBackdrop and hands the
default back when the sky goes, so a colour someone chose is never touched.
Sun glare
Bevy's bloom caps how much any single pixel adds to the glow (its first pass
is a firefly filter), so a sun disc a hundred thousand times brighter than the
sky blooms no more than a bright cloud. renzora_atmosphere::glare draws the
glare as its own pass instead.
- Main world.
sync_sun_glarepicks the brightestSunand inserts aSunGlare(toward_sun,tint,strength,spread,disc_radius) on everyCamera3dthat hasAtmosphereSettings. A camera without a sky has no glare, so turning the sky off takes it too. The component is only rewritten when it changes, so a still scene does not re-extract it. There is no glare while the sun is down or the disc is switched off. - Render world.
SunGlarePassis registered withadd_render_pass("sun_glare", RenderPhase::HdrPost, 0.0, ...): after TAA and DLSS, before tonemapping, so auto exposure meters it with the rest of the frame and no upscaler treats it as noisy input. See Post-Processing for the phase model.
Visibility is measured on screen, not assumed. A measure entry point
compares a few texels inside the disc with a ring of sky just outside it and
writes the result into a 1x1 Rgba16Float history texture per view. Its blend
state is new * c + old * (1 - c) with c = 0.15 as the blend constant, so
the running average is the blend itself (no ping-pong) and settles in about a
tenth of a second at 60 FPS. That swallows the frame-to-frame noise Solari's
denoiser and camera jitter put on a disc a few pixels wide, while a cloud
crossing the sun still reads as it happens. Because it is a ratio, the test is
independent of exposure and of how much the atmosphere has dimmed the sun;
clouds, terrain and buildings all occlude it without the pass knowing about
any of them.
The pass also runs at zero strength: it clamps non-finite pixels from the disc
back into range before bloom sees them, which is needed whether or not the
glare is drawn. The pass only draws into an Rgba16Float (HDR) target.
Moon
Bevy's SunDisk is flat and untextured, so the moon is drawn by
renzora_atmosphere::moon as a real sphere with its own material
(MoonMaterial, moon.wesl) plus a second, larger glow sphere
(GLOW_EXTENT = 10 moon radii) drawn with AlphaMode::Add.
- Both follow the highest-order active camera on the default render layer, at
MOON_DISTANCE= 700 m, which keeps them inside a 1000 m far plane. - The face is not lit by the scene's sun (whose position is chosen for the
scene's lighting and would make the moon full every night). The shading
light is swung around the viewer by
Sun::moon_phase_angle: from behind the viewer at full, from the right while waxing, from the left while waning. moon_eclipseslides the Earth's shadow across the face and pulls the phase to full, where eclipses happen.- Brightness is
moon_illuminance * 8nits for the face and* 1.2for the glow, kept apart so a brighter face does not swell the halo into fog. - They are chrome, not content:
HideInHierarchy, no shadows cast or received, never saved, and despawned while the moon is down.
Clouds
renzora_clouds raymarches a spherical cloud deck: a tileable Perlin-Worley
base map for the silhouette, a 3D Worley volume to erode it, a height profile
for flat bases, and a second march toward the sun for self-shadowing.
Data
CloudsData is defined in the crate, not the contract, so the engine core
names no cloud type. Scenes saved when it lived at
renzora::clouds::CloudsData still load, because the scene loader matches a
moved type by its short name. Only the first enabled CloudsData is drawn;
two enabled at once alternate frame to frame, which the crate logs as
source (MULTIPLE enabled!).
| Group | Fields (default) |
|---|---|
| Deck | bottom_height (1690 m), top_height (2960 m), planet_radius (6,371,000 m) |
| Shape | coverage (0.45), density (0.021), scale (1.5), detail_scale (30.5), detail_strength (0.27), edge_softness (0.1), base_softness (0.3) |
| Wind | speed (40 m/s), wind_direction (220), follow_world_wind (true), morph_speed (50) |
| Lighting | color, brightness (5.5), ambient_color, shadow_color, ambient_brightness (2.5), absorption (1.0), forward_scattering (0.85), backward_scattering (-0.35), scattering_blend (0.5), powder_strength (0.3) |
| March | raymarch_steps (42), shadow_steps (6) |
| Atmosphere | atmosphere_lighting (true), horizon_color, atmosphere_strength (0.8) |
A freshly spawned World Environment gets the defaults, with coverage 0.4
when the event says outdoor_daylight. follow_world_wind is not shown in the
inspector.
Per frame
sync_clouds packs a CloudsUniform into a CloudMaterial asset and only
writes it back when a value actually changed, so a still sky is not
re-uploaded every frame:
- Light. The sun is the brightest
DirectionalLighton the default render layer (preview rigs on their own layers are ignored). Radiance scales with its illuminance over a 40,000 lux reference, so dimming the sun dims the deck. The deck fades out between 8 degrees of sun elevation and the horizon, matching the sky, which goes to night at 0. - Atmosphere coupling (
sky.rs). Bevy's atmosphere LUTs live in the render world where aMaterialcannot reach them, so the same physics is evaluated on the CPU from the sameScatteringMedium, with Bevy's own falloff and phase functions. Results are relative to a noon reference, so a noon sky multiplies the authored colours by exactly 1. With noAtmospherein the scene (a skybox, or the sky switched off) Earth's medium is measured instead, so clouds still follow the sun down. - Wind. With
follow_world_wind, heading comes from theWindStateresource and drift isspeed * (0.35 + 0.65 * strength01), sospeedkeeps its meaning and gusts are ignored. No engine crate writesWindState(a plugin from the Marketplace can); without it the default is dead calm along +X, so the deck drifts at 35% ofspeedtoward +X. Turnfollow_world_windoff to usespeedandwind_directionas authored. - Tier.
GraphicsQuality::clouds()is false at Low, which drops the deck exactly as the inspector toggle does. Below High the steps are capped at 24 view and 4 shadow.
Rendering
noise.rsbakes both noise volumes once, on the GPU, on the first frame the pipelines are ready. They are static: wind moves the sample position, not the noise.render.rsmarches the deck per 3D camera that sees the default render layer, in two steps: a compute pass namedcloudsmarches one ray per 2x2 pixel block into a half-resolution texture (lowres.wesl), after the prepass and before the main pass, skipping texels the prepass depth shows are hidden; thenDrawCloudSky, a fullscreen item at the front of the transparent pass, filters it up (composite.wesl) with a depth test that passes only where nothing was drawn, so edges against geometry stay at full resolution. The march jitters its start each frame for TAA to average.probe.rskeeps a second cubemap per camera holding the atmosphere's sky with the deck marched over it, and points the camera's environment light at it, so reflections, image-based light and Solari see the clouds. It is a separate texture because the atmosphere rewrites its own cubemap every frame from a system Renzora cannot order against. Under Solari one face is refreshed per frame; without it the whole cube is rewritten only on frames the environment map filter runs. A new cube writes all six faces at once.
Both marches are built from one source (clouds.wesl with an entry point
appended by compute_shader_source), so the sky and its reflection cannot
drift apart. Clouds cast no shadows on the ground.
Skybox
renzora_skybox is the non-physical background, from SkyboxData:
sky_mode | What sync_skybox does |
|---|---|
Color (default) | Removes Skybox; cameras clear to clear_color (default (0.4, 0.6, 0.9)) |
Procedural | Generates a 256-pixel-per-face sRGB cubemap from ProceduralSkyData (top, horizon and ground colours plus two curve exponents), regenerated only when the parameter hash changes |
Panorama | Loads panorama_sky.panorama_path, converts the equirectangular image to a cube on the AsyncComputeTaskPool, then rotates it by rotation degrees about Y at energy * 1000 brightness |
Tiled | A checkerboard level-design backdrop from TiledSkyData (tile_count 16, line_width 0.015) |
The panorama conversion runs off the main thread because a 4K panorama is
millions of texels to reproject. The face size is half the source height,
clamped to 256..2048. The source image handle is dropped once conversion
starts, and the cube is kept only on the GPU, to avoid holding both copies in
memory. A cube-based mode sets the clear colour to None.
The skybox applies to every Camera3d without IsolatedCamera. It is
independent of the atmosphere; a scene normally uses one or the other.
Distance fog
The World Environment's fog is WorldEnvironment::fog, a FogSection
(enabled false by default, mode 0 Linear, 1 Exponential, 2
ExponentialSquared, 3 Atmospheric (default), plus colour, directional
in-scatter, start 50, end 800, density 0.005, extinction,
inscattering).
Bevy's DistanceFog occupies a binding in PBR's shared mesh-view bind group,
so adding or removing it at runtime changes that layout and crashes wgpu.
renzora_engine::camera therefore attaches a DistanceFog to cameras at
spawn, and renzora_distance_fog's reconcile_world_environment only ever
updates it: a disabled section, or a camera whose source is gone, gets a
zero-density exponential falloff rather than a removal. Cameras without a
DistanceFog (utility cameras) are skipped.
The old per-effect DistanceFogSettings component is still registered so that
older scenes deserialize, but nothing syncs it.
Exporting
Each crate is an optional dependency of renzora_runtime behind a feature
(atmosphere, clouds, skybox, distance_fog), and each is an export
capability detected from the scene's type paths, so a lean export only links
the sky pieces a game uses. See
Export System.