Implement moon in terrain/weather#1549
Implement moon in terrain/weather#1549Anthony-Gaudino wants to merge 12 commits intoturanszkij:masterfrom
Conversation
Add moon support to the scene and editor: - Add moon parameters to WeatherComponent (direction, color, intensity, angular radius, phase, texture, mip bias). - Create EnsureMoonLight to auto-create/sync a directional moon light entity (created automatically when terrain/sun is added). - Render lunar disk in the sky shader and expose a moon texture picker in the Weather window. - Expose moon controls to Lua and serialize moon settings with the scene. - Wire editor UI (Weather panel) to control moon orientation and appearance.
Enable the moon to illuminate volumetric clouds by streaming moon lighting parameters to the GPU and sampling them during the volumetric cloud scattering pass: - Export moon direction/color/intensity/phase to GPU via ShaderInterop_Weather. - Add moon light helpers to globals.hlsli for shareable math/phase evaluation. - Update volumetricCloud_renderCS.hlsl to include moon scattering, rim-lighting, and simple self-shadowing from the lunar direction. - Ensure wiScene/Weather updates push moon parameters to shader constant buffers; add minor serialization/UI sync where needed. Note: this change affects cloud appearance at night; tune moon intensity and phase controls and rebuild shader cache after merging.
Extend moon lighting with shadow map support: track its directional light index alongside the sun, feed it through the renderer's light buffer, and sample the cascade array in sky/cloud shaders so moonlit scenes receive proper shadowing.
Implement dynamic moon phases so the visible disk, halo, and moonlight intensity depend on sun/moon alignment. The renderer now derives a phase visibility factor per frame, scales moon directional light output, and the sky shader uses that same value to shade crescents and gibbous shapes procedurally, providing consistent night lighting as sun–moon directions change.
Extend the dynamic sky moon disk shading to animate its lit hemisphere. The shader now warps the local normal toward the sun, layers time-driven crater detail, and adds a subtle rim glow so crescents evolve smoothly as phase visibility changes.
Add an eclipse strength scalar to WeatherComponent, serialize it, and feed it to the sky shader so designers can dim the moon disk, halo, and moonlight on demand.
Add a weather flag and UI toggle that detects when the Moon moves into Earth's shadow, dims the disk/light automatically, and serializes the state with archive version 99. The editor slider can still override the effect when automation is off, and Lua bindings expose the new control for scripts.
Add solar eclipse pipeline including weather controls, shaders, renderer, and serialization - extend WeatherComponent, serialization, and Lua bindings with sun eclipse automation - thread eclipse factor through shader interop, realistic sky shading, and directional light scaling - expose solar eclipse sliders/toggles in the editor and reset defaults when weather is missing - bump archive/component versions and update resolver logic to keep moon lighting consistent
turanszkij
left a comment
There was a problem hiding this comment.
Haven't checked everything, just a quick try and some observations.
- When I place a terrain, now there are two directional lights, sun and moon. Moon cannot be rotated like the sun
- Moon can be rotated only inside weather settings, but I think it should be working like the sun. It should be active only if someone puts a directional light, and for example tags it as moon
- It looks like moon is lit on the other side of where it should be relative to the sun-moon directions
- I think the moon halo effect is not necessary, since it is not the same shape as the moon it looks out of place. Maybe we can just rely on the bloom effect picking up a bright moon, or it could be also handled by the lensflare system
- Moon should be optional, just like the sun. Especially moon shadows, we don't want to render them usually, only when there is no sun. Moon parameters on a directional light could work better, because that can be then placed like the sun.
Good work so far!
| @@ -1,5 +1,12 @@ | |||
| This file contains changelog of wi::Archive versions | |||
|
|
|||
| 100: serialized WeatherComponent sun eclipse controls | |||
There was a problem hiding this comment.
These changes must go into the component versioning now, the versions are declared in wiScene.h in the ComponentManager declarations. Also, make just one version for the pull request, no need to make multiple versions, all new changes can go into the next version.
| { | ||
| // this should always be only INCREMENTED and only if a new serialization is implemeted somewhere! | ||
| static constexpr uint64_t __archiveVersion = 93; | ||
| static constexpr uint64_t __archiveVersion = 100; |
There was a problem hiding this comment.
Same as above, this must go into the WeatherComponent's own versioning instead.
| XMVECTOR moon = XMLoadFloat3(&moon_dir); | ||
| const float sun_len_sq = XMVectorGetX(XMVector3LengthSq(sun)); | ||
| const float moon_len_sq = XMVectorGetX(XMVector3LengthSq(moon)); | ||
| if (!std::isfinite(sun_len_sq) || !std::isfinite(moon_len_sq) || sun_len_sq < 1e-6f || moon_len_sq < 1e-6f) |
There was a problem hiding this comment.
We should avoid all these std::isfinite calls, instead make it to never be infinite (check that source vector is not zero if you must). Then we also don't need to include cmath.
|
I found a problem where playing with the rain amount can cause a crash |
@socialtwisty could you please try to replicate the crash in the main branch to check if this is crash is related to this branch or not. |


Adds a moon when a terrain is added.
The moon is a second
Directional light, so it has it's own light and casts shadows.Users can load a texture for the moon.
Moon properties are accessible in the Weather component.
Moon, sun and earth lighting interactions simulations are implemented, for example, the earth shadow is cast on the moon.
Tested on Linux with Vulkan.
Current issues:
Help would be appreciated.