Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(render): the sky scatters light like an atmosphere and carries volumetric clouds the sun lights

yhh2ef3cba3a973
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 07f3eafd3..75b852de3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@ published separately; it ships inside the editor.
### Added
- **Contact shadows and screen-space bounce light.** Contact Shadows and Screen Space GI effects add small sharp shadows at contacts and one bounce of colour between surfaces, and the weather softens the sun's shadows. `contactShadows` marches a short ray toward the scene's sun in the depth buffer; `ssgi` gathers eight rays a pixel over the G-buffer's normals at half size into a float target and averages the neighbours on the same surface before laying the light, times the receiver's colour, over the picture. The Weather component raises the sun's `sourceAngle` and lowers its `shadowStrength` as the sky clouds over.
+- **Sky.** The Sky Atmosphere effect scatters the sun's light through an atmosphere and draws volumetric clouds that the sun lights and the wind moves. The dome is single scattering through a planet's atmosphere (Rayleigh and Mie), so a sunset's reds and the afterglow come from the same calculation as noon's blue; the clouds are a slab marched against a noise density, lit through what lies between them and the sun, and a Weather's overcast raises their coverage.
- **Time of day.** A TimeOfDay component moves the sun and the moon across the sky, and a Sky Atmosphere effect draws the day, the dusk and the night. The sun is placed from the hour, the latitude and the season; the scene's directional light is aimed at it by day and at the moon by night, scaled and tinted by a day's curve, and the ambient light, baked reflections, fog and exposure follow. Sky Atmosphere draws the dome, the sun, a dusk glow, the moon and stars where there is no surface, and Weather greys it as it clouds over. A directional light that follows a panorama's sun can now be aimed by its own Transform (`aimFollowedSun`), which is what lets a panorama photographed with the sun in one place be lit by a sun that moves.
- **Weather.** A Weather component puts a scene under clear, mist, overcast, rain or storm, turns between them and cycles by itself. A preset is a set of multipliers of what the scene already has — the sun at a fraction of its strength, the fog thicker, the picture greyer — plus absolute levels for rain and wetness, so one preset fits any project. The component drives the directional and ambient lights (in play mode only), the effects the scene's volumes resolve (Height Fog, Rain, Screen Space Reflections, Colour Grade, Auto Exposure), and takes `registerWeatherPreset` for weathers of a project's own. Volumes whose effects differ only in numbers now write the numbers into the passes they have instead of rebuilding them. Reflection probes follow the weather: the ambient light scales what baked probes show and how much colour they keep. The Ambient `Light` gains `reflectionScale` and `reflectionSaturation`, which the weather drives. Rain stays off what stands under a roof, and the Weather component turns a looping rain track up and down. The frame draws the scene once from straight above, depth only, around the camera whenever a `rain` effect is in the chain, and the effect keeps wetness, puddles, ripples and streaks off ground that something stands over; `soundSource` names the `AudioSource` the weather drives.
- **Quality levels are edited in Settings.** Settings → Project → Rendering edits each quality level, including which effects it runs. **Editing level** picks Low, Medium or High and the groups below — Rendering (render scale, minimum scale, MSAA), Shadows, Reflections and particles, Post-processing — show and change that level, so a level is read the way Unity's Quality page reads: a level, then its settings by subsystem. Post-processing lists every effect the engine has, ticked where the level runs it; an unticked one is skipped at that level wherever a camera's volume asks for it, with all of its passes. Device rules — the model, GPU, memory and core conditions Auto chooses a level by — are a table, shown when the mode is Auto, that says so on a row with no condition instead of dropping it while it is typed. Only what you change is saved to `project.esproject`, as a difference to that level, so an engine default that improves later still reaches a project that never touched it; a row's "changed" mark and reset follow the default of the level it is showing. The old per-level shadow distance rows are the Shadows group's Distance now. The effects a level leaves out had been matched by the prefix of a pass's name, which found none of Auto Exposure's passes; they are now matched by effect type. A new Quality Levels page in the performance docs describes it.
diff --git a/README.md b/README.md
index 86df7c65c..9e71fedc6 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@
Estella is a **2D and 3D game engine** — sprites, tilemaps and UI as much as lit, shadowed, physically simulated 3D worlds — with a TypeScript SDK driven by a high-performance **C++** core — as WebAssembly on the web, and compiled ahead of time on native platforms. It outputs games that run in **web browsers**, on the **desktop**, in **WeChat MiniGames**, as single-file **playable ads**, and as native **Android / iOS** apps. A visual editor is available as a separate, free download.
<div align="center">
- <img src="docs/assets/day-43870a6c.webp" alt="A Paris street corner rendered in real time by the Estella engine, through a whole day: morning mist, sun, rain with puddles, and a night of lamps" width="900" />
+ <img src="docs/assets/day-411efe8a.webp" alt="A Paris street corner rendered in real time by the Estella engine, through a whole day: morning mist, sun, rain with puddles, and a night of lamps" width="900" />
<br/>
<sub><i>Amazon Lumberyard Bistro, rendered in real time by Estella (a sun that follows the sky, baked bounce light and reflections, the Neutral output transform). Scene © Amazon Lumberyard, <a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>, modified.</i></sub>
</div>
diff --git a/desktop b/desktop
index e84c96d99..269475ad4 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit e84c96d9956cacf9f20164b2c6a108b60cf4a2b4
+Subproject commit 269475ad4412ee970ef63258598f94ac35c26b08
diff --git a/docs/assets/day-411efe8a.webp b/docs/assets/day-411efe8a.webp
new file mode 100644
index 000000000..18170eaca
Binary files /dev/null and b/docs/assets/day-411efe8a.webp differ
diff --git a/docs/assets/day-43870a6c.webp b/docs/assets/day-43870a6c.webp
deleted file mode 100644
index a778afbad..000000000
Binary files a/docs/assets/day-43870a6c.webp and /dev/null differ
diff --git a/docs/astro/src/content/docs/graphics/post-processing.mdx b/docs/astro/src/content/docs/graphics/post-processing.mdx
index b46307222..d23a6b707 100644
--- a/docs/astro/src/content/docs/graphics/post-processing.mdx
+++ b/docs/astro/src/content/docs/graphics/post-processing.mdx
@@ -24,7 +24,7 @@ several can stack in one frame at no extra target cost beyond the passes.
| `fxaa` | Fast anti-aliasing | `intensity` |
| `distanceFog` | Linear fog by distance from the camera | `near`, `far`, `intensity`, colour |
| `heightFog` | Exponential height fog with the sun's glow and a hazy horizon | `density`, `heightFalloff`, `baseHeight`, `sunAzimuth`, `sunElevation`, `skyFog`, colours |
-| `skyAtmosphere` | A sky with a time of day: dome, sun, dusk glow, moon and stars, drawn where there is no surface | `intensity`, `overcast`, `moon`, `stars`, `twilight`, `sunAzimuth`, `sunElevation` |
+| `skyAtmosphere` | An atmosphere that scatters the sun's light, with sun, moon, stars and volumetric clouds, drawn where there is no surface | `intensity`, `haze`, `altitude`, `clouds`, `cloudBase`, `cloudThickness`, `windSpeed`, `overcast`, `sunAzimuth`, `sunElevation` |
| `lightShafts` | Sun rays through whatever stands in front of it | `intensity`, `sunAzimuth`, `sunElevation`, `decay`, `reach` |
| `contactShadows` | The small sharp shadows at a contact a shadow map is too coarse to hold | `intensity`, `length`, `thickness` |
| `ssgi` | One bounce of diffuse light between the surfaces the camera sees | `intensity`, `radius`, `thickness`, `maxBounce` |
diff --git a/docs/astro/src/content/docs/graphics/time-of-day.mdx b/docs/astro/src/content/docs/graphics/time-of-day.mdx
index 691b97d6e..1a9524c12 100644
--- a/docs/astro/src/content/docs/graphics/time-of-day.mdx
+++ b/docs/astro/src/content/docs/graphics/time-of-day.mdx
@@ -30,8 +30,10 @@ Add a `TimeOfDay` component to one entity.
that fall away from the moon. The crossover happens where both are dark, so nothing pops.
- **The ambient light** is scaled and tinted — blue by night, warm at dusk — and **baked reflection probes** are dimmed and
drained of colour, since they were baked under a daytime sky.
-- **The sky.** A [Sky Atmosphere](/docs/graphics/post-processing/) effect draws the dome, the sun, a dusk glow on the sun's side of the
- horizon, the moon and the stars. It takes the sun from the clock, so it never mistakes the moon-lit key light for the sun.
+- **The sky.** A [Sky Atmosphere](/docs/graphics/post-processing/) effect scatters the sun's light through a planet's atmosphere — Rayleigh for
+ the blue of the air, Mie for the haze and the glare round the sun — so the blue of noon, the red of a sunset and the afterglow
+ after it come out of one calculation. It draws the sun (white overhead, red at the horizon), the moon, the stars, and volumetric
+ clouds the sun lights and the wind moves. It takes the sun from the clock, so it never mistakes the moon-lit key light for the sun.
- **Fog.** Height Fog's colour is lit as the day is (dark at night, orange at dusk), and its glow follows the key light.
- **Exposure.** Auto Exposure's compensation is raised at night so it stays readable (a scene without one gets it on its Colour
Grade).
diff --git a/docs/astro/src/content/docs/graphics/weather.mdx b/docs/astro/src/content/docs/graphics/weather.mdx
index db6ea395a..c56578e0f 100644
--- a/docs/astro/src/content/docs/graphics/weather.mdx
+++ b/docs/astro/src/content/docs/graphics/weather.mdx
@@ -41,7 +41,7 @@ A turn is eased, so it starts and ends gently, and a finished turn lands on its
- **Reflections.** A baked reflection probe shows the sky it was baked under, so a rainy street would mirror a sunny one.
The ambient light carries `reflectionScale` and `reflectionSaturation` for exactly this: what baked probes show is
multiplied by the first and drained of colour by the second, and the weather turns both down.
-- **Sky.** A Sky Atmosphere effect is greyed by the preset's `overcast`: the sun, moon and stars are hidden as it clouds over.
+- **Sky.** A Sky Atmosphere effect takes the preset's `overcast` as cloud coverage and haze: the clouds thicken and join up, and the sun, moon and stars behind them are hidden by the same transmittance.
- **Grade and exposure.** Colour Grade's saturation and contrast are scaled, and Auto Exposure's compensation raised.
The effects are applied after the scene's volumes have blended, so a scene that fogs itself thinly stays thinner than
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx b/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx
index 573f8c3c5..5a9911eaf 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/post-processing.mdx
@@ -23,7 +23,7 @@ Estella 通过 ping-pong 帧缓冲运行全屏后处理。加一个 `PostProcess
| `fxaa` | 快速抗锯齿 | `intensity` |
| `distanceFog` | 按到相机的距离做线性雾 | `near`、`far`、`intensity`、颜色 |
| `heightFog` | 指数高度雾,带太阳辉光和朦胧的地平线 | `density`、`heightFalloff`、`baseHeight`、`sunAzimuth`、`sunElevation`、`skyFog`、颜色 |
-| `skyAtmosphere` | 有昼夜的天空:天穹、太阳、黄昏辉光、月亮和星星,画在没有表面的地方 | `intensity`、`overcast`、`moon`、`stars`、`twilight`、`sunAzimuth`、`sunElevation` |
+| `skyAtmosphere` | 散射太阳光的大气,带太阳、月亮、星星和体积云,画在没有表面的地方 | `intensity`、`haze`、`altitude`、`clouds`、`cloudBase`、`cloudThickness`、`windSpeed`、`overcast`、`sunAzimuth`、`sunElevation` |
| `lightShafts` | 太阳光穿过前方遮挡物形成的光束 | `intensity`、`sunAzimuth`、`sunElevation`、`decay`、`reach` |
| `contactShadows` | 阴影贴图太粗放不下的接触处的小而锐利的阴影 | `intensity`、`length`、`thickness` |
| `ssgi` | 相机看得见的表面之间的一次漫反射光弹射 | `intensity`、`radius`、`thickness`、`maxBounce` |
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/time-of-day.mdx b/docs/astro/src/content/docs/zh-cn/graphics/time-of-day.mdx
index 52442c0dc..e5f6b9dc9 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/time-of-day.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/time-of-day.mdx
@@ -26,8 +26,9 @@ description: 一个 TimeOfDay 组件,让太阳和月亮在天空中运行,调暗
落到地平线以下一点就熄灭。太阳落下后它对准**月亮**,强度是太阳的几百分之一,带蓝色,所以夜里的阴影背着月亮倒下。
交接发生在两者都很暗的地方,不会突变。
- **环境光**被缩放并染色——夜里偏蓝、黄昏偏暖——**烘焙反射探针**被调暗并褪色,因为它们是在白天的天空下烘焙的。
-- **天空。** [Sky Atmosphere](/docs/zh-cn/graphics/post-processing/) 特效画出天穹、太阳、地平线上太阳那一侧的黄昏辉光、月亮和星星。
- 它的太阳取自时钟,所以不会把月光下的主光当成太阳。
+- **天空。** [Sky Atmosphere](/docs/zh-cn/graphics/post-processing/) 特效让太阳光穿过一颗行星的大气层发生散射——瑞利散射给出空气的蓝,
+ 米氏散射给出雾霾和太阳周围的眩光——所以正午的蓝、日落的红和日落之后的余晖出自同一个计算。它画出太阳(头顶是白的、贴着地平线是红的)、月亮、
+ 星星,以及被太阳照亮、被风吹动的体积云。它的太阳取自时钟,所以不会把月光下的主光当成太阳。
- **雾。** Height Fog 的颜色随白天而被照亮(夜里暗、黄昏偏橙),辉光跟随主光。
- **曝光。** 夜里 Auto Exposure 的补偿被抬高,让画面保持可读(没有它的场景改加在 Colour Grade 上)。
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/weather.mdx b/docs/astro/src/content/docs/zh-cn/graphics/weather.mdx
index 6384ce82d..83387e960 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/weather.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/weather.mdx
@@ -34,7 +34,7 @@ description: 一个 Weather 组件,让场景处于晴、薄雾、阴天、雨或
天气只能把它提高。
- **反射。** 烘焙的反射探针显示的是它烘焙时的天空,所以下雨的街道会映出晴天的街道。环境光带有 `reflectionScale` 和
`reflectionSaturation` 就是为此:探针显示的内容乘以前者、按后者褪色,天气会把两者调低。
-- **天空。** Sky Atmosphere 特效会随预设的 `overcast` 变灰:天阴下来时太阳、月亮和星星随之隐去。
+- **天空。** Sky Atmosphere 特效把预设的 `overcast` 当作云量和雾霾:云变厚并连成一片,后面的太阳、月亮和星星被同一份透射率遮住。
- **调色与曝光。** Colour Grade 的饱和度和对比度被缩放,Auto Exposure 的补偿被提高。
这些效果在场景的体积混合之后才施加,所以在同一场雨里,雾设得薄的场景仍然比雾设得厚的场景薄。
diff --git a/docs/landing/day-1b5a4973.webm b/docs/landing/day-1b5a4973.webm
new file mode 100644
index 000000000..f94b5df29
Binary files /dev/null and b/docs/landing/day-1b5a4973.webm differ
diff --git a/docs/landing/day-a2d1a583.mp4 b/docs/landing/day-a2d1a583.mp4
deleted file mode 100644
index 57690a6a2..000000000
Binary files a/docs/landing/day-a2d1a583.mp4 and /dev/null differ
diff --git a/docs/landing/day-c3f82849.webm b/docs/landing/day-c3f82849.webm
deleted file mode 100644
index ae2bc1557..000000000
Binary files a/docs/landing/day-c3f82849.webm and /dev/null differ
diff --git a/docs/landing/day-cadfc12e.mp4 b/docs/landing/day-cadfc12e.mp4
new file mode 100644
index 000000000..1a2dc3519
Binary files /dev/null and b/docs/landing/day-cadfc12e.mp4 differ
diff --git a/docs/landing/index.html b/docs/landing/index.html
index f6a76e3ba..656a6aeee 100644
--- a/docs/landing/index.html
+++ b/docs/landing/index.html
@@ -452,8 +452,8 @@
<video id="hero-loop" width="1280" height="720" autoplay muted loop playsinline preload="metadata"
poster="/hero-5df1f015.png"
aria-label="A Paris street corner rendered in real time by the Estella engine, through a whole day: morning mist, a sunlit noon with long shadows, rain with wet cobbles and puddles that mirror the scene, and a night lit by lamps">
- <source src="/day-c3f82849.webm" type="video/webm" />
- <source src="/day-a2d1a583.mp4" type="video/mp4" />
+ <source src="/day-1b5a4973.webm" type="video/webm" />
+ <source src="/day-cadfc12e.mp4" type="video/mp4" />
<img src="/hero-5df1f015.png" width="1742" height="980"
alt="A Paris street corner in daylight, rendered in real time by the Estella engine: a cafe, a scooter, cobbles and sun shadows" />
</video>
diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.ts
index 206ab87a4..7cce90016 100644
--- a/sdk/src/postprocess/effects.ts
+++ b/sdk/src/postprocess/effects.ts
@@ -240,18 +240,29 @@ registerEffect({
label: 'Sky Atmosphere',
factory: () => postProcessEffects.createSkyAtmosphere(),
uniforms: [
- // How bright the day's sky is; the night's is its own.
+ // How bright the sky is.
{ name: 'u_intensity', label: 'Brightness', min: 0, max: 8, step: 0.01, defaultValue: 1 },
// How much of the sky behind the scene (a panorama, a clear colour) is kept: 0 replaces it, 1 leaves it.
{ name: 'u_panorama', label: 'Keep Background', min: 0, max: 1, step: 0.01, defaultValue: 0, neutralValue: 1 },
- // 0 is a clear sky; 1 a grey one with no sun, moon or stars. A Weather component drives it.
+ // 0 is the weather's to say not at all; 1 a sky with no break in it. A Weather component drives it.
{ name: 'u_overcast', label: 'Overcast', min: 0, max: 1, step: 0.01, defaultValue: 0 },
+ // How much haze (Mie scattering) the air holds: more is a whiter, glarier sky and a redder sunset.
+ { name: 'u_haze', label: 'Haze', min: 0, max: 8, step: 0.05, defaultValue: 1 },
+ // The camera's height above the ground the sky is seen from, in kilometres.
+ { name: 'u_altitude', label: 'Altitude', min: 0, max: 20, step: 0.1, defaultValue: 0.1 },
{ name: 'u_sunSize', label: 'Sun Size', min: 0.2, max: 8, step: 0.1, defaultValue: 1 },
{ name: 'u_sunBrightness', label: 'Sun Brightness', min: 0, max: 400, step: 1, defaultValue: 40 },
{ name: 'u_moon', label: 'Moon', min: 0, max: 4, step: 0.05, defaultValue: 1 },
{ name: 'u_stars', label: 'Stars', min: 0, max: 4, step: 0.05, defaultValue: 1 },
- // How strong the glow of dusk and dawn is on the horizon.
- { name: 'u_twilight', label: 'Twilight', min: 0, max: 2, step: 0.05, defaultValue: 1 },
+ // How much of the sky the clouds cover, 0 to 1. A weather raises it.
+ { name: 'u_clouds', label: 'Cloud Coverage', min: 0, max: 1, step: 0.01, defaultValue: 0.45, neutralValue: 0 },
+ // Where the cloud layer starts and how deep it is, in kilometres above the ground.
+ { name: 'u_cloudBase', label: 'Cloud Base', min: 0.2, max: 10, step: 0.1, defaultValue: 1.5 },
+ { name: 'u_cloudThickness', label: 'Cloud Thickness', min: 0.2, max: 8, step: 0.1, defaultValue: 2.5 },
+ { name: 'u_cloudBrightness', label: 'Cloud Brightness', min: 0, max: 4, step: 0.05, defaultValue: 1 },
+ // How fast the clouds drift (kilometres a second) and which way (degrees from +Z toward +X).
+ { name: 'u_windSpeed', label: 'Wind Speed', min: 0, max: 2, step: 0.01, defaultValue: 0.05 },
+ { name: 'u_windDirection', label: 'Wind Direction', min: 0, max: 360, step: 1, defaultValue: 60 },
// 1: the sun is the scene's directional light. 0: the two angles are. A TimeOfDay component writes them.
{ name: 'u_followSun', label: 'Follow Scene Sun', min: 0, max: 1, step: 1, defaultValue: 1, neutralValue: 1 },
{ name: 'u_sunAzimuth', label: 'Sun Azimuth', min: 0, max: 360, step: 1, defaultValue: 40 },
diff --git a/sdk/src/postprocess/postProcessEffects.ts b/sdk/src/postprocess/postProcessEffects.ts
index 10b757de6..d684c7f84 100644
--- a/sdk/src/postprocess/postProcessEffects.ts
+++ b/sdk/src/postprocess/postProcessEffects.ts
@@ -1507,14 +1507,17 @@ fn depthAt(texel : vec2i, size : vec2i) -> f32 {
},
/**
- * A sky that has a time of day: the gradient of the dome, the sun and its halo, the glow of dusk, a moon, and stars.
+ * A sky that has a time of day and weather in it: the scattering of the atmosphere, a sun that goes red as it sets, a
+ * moon, stars, and volumetric clouds that the sun lights.
*
* Drawn only where there is no surface (the depth buffer is at its far plane), so it replaces the panorama behind the
- * scene and leaves everything in front of it alone. The dome is two colours — zenith and horizon — for the day and two
- * for the night, mixed by how high the sun stands; near the horizon a warm glow gathers toward the sun's side of the
- * sky. The sun is a disc with a halo, the moon a disc standing opposite it (high when the sun is far below the
- * horizon), and the stars are points hashed from the view direction, so they hold still as the camera turns. An
- * overcast sky greys the dome and hides all three.
+ * scene and leaves everything in front of it alone. The dome is single scattering through a planet's atmosphere — Rayleigh
+ * for the blue of the air, Mie for the haze and the white glare round the sun — integrated along the view ray and, for
+ * each step of it, along the ray to the sun, so a sunset's reds and the sky after it are the same calculation as noon's
+ * blue and not separate colours blended by hand. The clouds are a slab a few kilometres up that is marched in steps
+ * against a noise density: lit by the sun through what lies between (they go dark underneath and silver at the edge, and
+ * pink at dusk since the light that reaches them is the sun's after the air), moved by the wind, and thick enough that
+ * the sun, moon and stars behind them are dimmed by the same transmittance. A Weather component raises the coverage.
*
* Where the sun is comes from the scene's own directional light, or — when the effect is told not to follow it — from two
* angles, which is what a TimeOfDay component writes. The effect is a sky and not a lighting model: what lights the
@@ -1527,11 +1530,18 @@ fn depthAt(texel : vec2i, size : vec2i) -> f32 {
#pragma param u_intensity float default(1) range(0,8)
#pragma param u_panorama float default(0) range(0,1)
#pragma param u_overcast float default(0) range(0,1)
+#pragma param u_haze float default(1) range(0,8)
+#pragma param u_altitude float default(0.1) range(0,20)
#pragma param u_sunSize float default(1) range(0.2,8)
#pragma param u_sunBrightness float default(40) range(0,400)
#pragma param u_moon float default(1) range(0,4)
#pragma param u_stars float default(1) range(0,4)
-#pragma param u_twilight float default(1) range(0,2)
+#pragma param u_clouds float default(0.45) range(0,1)
+#pragma param u_cloudBase float default(1.5) range(0.2,10)
+#pragma param u_cloudThickness float default(2.5) range(0.2,8)
+#pragma param u_cloudBrightness float default(1) range(0,4)
+#pragma param u_windSpeed float default(0.05) range(0,2)
+#pragma param u_windDirection float default(60) range(0,360)
#pragma param u_followSun float default(1) range(0,1)
#pragma param u_sunAzimuth float default(40) range(0,360)
#pragma param u_sunElevation float default(35) range(-90,90)
@@ -1545,11 +1555,32 @@ uniform sampler2D u_texture;
uniform highp sampler2D u_sceneDepth;
out vec4 fragColor;
+const float R_E = 6360.0;
+const float R_A = 6420.0;
+const vec3 BETA_R = vec3(0.0058, 0.0135, 0.0331);
+const float BETA_M = 0.021;
+const float H_R = 8.0;
+const float H_M = 1.2;
+const float SUN_I = 22.0;
+
float hash13(vec3 p) {
p = fract(p * 0.1031);
p += dot(p, p.zyx + 31.32);
return fract((p.x + p.y) * p.z);
}
+float ign(vec2 p) {
+ return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715))));
+}
+float vnoise(vec3 p) {
+ vec3 i = floor(p);
+ vec3 f = fract(p);
+ f = f * f * (3.0 - 2.0 * f);
+ float a = mix(hash13(i), hash13(i + vec3(1, 0, 0)), f.x);
+ float b = mix(hash13(i + vec3(0, 1, 0)), hash13(i + vec3(1, 1, 0)), f.x);
+ float c = mix(hash13(i + vec3(0, 0, 1)), hash13(i + vec3(1, 0, 1)), f.x);
+ float d = mix(hash13(i + vec3(0, 1, 1)), hash13(i + vec3(1, 1, 1)), f.x);
+ return mix(mix(a, b, f.y), mix(c, d, f.y), f.z);
+}
vec3 lin(vec3 c) {
#ifdef ES_LINEAR
@@ -1559,6 +1590,68 @@ vec3 lin(vec3 c) {
#endif
}
+/// Where a ray from o along d meets the sphere of radius r about the planet's centre: the two distances, or -1 for a miss.
+vec2 sphereHit(vec3 o, vec3 d, float r) {
+ float b = dot(o, d);
+ float disc = b * b - (dot(o, o) - r * r);
+ if (disc < 0.0) return vec2(-1.0);
+ float s = sqrt(disc);
+ return vec2(-b - s, -b + s);
+}
+
+/// The air between p and the top of the atmosphere along d, as (Rayleigh, Mie) optical depth; z is 0 where the planet is in the way.
+vec3 lightDepth(vec3 p, vec3 d) {
+ vec2 ground = sphereHit(p, d, R_E);
+ if (ground.y > 0.0 && ground.x > 0.0) return vec3(0.0);
+ float len = sphereHit(p, d, R_A).y;
+ float ds = len / 4.0;
+ vec2 od = vec2(0.0);
+ for (int j = 0; j < 4; ++j) {
+ vec3 q = p + d * (ds * (float(j) + 0.5));
+ od += exp(-(length(q) - R_E) / vec2(H_R, H_M)) * ds;
+ }
+ return vec3(od, 1.0);
+}
+
+/// The sky's radiance along dir, by single scattering; @p sunTrans is the sun's light by the time it reaches the viewer.
+vec3 scatter(vec3 dir, vec3 sun, float alt, float haze, out vec3 sunTrans) {
+ vec3 o = vec3(0.0, R_E + alt, 0.0);
+ float len = sphereHit(o, dir, R_A).y;
+ const int N = 16;
+ float ds = len / float(N);
+ float mu = dot(dir, sun);
+ float g = 0.76;
+ float phaseR = 3.0 / (16.0 * 3.14159265) * (1.0 + mu * mu);
+ float phaseM = 3.0 / (8.0 * 3.14159265) * ((1.0 - g * g) * (1.0 + mu * mu)) / ((2.0 + g * g) * pow(1.0 + g * g - 2.0 * g * mu, 1.5));
+ vec2 od = vec2(0.0);
+ vec3 sumR = vec3(0.0);
+ vec3 sumM = vec3(0.0);
+ for (int i = 0; i < N; ++i) {
+ vec3 p = o + dir * (ds * (float(i) + 0.5));
+ vec2 dens = exp(-(length(p) - R_E) / vec2(H_R, H_M)) * ds;
+ od += dens;
+ vec3 ol = lightDepth(p, sun);
+ if (ol.z > 0.5) {
+ vec3 attn = exp(-(BETA_R * (od.x + ol.x) + BETA_M * haze * 1.1 * (od.y + ol.y)));
+ sumR += attn * dens.x;
+ sumM += attn * dens.y;
+ }
+ }
+ vec3 st = lightDepth(o, sun);
+ sunTrans = st.z > 0.5 ? exp(-(BETA_R * st.x + BETA_M * haze * 1.1 * st.y)) : vec3(0.0);
+ return (sumR * BETA_R * phaseR + sumM * BETA_M * haze * phaseM) * SUN_I;
+}
+
+float cloudDensity(vec3 p, float coverage, float base, float thick, int octaves) {
+ float h = clamp((p.y - base) / thick, 0.0, 1.0);
+ float shape = smoothstep(0.0, 0.14, h) * smoothstep(1.0, 0.55, h);
+ vec3 q = vec3(p.x, p.y * 1.8, p.z) * 0.32;
+ float n = vnoise(q) * 0.58 + vnoise(q * 2.13) * 0.28;
+ if (octaves > 2) n += vnoise(q * 4.7) * 0.14;
+ else n += 0.07;
+ return smoothstep(1.0 - coverage, 1.0 - coverage + 0.22, n) * shape;
+}
+
void main() {
vec4 src = texture(u_texture, v_texCoord);
ivec2 size = textureSize(u_sceneDepth, 0);
@@ -1577,33 +1670,26 @@ void main() {
vec3 sun = follow ? lightDir.xyz : vec3(cos(el) * sin(az), sin(el), cos(el) * cos(az));
float se = sun.y;
- float day = smoothstep(-0.10, 0.25, se);
- float twi = exp(-se * se * 70.0);
- float up = max(dir.y, 0.0);
- float haze = pow(1.0 - up, 3.0);
-
- vec3 dayCol = mix(lin(vec3(0.12, 0.30, 0.72)), lin(vec3(0.60, 0.74, 0.92)), haze) * 2.0 * u_intensity;
- dayCol *= mix(0.12, 1.0, smoothstep(-0.12, 0.35, se));
- vec3 nightCol = mix(lin(vec3(0.003, 0.006, 0.02)), lin(vec3(0.016, 0.024, 0.06)), haze);
- vec3 col = mix(nightCol, dayCol, day);
-
- // The glow of dusk and dawn: low in the sky, and thickest on the sun's side of it.
- vec2 flatDir = dir.xz / max(length(dir.xz), 1e-4);
- vec2 flatSun = sun.xz / max(length(sun.xz), 1e-4);
- float side = max(dot(flatDir, flatSun), 0.0);
- col += lin(vec3(1.0, 0.42, 0.16)) * (twi * haze * (0.25 + 0.75 * side * side) * 1.8 * u_twilight);
-
float overcast = clamp(u_overcast, 0.0, 1.0);
- float clear = 1.0 - overcast;
-
- // The sun: a disc, a tight halo and a wide one, warm near the horizon and white above.
+ float haze = u_haze * (1.0 + overcast * 2.0);
+
+ // The dome. Below the horizon there is no sky: the ray is flattened onto it so a camera that looks down sees the haze there.
+ vec3 sdir = normalize(vec3(dir.x, max(dir.y, 0.015), dir.z));
+ vec3 sunTrans;
+ vec3 col = scatter(sdir, sun, u_altitude, haze, sunTrans) * 0.55 * u_intensity;
+ // Below the horizon there is no sky, only the dimmer light the ground sends up.
+ col *= 1.0 - 0.75 * smoothstep(0.0, -0.3, dir.y);
+ // What the air keeps of the night: a faint glow so the dome is not black where there is no moon.
+ float night = 1.0 - smoothstep(-0.10, 0.12, se);
+ col += mix(lin(vec3(0.003, 0.006, 0.02)), lin(vec3(0.016, 0.024, 0.06)), pow(1.0 - max(dir.y, 0.0), 3.0)) * night;
+ vec3 dome = col;
+
+ // The sun: a disc as bright as the light that reaches us, so it is white overhead and red at the horizon.
float cosd = dot(dir, sun);
float sunR = radians(0.265 * u_sunSize);
float disc = smoothstep(cos(sunR * 1.15), cos(sunR * 0.85), cosd);
- float halo = pow(max(cosd, 0.0), 16.0) * 0.25 + pow(max(cosd, 0.0), 256.0);
- vec3 sunCol = mix(lin(vec3(1.0, 0.55, 0.25)), lin(vec3(1.0, 0.96, 0.88)), smoothstep(0.0, 0.35, se));
- float above = smoothstep(-0.02, 0.02, dir.y) * smoothstep(-0.05, 0.0, se);
- col += sunCol * (disc * u_sunBrightness * clear + halo * (0.15 + 0.85 * clear)) * above;
+ float above = smoothstep(-0.02, 0.02, dir.y);
+ col += sunTrans * disc * u_sunBrightness * above * (1.0 - overcast);
// The moon stands opposite the sun and a little above where it would be, so it is up when the sun is well down.
float sAz = atan(sun.x, sun.z);
@@ -1615,8 +1701,7 @@ void main() {
float moonR = radians(0.26 * 2.5);
float moonDisc = smoothstep(cos(moonR * 1.1), cos(moonR * 0.9), md);
float moonGlow = pow(max(md, 0.0), 2500.0) * 0.5 + pow(max(md, 0.0), 60.0) * 0.015;
- float night = 1.0 - day;
- col += lin(vec3(0.80, 0.88, 1.0)) * ((moonDisc * 3.0 + moonGlow) * u_moon * night * clear * clear * smoothstep(-0.02, 0.04, dir.y));
+ col += lin(vec3(0.80, 0.88, 1.0)) * ((moonDisc * 3.0 + moonGlow) * u_moon * night * smoothstep(-0.02, 0.04, dir.y));
// Stars: a point in some of the cells of a lattice over the sphere, brighter and more coloured at random.
if (night > 0.02 && dir.y > 0.0 && u_stars > 0.0) {
@@ -1629,25 +1714,87 @@ void main() {
float spot = smoothstep(0.22, 0.02, length(fr - c));
float bright = (0.4 + hash13(id + 1.7) * 1.6) * (h > 0.995 ? 3.0 : 1.0);
vec3 tint = mix(lin(vec3(1.0, 0.85, 0.7)), lin(vec3(0.7, 0.8, 1.0)), hash13(id + 5.3));
- float seen = night * night * clear * clear * smoothstep(0.05, -0.15, se) * smoothstep(0.0, 0.15, dir.y) * (1.0 - 0.9 * smoothstep(0.97, 0.999, md));
+ float seen = night * night * smoothstep(0.05, -0.15, se) * smoothstep(0.0, 0.15, dir.y) * (1.0 - 0.9 * smoothstep(0.97, 0.999, md));
col += tint * (spot * bright * 2.5 * u_stars * seen);
}
}
- // An overcast sky is grey and a little darker than the one above it.
+ // Clouds: a slab marched against a noise density, lit by the sun through what is between.
+ float coverage = max(u_clouds, overcast * 0.95);
+ if (coverage > 0.01 && dir.y > 0.01) {
+ float base = u_cloudBase;
+ float thick = u_cloudThickness;
+ float tb = max(base - u_altitude, 0.0) / dir.y;
+ float tt = (base + thick - u_altitude) / dir.y;
+ const int STEPS = 16;
+ float ds = (tt - tb) / float(STEPS);
+ float jitter = ign(gl_FragCoord.xy);
+ float sigma = 1.3 * (1.0 + overcast * 1.5);
+ float wind = radians(u_windDirection);
+ vec3 drift = vec3(sin(wind), 0.0, cos(wind)) * (u_windSpeed * u_time.x);
+ float cosS = dot(dir, sun);
+ float phase = mix(0.35 + 0.65 * pow(max(cosS, 0.0), 6.0), 0.5, 0.4);
+ vec3 ambient = dome * 0.7 + lin(vec3(0.55, 0.65, 0.9)) * 0.015 * night;
+ vec3 sunLight = sunTrans * 1.2 * u_cloudBrightness;
+ float trans = 1.0;
+ vec3 lit = vec3(0.0);
+ for (int i = 0; i < STEPS; ++i) {
+ if (trans < 0.02) break;
+ float t = tb + (float(i) + jitter) * ds;
+ vec3 p = vec3(dir.x * t, u_altitude + dir.y * t, dir.z * t) + drift;
+ float d = cloudDensity(p, coverage, base, thick, 3);
+ if (d < 0.002) continue;
+ float tau = 0.0;
+ for (int k = 1; k <= 3; ++k) {
+ vec3 q = p + sun * (0.35 * float(k));
+ tau += cloudDensity(q, coverage, base, thick, 2) * 0.35 * sigma;
+ }
+ float energy = exp(-tau * 1.1) + 0.25 * exp(-tau * 0.25);
+ vec3 S = sunLight * energy * phase * 2.0 + ambient;
+ float ext = d * sigma * ds;
+ float tr = exp(-ext);
+ lit += trans * (1.0 - tr) * S;
+ trans *= tr;
+ }
+ float fade = smoothstep(0.01, 0.14, dir.y);
+ col = mix(col, col * trans + lit, fade);
+ }
+
+ // An overcast sky is also a little greyer than the cloud-free one under it.
float luma = dot(col, vec3(0.2126, 0.7152, 0.0722));
- col = mix(col, vec3(luma) * 0.85, overcast * 0.85) * (1.0 - 0.3 * overcast);
+ col = mix(col, vec3(luma), overcast * 0.5);
fragColor = vec4(mix(col, src.rgb, clamp(u_panorama, 0.0, 1.0)), src.a);
}
#pragma end
#pragma fragment wgsl
+const R_E : f32 = 6360.0;
+const R_A : f32 = 6420.0;
+const BETA_R : vec3f = vec3f(0.0058, 0.0135, 0.0331);
+const BETA_M : f32 = 0.021;
+const H_R : f32 = 8.0;
+const H_M : f32 = 1.2;
+const SUN_I : f32 = 22.0;
+
fn hash13(p0 : vec3f) -> f32 {
var p = fract(p0 * 0.1031);
p = p + dot(p, p.zyx + 31.32);
return fract((p.x + p.y) * p.z);
}
+fn ign(p : vec2f) -> f32 {
+ return fract(52.9829189 * fract(dot(p, vec2f(0.06711056, 0.00583715))));
+}
+fn vnoise(p : vec3f) -> f32 {
+ let i = floor(p);
+ var f = fract(p);
+ f = f * f * (3.0 - 2.0 * f);
+ let a = mix(hash13(i), hash13(i + vec3f(1, 0, 0)), f.x);
+ let b = mix(hash13(i + vec3f(0, 1, 0)), hash13(i + vec3f(1, 1, 0)), f.x);
+ let c = mix(hash13(i + vec3f(0, 0, 1)), hash13(i + vec3f(1, 0, 1)), f.x);
+ let d = mix(hash13(i + vec3f(0, 1, 1)), hash13(i + vec3f(1, 1, 1)), f.x);
+ return mix(mix(a, b, f.y), mix(c, d, f.y), f.z);
+}
fn lin(c : vec3f) -> vec3f {
#ifdef ES_LINEAR
@@ -1657,6 +1804,70 @@ fn lin(c : vec3f) -> vec3f {
#endif
}
+fn sphereHit(o : vec3f, d : vec3f, r : f32) -> vec2f {
+ let b = dot(o, d);
+ let disc = b * b - (dot(o, o) - r * r);
+ if (disc < 0.0) { return vec2f(-1.0); }
+ let s = sqrt(disc);
+ return vec2f(-b - s, -b + s);
+}
+
+fn lightDepth(p : vec3f, d : vec3f) -> vec3f {
+ let ground = sphereHit(p, d, R_E);
+ if (ground.y > 0.0 && ground.x > 0.0) { return vec3f(0.0); }
+ let len = sphereHit(p, d, R_A).y;
+ let ds = len / 4.0;
+ var od = vec2f(0.0);
+ for (var j : i32 = 0; j < 4; j = j + 1) {
+ let q = p + d * (ds * (f32(j) + 0.5));
+ od = od + exp(-(length(q) - R_E) / vec2f(H_R, H_M)) * ds;
+ }
+ return vec3f(od, 1.0);
+}
+
+struct Scatter { radiance : vec3f, sunTrans : vec3f };
+
+fn scatter(dir : vec3f, sun : vec3f, alt : f32, haze : f32) -> Scatter {
+ let o = vec3f(0.0, R_E + alt, 0.0);
+ let len = sphereHit(o, dir, R_A).y;
+ let N = 16;
+ let ds = len / f32(N);
+ let mu = dot(dir, sun);
+ let g = 0.76;
+ let phaseR = 3.0 / (16.0 * 3.14159265) * (1.0 + mu * mu);
+ let phaseM = 3.0 / (8.0 * 3.14159265) * ((1.0 - g * g) * (1.0 + mu * mu)) / ((2.0 + g * g) * pow(1.0 + g * g - 2.0 * g * mu, 1.5));
+ var od = vec2f(0.0);
+ var sumR = vec3f(0.0);
+ var sumM = vec3f(0.0);
+ for (var i : i32 = 0; i < N; i = i + 1) {
+ let p = o + dir * (ds * (f32(i) + 0.5));
+ let dens = exp(-(length(p) - R_E) / vec2f(H_R, H_M)) * ds;
+ od = od + dens;
+ let ol = lightDepth(p, sun);
+ if (ol.z > 0.5) {
+ let attn = exp(-(BETA_R * (od.x + ol.x) + BETA_M * haze * 1.1 * (od.y + ol.y)));
+ sumR = sumR + attn * dens.x;
+ sumM = sumM + attn * dens.y;
+ }
+ }
+ let st = lightDepth(o, sun);
+ var trans = vec3f(0.0);
+ if (st.z > 0.5) { trans = exp(-(BETA_R * st.x + BETA_M * haze * 1.1 * st.y)); }
+ var out : Scatter;
+ out.radiance = (sumR * BETA_R * phaseR + sumM * BETA_M * haze * phaseM) * SUN_I;
+ out.sunTrans = trans;
+ return out;
+}
+
+fn cloudDensity(p : vec3f, coverage : f32, base : f32, thick : f32, octaves : i32) -> f32 {
+ let h = clamp((p.y - base) / thick, 0.0, 1.0);
+ let shape = smoothstep(0.0, 0.14, h) * smoothstep(1.0, 0.55, h);
+ let q = vec3f(p.x, p.y * 1.8, p.z) * 0.32;
+ var n = vnoise(q) * 0.58 + vnoise(q * 2.13) * 0.28;
+ if (octaves > 2) { n = n + vnoise(q * 4.7) * 0.14; } else { n = n + 0.07; }
+ return smoothstep(1.0 - coverage, 1.0 - coverage + 0.22, n) * shape;
+}
+
@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
let src = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);
let size = vec2i(textureDimensions(t7, 0));
@@ -1674,30 +1885,23 @@ fn lin(c : vec3f) -> vec3f {
if (follow) { sun = found.dir.xyz; }
let se = sun.y;
- let day = smoothstep(-0.10, 0.25, se);
- let twi = exp(-se * se * 70.0);
- let up = max(dir.y, 0.0);
- let haze = pow(1.0 - up, 3.0);
-
- let dayCol = mix(lin(vec3f(0.12, 0.30, 0.72)), lin(vec3f(0.60, 0.74, 0.92)), haze) * 2.0 * mc.u_intensity * mix(0.12, 1.0, smoothstep(-0.12, 0.35, se));
- let nightCol = mix(lin(vec3f(0.003, 0.006, 0.02)), lin(vec3f(0.016, 0.024, 0.06)), haze);
- var col = mix(nightCol, dayCol, day);
-
- let flatDir = dir.xz / max(length(dir.xz), 1e-4);
- let flatSun = sun.xz / max(length(sun.xz), 1e-4);
- let side = max(dot(flatDir, flatSun), 0.0);
- col = col + lin(vec3f(1.0, 0.42, 0.16)) * (twi * haze * (0.25 + 0.75 * side * side) * 1.8 * mc.u_twilight);
-
let overcast = clamp(mc.u_overcast, 0.0, 1.0);
- let clear = 1.0 - overcast;
+ let haze = mc.u_haze * (1.0 + overcast * 2.0);
+
+ let sdir = normalize(vec3f(dir.x, max(dir.y, 0.015), dir.z));
+ let sc = scatter(sdir, sun, mc.u_altitude, haze);
+ let sunTrans = sc.sunTrans;
+ var col = sc.radiance * 0.55 * mc.u_intensity;
+ col = col * (1.0 - 0.75 * smoothstep(0.0, -0.3, dir.y));
+ let night = 1.0 - smoothstep(-0.10, 0.12, se);
+ col = col + mix(lin(vec3f(0.003, 0.006, 0.02)), lin(vec3f(0.016, 0.024, 0.06)), pow(1.0 - max(dir.y, 0.0), 3.0)) * night;
+ let dome = col;
let cosd = dot(dir, sun);
let sunR = radians(0.265 * mc.u_sunSize);
let disc = smoothstep(cos(sunR * 1.15), cos(sunR * 0.85), cosd);
- let halo = pow(max(cosd, 0.0), 16.0) * 0.25 + pow(max(cosd, 0.0), 256.0);
- let sunCol = mix(lin(vec3f(1.0, 0.55, 0.25)), lin(vec3f(1.0, 0.96, 0.88)), smoothstep(0.0, 0.35, se));
- let above = smoothstep(-0.02, 0.02, dir.y) * smoothstep(-0.05, 0.0, se);
- col = col + sunCol * (disc * mc.u_sunBrightness * clear + halo * (0.15 + 0.85 * clear)) * above;
+ let above = smoothstep(-0.02, 0.02, dir.y);
+ col = col + sunTrans * disc * mc.u_sunBrightness * above * (1.0 - overcast);
let sAz = atan2(sun.x, sun.z);
let sEl = asin(clamp(sun.y, -1.0, 1.0));
@@ -1708,8 +1912,7 @@ fn lin(c : vec3f) -> vec3f {
let moonR = radians(0.26 * 2.5);
let moonDisc = smoothstep(cos(moonR * 1.1), cos(moonR * 0.9), md);
let moonGlow = pow(max(md, 0.0), 2500.0) * 0.5 + pow(max(md, 0.0), 60.0) * 0.015;
- let night = 1.0 - day;
- col = col + lin(vec3f(0.80, 0.88, 1.0)) * ((moonDisc * 3.0 + moonGlow) * mc.u_moon * night * clear * clear * smoothstep(-0.02, 0.04, dir.y));
+ col = col + lin(vec3f(0.80, 0.88, 1.0)) * ((moonDisc * 3.0 + moonGlow) * mc.u_moon * night * smoothstep(-0.02, 0.04, dir.y));
if (night > 0.02 && dir.y > 0.0 && mc.u_stars > 0.0) {
let p = dir * 180.0;
@@ -1722,13 +1925,53 @@ fn lin(c : vec3f) -> vec3f {
var bright = 0.4 + hash13(id + 1.7) * 1.6;
if (h > 0.995) { bright = bright * 3.0; }
let tint = mix(lin(vec3f(1.0, 0.85, 0.7)), lin(vec3f(0.7, 0.8, 1.0)), hash13(id + 5.3));
- let seen = night * night * clear * clear * smoothstep(0.05, -0.15, se) * smoothstep(0.0, 0.15, dir.y) * (1.0 - 0.9 * smoothstep(0.97, 0.999, md));
+ let seen = night * night * smoothstep(0.05, -0.15, se) * smoothstep(0.0, 0.15, dir.y) * (1.0 - 0.9 * smoothstep(0.97, 0.999, md));
col = col + tint * (spot * bright * 2.5 * mc.u_stars * seen);
}
}
+ let coverage = max(mc.u_clouds, overcast * 0.95);
+ if (coverage > 0.01 && dir.y > 0.01) {
+ let base = mc.u_cloudBase;
+ let thick = mc.u_cloudThickness;
+ let tb = max(base - mc.u_altitude, 0.0) / dir.y;
+ let tt = (base + thick - mc.u_altitude) / dir.y;
+ let STEPS = 16;
+ let ds = (tt - tb) / f32(STEPS);
+ let jitter = ign(v.pos.xy);
+ let sigma = 1.3 * (1.0 + overcast * 1.5);
+ let wind = radians(mc.u_windDirection);
+ let drift = vec3f(sin(wind), 0.0, cos(wind)) * (mc.u_windSpeed * tc.u_time.x);
+ let cosS = dot(dir, sun);
+ let phase = mix(0.35 + 0.65 * pow(max(cosS, 0.0), 6.0), 0.5, 0.4);
+ let ambient = dome * 0.7 + lin(vec3f(0.55, 0.65, 0.9)) * 0.015 * night;
+ let sunLight = sunTrans * 1.2 * mc.u_cloudBrightness;
+ var trans = 1.0;
+ var lit = vec3f(0.0);
+ for (var i : i32 = 0; i < STEPS; i = i + 1) {
+ if (trans < 0.02) { break; }
+ let t = tb + (f32(i) + jitter) * ds;
+ let p = vec3f(dir.x * t, mc.u_altitude + dir.y * t, dir.z * t) + drift;
+ let d = cloudDensity(p, coverage, base, thick, 3);
+ if (d < 0.002) { continue; }
+ var tau = 0.0;
+ for (var k : i32 = 1; k <= 3; k = k + 1) {
+ let q = p + sun * (0.35 * f32(k));
+ tau = tau + cloudDensity(q, coverage, base, thick, 2) * 0.35 * sigma;
+ }
+ let energy = exp(-tau * 1.1) + 0.25 * exp(-tau * 0.25);
+ let S = sunLight * energy * phase * 2.0 + ambient;
+ let ext = d * sigma * ds;
+ let tr = exp(-ext);
+ lit = lit + trans * (1.0 - tr) * S;
+ trans = trans * tr;
+ }
+ let fade = smoothstep(0.01, 0.14, dir.y);
+ col = mix(col, col * trans + lit, fade);
+ }
+
let luma = dot(col, vec3f(0.2126, 0.7152, 0.0722));
- col = mix(col, vec3f(luma) * 0.85, overcast * 0.85) * (1.0 - 0.3 * overcast);
+ col = mix(col, vec3f(luma), overcast * 0.5);
return vec4f(mix(col, src.rgb, clamp(mc.u_panorama, 0.0, 1.0)), src.a);
}
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index e9d0a7938..47f12e518 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -2493,6 +2493,8 @@ export const NOTED = {
{"note":"Skinned meshes are followed by their bones, from the palette they were last drawn with."},
"feat(render): fog follows the scene's sun and can walk the air against its shadow map":
{"note":"Height Fog and Light Shafts follow the scene's own sun, and Height Fog can carry the sun's shadows as volumetric light."},
+ "feat(render): the sky scatters light like an atmosphere and carries volumetric clouds the sun lights":
+ {"note":"The Sky Atmosphere effect scatters the sun's light through an atmosphere and draws volumetric clouds that the sun lights and the wind moves."},
"feat(runtime): a TimeOfDay component moves the sun and the moon across the sky and draws the day, the dusk and the night":
{"note":"A TimeOfDay component moves the sun and the moon across the sky, and a Sky Atmosphere effect draws the day, the dusk and the night."},
"fix(render): the dusk sky is dimmer and warmer, the moon is a disc, and an overcast sky hides the moon and stars":