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.

fix(postprocess): rain darkens a slope and a leaf as it does the flat, so a hillside in the rain is not cut into pale wedges

yhhd7cff8b6d6cd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9cac9c79f..8bb2ea0d8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -94,6 +94,7 @@ published separately; it ships inside the editor.
- **A terrain with texture layers no longer keeps a second copy of them in memory.** Its layer arrays were made as content the graphics device keeps a CPU copy of, to restore after a GPU loss: 12 MiB on Terrain & Water, which took the copies past their 16 MiB budget and logged a warning. The terrain now says how to make them again: after a loss it reads and packs its layer files once more and puts them back behind the same textures.
- **No "NaN is an invalid value for height" error when a project opens.** The content browser measured its grid before the editor had placed the panel, read the panel's padding as a number it was not, and gave the grid a height of NaN for that first frame.
- **A web game comes back after the GPU goes away.** A browser can take the GPU from a page (a driver reset, a laptop waking, too many tabs). Three things stood in the way of the way back, all seen on Terrain & Water: while the engine waited for its textures, the frames it refused still gathered geometry and never emptied it, until an allocation of gigabytes stopped the module; the restored context had none of the WebGL extensions the engine relies on, so an HDR scene came back black; and the terrain's page atlases were never refilled, so the ground came back flat and black. The game now recovers to the picture it had.
+- **Rain wets hillsides and plants, not only flat ground.** The rain effect darkened only what faced almost straight up, so in a storm a slope steeper than about 20 degrees stayed dry-bright beside the darkened flat, and every plant stood light on dark ground: from a distance a hillside read as pale wedges and white speckle. Everything under the rain darkens now, a little less where it faces away from the sky; standing water still only gathers on the flat.
- **A subpath of an official package resolves.** Importing `estella-plugin-…/something` from a project script no longer hangs the script build.
- **Background shader compilation, the warm-up and on-demand drawing reach a build whose quality level is Off.** A build dropped the whole `quality` block when the level was Off, though these three choices hold whatever the level: a project that switched `asyncShaderCompile`, `prewarmShaders` or `renderOnDemand` on read them in the editor and shipped a game that ignored them. The block now ships when any of them is on.
- **A terrain and a streamed world run on the Android and iOS templates.** The terrain's layer textures were refused on a device (it has no wasm heap to copy them through), and a chunked world's maker threw on every tick because QuickJS has no `AbortController`. The layers now go over as bytes, as every other texture does, and the world uses a handle of its own where the host has none.
diff --git a/fixtures/scenes/rain-wet-slope.esscene b/fixtures/scenes/rain-wet-slope.esscene
new file mode 100644
index 000000000..ca4b35b6f
--- /dev/null
+++ b/fixtures/scenes/rain-wet-slope.esscene
@@ -0,0 +1,147 @@
+{
+ "version": 4,
+ "name": "RainWetSlope",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 320,
+ "z": 480
+ },
+ "rotation": {
+ "x": -0.284,
+ "y": 0,
+ "z": 0,
+ "w": 0.9588
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 0,
+ "fov": 60,
+ "nearPlane": 10,
+ "farPlane": 3000,
+ "isActive": true,
+ "priority": 0
+ }
+ },
+ {
+ "type": "PostProcessVolume",
+ "data": {
+ "isGlobal": true,
+ "priority": 0,
+ "weight": 1,
+ "effects": [
+ {
+ "type": "rain",
+ "enabled": true,
+ "uniforms": {
+ "u_intensity": 0,
+ "u_wetness": 1,
+ "u_puddles": 0
+ }
+ }
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Flat",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -220,
+ "y": 0,
+ "z": -100
+ },
+ "scale": {
+ "x": 3.5,
+ "y": 1,
+ "z": 5
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:plane",
+ "color": {
+ "r": 0.8,
+ "g": 0.8,
+ "b": 0.8,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": false,
+ "enabled": true
+ }
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "name": "Slope",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 220,
+ "y": 80,
+ "z": -100
+ },
+ "rotation": {
+ "x": 0.342,
+ "y": 0,
+ "z": 0,
+ "w": 0.9397
+ },
+ "scale": {
+ "x": 3.5,
+ "y": 1,
+ "z": 5
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:plane",
+ "color": {
+ "r": 0.8,
+ "g": 0.8,
+ "b": 0.8,
+ "a": 1
+ },
+ "lit": false,
+ "opaque": true,
+ "cullBackfaces": false,
+ "enabled": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/sdk/src/postprocess/sources/atmosphere.ts b/sdk/src/postprocess/sources/atmosphere.ts
index d93ddcb50..586e4ddc7 100644
--- a/sdk/src/postprocess/sources/atmosphere.ts
+++ b/sdk/src/postprocess/sources/atmosphere.ts
@@ -2234,7 +2234,13 @@ void main() {
// Standing water on what is sealed (a street, a flagstone); ground as rough as soil or grass soaks it up, and is only darker.
float soaks = surface.known ? smoothstep(0.82, 0.95, surface.roughness) : 0.0;
float puddle = puddleMask(P.xz, basinCoverage(c, size, P, u_puddles, u_puddleScale), u_puddleScale) * up * wet * (1.0 - soaks);
- col *= 1.0 - 0.32 * wet * up;
+ // Rain darkens a slope and a leaf as it does the flat, a little less where it faces away from the sky: darkening only what
+ // faced straight up cut a hillside into pale wedges at one slope and left every plant light on dark ground. The surface's
+ // own normal where it wrote one (a leaf's), the depth's elsewhere.
+ vec3 Ns = surface.known ? surface.normal : N;
+ if (dot(Ns, viewDirection(P)) < 0.0) Ns = -Ns;
+ float exposed = mix(0.6, 1.0, smoothstep(0.0, 0.9, Ns.y));
+ col *= 1.0 - 0.32 * wet * exposed;
col *= 1.0 - 0.35 * puddle;
// Drops landing need drops falling: wet ground under no rain is still.
float falling = clamp(u_intensity, 0.0, 1.0) * (1.0 - shelter);
@@ -2329,7 +2335,12 @@ fn shelteredAt(W : vec3f) -> f32 {
var soaks = 0.0;
if (surface.known) { soaks = smoothstep(0.82, 0.95, surface.roughness); }
let puddle = puddleMask(P.xz, basinCoverage(c, size, P, mc.u_puddles, mc.u_puddleScale), mc.u_puddleScale) * up * wet * (1.0 - soaks);
- col = col * (1.0 - 0.32 * wet * up);
+ // See the GLSL: rain darkens what does not face straight up too.
+ var Ns = N;
+ if (surface.known) { Ns = surface.normal; }
+ if (dot(Ns, viewDirection(P)) < 0.0) { Ns = -Ns; }
+ let exposed = mix(0.6, 1.0, smoothstep(0.0, 0.9, Ns.y));
+ col = col * (1.0 - 0.32 * wet * exposed);
col = col * (1.0 - 0.35 * puddle);
let falling = clamp(mc.u_intensity, 0.0, 1.0) * (1.0 - shelter);
let near = 1.0 - smoothstep(1200.0, 3500.0, dist);
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 145db7cc0..f2055138f 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -3442,4 +3442,6 @@ export const NOTED = {
{"note":"A web game comes back after the GPU goes away."},
"fix(terrain): the page atlases are owed after a device loss, so their refill runs and the ground comes back":
{"note":"A web game comes back after the GPU goes away."},
+ "fix(postprocess): rain darkens a slope and a leaf as it does the flat, so a hillside in the rain is not cut into pale wedges":
+ {"note":"Rain wets hillsides and plants, not only flat ground."},
};
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index e0583a24e..6c8e62b66 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -777,6 +777,9 @@ export const SCENES = [
{ id: "aa-edge-post", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/aa-edge-post.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.2353,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.2392,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.749,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.7529,\"y\":0.502,\"rgb\":[128,128,128],\"tol\":64},{\"x\":0.502,\"y\":0.502,\"rgb\":[255,255,255],\"tol\":6},{\"x\":0.0784,\"y\":0.0784,\"rgb\":[0,0,0],\"tol\":6}]" } },
{ id: "edge-outline", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/edge-outline.esscene", ESTELLA_VERIFY_W: "640", ESTELLA_VERIFY_H: "480", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.2458,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.5,\"y\":0.85,\"rgb\":[129,129,129],\"tol\":12},{\"x\":0.36,\"y\":0.42,\"rgb\":[137,95,70],\"tol\":15},{\"x\":0.7,\"y\":0.45,\"rgb\":[128,128,128],\"tol\":12}]" } },
{ id: "blob-shadow", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/blob-shadow.esscene", ESTELLA_VERIFY_W: "640", ESTELLA_VERIFY_H: "480", ESTELLA_VERIFY_STEPS: "6", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.85,\"rgb\":[191,191,191],\"tol\":8},{\"x\":0.38,\"y\":0.4,\"rgb\":[204,140,102],\"tol\":10},{\"x\":0.85,\"y\":0.38,\"rgb\":[199,178,127],\"tol\":12},{\"x\":0.845,\"y\":0.475,\"rgb\":[91,91,91],\"tol\":22},{\"x\":0.61,\"y\":0.46,\"rgb\":[102,102,102],\"tol\":22},{\"x\":0.385,\"y\":0.49,\"rgb\":[124,124,124],\"tol\":22}]" } },
+ // Rain darkens a 40-degree slope as it does the flat beside it (unlit grey 204 to about 139 on both). Darkening only what faced
+ // straight up left the slope at 204, and a hillside in the rain cut into pale wedges.
+ { id: "rain-wet-slope", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/rain-wet-slope.esscene", ESTELLA_VERIFY_W: "320", ESTELLA_VERIFY_H: "240", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.25,\"y\":0.5,\"rgb\":[139,139,139],\"tol\":8},{\"x\":0.75,\"y\":0.4,\"rgb\":[140,140,140],\"tol\":8}]" } },
{ id: "ssao", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/ssao.esscene", ESTELLA_VERIFY_W: "320", ESTELLA_VERIFY_H: "240", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5016,\"y\":0.8996,\"rgb\":[191,191,191],\"tol\":6},{\"x\":0.3762,\"y\":0.4937,\"rgb\":[144,144,144],\"tol\":20},{\"x\":0.627,\"y\":0.4812,\"rgb\":[172,172,172],\"tol\":9},{\"x\":0.8527,\"y\":0.4686,\"rgb\":[147,147,147],\"tol\":9},{\"x\":0.1881,\"y\":0.5272,\"rgb\":[123,141,113],\"tol\":22},{\"x\":0.1285,\"y\":0.1967,\"rgb\":[133,136,148],\"tol\":9},{\"x\":0.627,\"y\":0.2008,\"rgb\":[179,184,199],\"tol\":5}]" } },
// The same occlusion with a neutral colour grade ahead of it in the chain: a pass
// behind another one still samples the scene's depth, and on WebGPU the colour it