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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(post): sky and clouds place the cloud layer from the camera's plane under an orthographic camera; oracle scenes for the sky dome and cloud shadows
yhh469d2a8bc6fe
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7dfe09c4d..aca94d55a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,7 +19,7 @@ published separately; it ships inside the editor.- **A terrain brush stroke no longer makes the ground vanish for a moment.** An edited page of the ground used to be thrown away at once and rebuilt over the next frames, so the touched area had no ground to draw until it was done; it now goes on being drawn as it was, and changes in place.- **Voxel Ground compiles on WebGPU again.** The Model shader's new wet-ground map left the voxel ground one texture past what a shader has units for, so its last texture was dropped and the whole shader was refused (`unresolved value 'u_wetMask'`). Voxel ground takes no wet map.- **Several editors open at once can be told apart by an agent, and each grants on its own.** An editor advertises itself in a file of its own (its process id, its project, its port, its permission) instead of the one file the last editor to start overwrote. An agent attached to more than one gets `list_editors` and `select_editor` (or `--instance` / `ESTELLA_MCP_INSTANCE`), and until it chooses it is refused with the list rather than sent to whichever window won. It then drives the editor it chose and no other. The Read only / Can edit permission belongs to the editor window it is switched in and every editor starts read-only; it is no longer a saved setting that a second editor inherited. The Connect AI Tools dialog shows which editor it is.-- **Fog works under an orthographic camera.** Distance Fog, Height Fog (and its volumetric pass) and Underwater measured their ray from depth 0, which for an orthographic eye is a plane as far behind the camera as the far plane is ahead (the projection runs from -far to far so 2D content behind the camera still draws). Distance Fog read every surface as past its end and fogged a scene to full colour at any near and far, Height Fog added a camera-length of extra air, and Underwater took the camera for being above the water and drew nothing. They now start from the plane the camera stands in. Perspective cameras are unchanged. Found by the closed-form render checks in `tools/oracle`, which draw spheres, floors and patches whose answer is a formula.+- **Fog, water and sky work under an orthographic camera.** Distance Fog, Height Fog (and its volumetric pass), Underwater, Sky Atmosphere and its clouds measured their ray from depth 0, which for an orthographic eye is a plane as far behind the camera as the far plane is ahead (the projection runs from -far to far so 2D content behind the camera still draws). Distance Fog read every surface as past its end and fogged a scene to full colour at any near and far, Height Fog added a camera-length of extra air, Underwater took the camera for being above the water and drew nothing, and the cloud layer, placed by that height, stood kilometres off, so a floor above the clouds was still in their shadow. They now start from the plane the camera stands in. Perspective cameras are unchanged. Found by the closed-form render checks in `tools/oracle`, which draw spheres, floors and patches whose answer is a formula.### Changeddiff --git a/fixtures/scenes/oracle-cloud-shadow-clear-ortho.esscene b/fixtures/scenes/oracle-cloud-shadow-clear-ortho.esscenenew file mode 100644index 000000000..47d03741d--- /dev/null+++ b/fixtures/scenes/oracle-cloud-shadow-clear-ortho.esscene@@ -0,0 +1,125 @@+{+ "version": 4,+ "name": "oracle-cloud-shadow-clear-ortho",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 400,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 1.8,+ "y": 0.1,+ "z": 1.8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.8,+ "g": 0.8,+ "b": 0.8,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Look",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "skyAtmosphere",+ "enabled": true,+ "uniforms": {+ "u_clouds": 1,+ "u_overcast": 1,+ "u_cloudShadow": 1,+ "u_unitsPerKm": 1000,+ "u_sunElevation": 40,+ "u_sunAzimuth": 40,+ "u_altitude": 5,+ "u_windSpeed": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-cloud-shadow-clear-perspective.esscene b/fixtures/scenes/oracle-cloud-shadow-clear-perspective.esscenenew file mode 100644index 000000000..954816cb6--- /dev/null+++ b/fixtures/scenes/oracle-cloud-shadow-clear-perspective.esscene@@ -0,0 +1,126 @@+{+ "version": 4,+ "name": "oracle-cloud-shadow-clear-perspective",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 400,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0,+ "fov": 40+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 1.8,+ "y": 0.1,+ "z": 1.8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.8,+ "g": 0.8,+ "b": 0.8,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Look",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "skyAtmosphere",+ "enabled": true,+ "uniforms": {+ "u_clouds": 1,+ "u_overcast": 1,+ "u_cloudShadow": 1,+ "u_unitsPerKm": 1000,+ "u_sunElevation": 40,+ "u_sunAzimuth": 40,+ "u_altitude": 5,+ "u_windSpeed": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-cloud-shadow-under-ortho.esscene b/fixtures/scenes/oracle-cloud-shadow-under-ortho.esscenenew file mode 100644index 000000000..0cce2c50d--- /dev/null+++ b/fixtures/scenes/oracle-cloud-shadow-under-ortho.esscene@@ -0,0 +1,125 @@+{+ "version": 4,+ "name": "oracle-cloud-shadow-under-ortho",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 400,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 1.8,+ "y": 0.1,+ "z": 1.8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.8,+ "g": 0.8,+ "b": 0.8,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Look",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "skyAtmosphere",+ "enabled": true,+ "uniforms": {+ "u_clouds": 1,+ "u_overcast": 1,+ "u_cloudShadow": 1,+ "u_unitsPerKm": 1000,+ "u_sunElevation": 40,+ "u_sunAzimuth": 40,+ "u_altitude": 2.2,+ "u_windSpeed": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-cloud-shadow-under-perspective.esscene b/fixtures/scenes/oracle-cloud-shadow-under-perspective.esscenenew file mode 100644index 000000000..1e7b3ca5d--- /dev/null+++ b/fixtures/scenes/oracle-cloud-shadow-under-perspective.esscene@@ -0,0 +1,126 @@+{+ "version": 4,+ "name": "oracle-cloud-shadow-under-perspective",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 400,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0,+ "fov": 40+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Floor",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 1.8,+ "y": 0.1,+ "z": 1.8+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.8,+ "g": 0.8,+ "b": 0.8,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Look",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "skyAtmosphere",+ "enabled": true,+ "uniforms": {+ "u_clouds": 1,+ "u_overcast": 1,+ "u_cloudShadow": 1,+ "u_unitsPerKm": 1000,+ "u_sunElevation": 40,+ "u_sunAzimuth": 40,+ "u_altitude": 2.2,+ "u_windSpeed": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-sky-afternoon.esscene b/fixtures/scenes/oracle-sky-afternoon.esscenenew file mode 100644index 000000000..6d61a4cf6--- /dev/null+++ b/fixtures/scenes/oracle-sky-afternoon.esscene@@ -0,0 +1,85 @@+{+ "version": 4,+ "name": "oracle-sky-afternoon",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 0.3303660895493522,+ "x": 0.08852132690137689,+ "y": 0.9076733711903686,+ "z": -0.24321034680169393+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0,+ "fov": 70+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Look",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "skyAtmosphere",+ "enabled": true,+ "uniforms": {+ "u_clouds": 0,+ "u_sunElevation": 35,+ "u_sunAzimuth": 40,+ "u_haze": 1,+ "u_intensity": 0.5,+ "u_altitude": 0.1,+ "u_sunBrightness": 40+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-sky-hazy.esscene b/fixtures/scenes/oracle-sky-hazy.esscenenew file mode 100644index 000000000..63aa158db--- /dev/null+++ b/fixtures/scenes/oracle-sky-hazy.esscene@@ -0,0 +1,85 @@+{+ "version": 4,+ "name": "oracle-sky-hazy",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 0.3303660895493522,+ "x": 0.08852132690137689,+ "y": 0.9076733711903686,+ "z": -0.24321034680169393+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0,+ "fov": 70+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Look",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "skyAtmosphere",+ "enabled": true,+ "uniforms": {+ "u_clouds": 0,+ "u_sunElevation": 35,+ "u_sunAzimuth": 40,+ "u_haze": 3,+ "u_intensity": 0.4,+ "u_altitude": 0.1,+ "u_sunBrightness": 40+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-sky-low-sun.esscene b/fixtures/scenes/oracle-sky-low-sun.esscenenew file mode 100644index 000000000..a75597153--- /dev/null+++ b/fixtures/scenes/oracle-sky-low-sun.esscene@@ -0,0 +1,85 @@+{+ "version": 4,+ "name": "oracle-sky-low-sun",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": -0.2935778713738289,+ "x": -0.0650846471536534,+ "y": 0.9311100509380921,+ "z": -0.2064221286261709+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0,+ "fov": 70+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Look",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "skyAtmosphere",+ "enabled": true,+ "uniforms": {+ "u_clouds": 0,+ "u_sunElevation": 8,+ "u_sunAzimuth": 40,+ "u_haze": 1,+ "u_intensity": 0.5,+ "u_altitude": 0.1,+ "u_sunBrightness": 40+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-sky-noon.esscene b/fixtures/scenes/oracle-sky-noon.esscenenew file mode 100644index 000000000..070ecbfb9--- /dev/null+++ b/fixtures/scenes/oracle-sky-noon.esscene@@ -0,0 +1,85 @@+{+ "version": 4,+ "name": "oracle-sky-noon",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": -0.16561121050749114,+ "x": -0.05221701409779434,+ "y": 0.939227847276016,+ "z": -0.29613740272754274+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0,+ "fov": 70+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Look",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "skyAtmosphere",+ "enabled": true,+ "uniforms": {+ "u_clouds": 0,+ "u_sunElevation": 65,+ "u_sunAzimuth": 40,+ "u_haze": 1,+ "u_intensity": 0.5,+ "u_altitude": 0.1,+ "u_sunBrightness": 40+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-sky-sun-glow-low.esscene b/fixtures/scenes/oracle-sky-sun-glow-low.esscenenew file mode 100644index 000000000..07419bf46--- /dev/null+++ b/fixtures/scenes/oracle-sky-sun-glow-low.esscene@@ -0,0 +1,85 @@+{+ "version": 4,+ "name": "oracle-sky-sun-glow-low",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": -0.33947077704170586,+ "x": -0.04168177029843368,+ "y": 0.9326882944868016,+ "z": -0.1145197226978409+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0,+ "fov": 70+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Look",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "skyAtmosphere",+ "enabled": true,+ "uniforms": {+ "u_clouds": 0,+ "u_sunElevation": 14,+ "u_sunAzimuth": 40,+ "u_haze": 1,+ "u_intensity": 0.06,+ "u_altitude": 0.1,+ "u_sunBrightness": 1+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-sky-sun-glow.esscene b/fixtures/scenes/oracle-sky-sun-glow.esscenenew file mode 100644index 000000000..3dc9b429b--- /dev/null+++ b/fixtures/scenes/oracle-sky-sun-glow.esscene@@ -0,0 +1,85 @@+{+ "version": 4,+ "name": "oracle-sky-sun-glow",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": -0.3261904081870283,+ "x": -0.10284744064531129,+ "y": 0.8962007809365465,+ "z": -0.28257102082169233+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0,+ "fov": 70+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Look",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "skyAtmosphere",+ "enabled": true,+ "uniforms": {+ "u_clouds": 0,+ "u_sunElevation": 35,+ "u_sunAzimuth": 40,+ "u_haze": 1,+ "u_intensity": 0.08,+ "u_altitude": 0.1,+ "u_sunBrightness": 1+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/sdk/src/postprocess/sources/atmosphere.ts b/sdk/src/postprocess/sources/atmosphere.tsindex b519a56e6..8431a0e4d 100644--- a/sdk/src/postprocess/sources/atmosphere.ts+++ b/sdk/src/postprocess/sources/atmosphere.ts@@ -389,6 +389,10 @@ const float BETA_M = 0.021;const float H_R = 8.0;const float H_M = 1.2;const float SUN_I = 22.0;+/// Where a view ray starts: the near plane of a perspective eye. An orthographic eye's depth range runs from far BEHIND the camera to far ahead of it+/// (the projection is built with near = -far), so depth 0 is that far-behind plane, kilometres above a camera that stands on the ground: the plane+/// the camera stands in is mid-depth. The cloud layer is placed by this height, so a start behind the camera moves the clouds and their shadows.+vec3 rayStart(vec2 uv) { return worldFromDepth(uv, u_camera.w > 0.5 ? 0.0 : 0.5); }float hash13(vec3 p) {p = fract(p * 0.1031);@@ -551,7 +555,7 @@ void main() {bool geometry = covered ? (depth < 1.0 && src.a > 0.999) : depth < 1.0;if (geometry && u_cloudShadow <= 0.001) { fragColor = src; return; }- vec3 entry = worldFromDepth(v_texCoord, 0.0);+ vec3 entry = rayStart(v_texCoord);vec3 dir = normalize(worldFromDepth(v_texCoord, 1.0) - entry);vec4 lightDir, lightColor;@@ -661,6 +665,8 @@ const BETA_M : f32 = 0.021;const H_R : f32 = 8.0;const H_M : f32 = 1.2;const SUN_I : f32 = 22.0;+/// Where a view ray starts (see the GLSL twin): the near plane of a perspective eye, the plane the camera stands in for an orthographic one.+fn rayStart(uv : vec2f) -> vec3f { return worldFromDepth(uv, select(0.5, 0.0, frame.camera.w > 0.5)); }fn hash13(p0 : vec3f) -> f32 {var p = fract(p0 * 0.1031);@@ -830,7 +836,7 @@ fn upsampledShadow(uv : vec2f, P : vec3f, entry : vec3f) -> ShadowRead {let geometry = (covered && depth < 1.0 && src.a > 0.999) || (!covered && depth < 1.0);if (geometry && mc.u_cloudShadow <= 0.001) { return src; }- let entry = worldFromDepth(v.v_texCoord, 0.0);+ let entry = rayStart(v.v_texCoord);var dir = normalize(worldFromDepth(v.v_texCoord, 1.0) - entry);let found = findSun();@@ -998,6 +1004,10 @@ const float BETA_M = 0.021;const float H_R = 8.0;const float H_M = 1.2;const float SUN_I = 22.0;+/// Where a view ray starts: the near plane of a perspective eye. An orthographic eye's depth range runs from far BEHIND the camera to far ahead of it+/// (the projection is built with near = -far), so depth 0 is that far-behind plane, kilometres above a camera that stands on the ground: the plane+/// the camera stands in is mid-depth. The cloud layer is placed by this height, so a start behind the camera moves the clouds and their shadows.+vec3 rayStart(vec2 uv) { return worldFromDepth(uv, u_camera.w > 0.5 ? 0.0 : 0.5); }float hash13(vec3 p) {p = fract(p * 0.1031);@@ -1099,7 +1109,7 @@ void main() {// the alpha; a surface texel holds the cloud shadow it lies in, its light in the red and minus that in the alpha.if (geometry && u_cloudShadow <= 0.001) { fragColor = vec4(1.0, 0.0, 0.0, -1.0); return; }- vec3 entry = worldFromDepth(v_texCoord, 0.0);+ vec3 entry = rayStart(v_texCoord);vec3 dir = normalize(worldFromDepth(v_texCoord, 1.0) - entry);vec4 lightDir, lightColor;@@ -1156,6 +1166,8 @@ const BETA_M : f32 = 0.021;const H_R : f32 = 8.0;const H_M : f32 = 1.2;const SUN_I : f32 = 22.0;+/// Where a view ray starts (see the GLSL twin): the near plane of a perspective eye, the plane the camera stands in for an orthographic one.+fn rayStart(uv : vec2f) -> vec3f { return worldFromDepth(uv, select(0.5, 0.0, frame.camera.w > 0.5)); }fn hash13(p0 : vec3f) -> f32 {var p = fract(p0 * 0.1031);@@ -1248,7 +1260,7 @@ ${CLOUD_WGSL}let geometry = (covered && depth < 1.0 && src.a > 0.999) || (!covered && depth < 1.0);if (geometry && mc.u_cloudShadow <= 0.001) { return vec4f(1.0, 0.0, 0.0, -1.0); }- let entry = worldFromDepth(v.v_texCoord, 0.0);+ let entry = rayStart(v.v_texCoord);var dir = normalize(worldFromDepth(v.v_texCoord, 1.0) - entry);let found = findSun();diff --git a/tools/check-render-scenes.mjs b/tools/check-render-scenes.mjsindex 9117c9de3..83abf27c0 100644--- a/tools/check-render-scenes.mjs+++ b/tools/check-render-scenes.mjs@@ -68,7 +68,7 @@ for (const s of SCENES) {if (!existsSync(file) || readFileSync(file, 'utf8').split(String.fromCharCode(13)).join('') !== want) {fail(`"${o.id}" is not what tools/oracle generates — run node tools/make-oracle-scenes.mjs`);}- if (!o.expect?.length) fail(`"${o.id}" has no probes`);+ if (!o.expect?.length && !o.twins?.pairs?.length) fail(`"${o.id}" has no probes`);}}diff --git a/tools/oracle/index.mjs b/tools/oracle/index.mjsindex c8840bf37..f653d4835 100644--- a/tools/oracle/index.mjs+++ b/tools/oracle/index.mjs@@ -7,8 +7,9 @@ import { SIZE } from './scene.mjs';import { LIGHT_SCENES } from './lights.mjs';import { SHADOW_SCENES } from './shadows.mjs';import { POST_SCENES } from './post.mjs';+import { SKY_SCENES } from './sky.mjs';-export const ORACLE = [...LIGHT_SCENES, ...SHADOW_SCENES, ...POST_SCENES];+export const ORACLE = [...LIGHT_SCENES, ...SHADOW_SCENES, ...POST_SCENES, ...SKY_SCENES];/** The renderScenes.mjs entry for one oracle scene. */export const oracleEntry = (o) => ({@@ -18,6 +19,8 @@ export const oracleEntry = (o) => ({ESTELLA_VERIFY_W: String(SIZE), ESTELLA_VERIFY_H: String(SIZE), ESTELLA_VERIFY_STEPS: '3',...(o.colorSpace === 'linear' ? { ESTELLA_VERIFY_COLORSPACE: 'linear' } : {}),...(o.outputTransform ? { ESTELLA_VERIFY_OUTPUT_TRANSFORM: o.outputTransform } : {}),- ESTELLA_VERIFY_EXPECT: JSON.stringify(o.expect),+ ...(o.expect ? { ESTELLA_VERIFY_EXPECT: JSON.stringify(o.expect) } : {}),+ ...(o.play ? { ESTELLA_VERIFY_PLAY: '1' } : {}),+ ...(o.twins ? { ESTELLA_VERIFY_TWINS: JSON.stringify(o.twins) } : {}),},});diff --git a/tools/oracle/sky.mjs b/tools/oracle/sky.mjsnew file mode 100644index 000000000..24d2fc96b--- /dev/null+++ b/tools/oracle/sky.mjs@@ -0,0 +1,178 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file sky.mjs — oracle scenes for the Sky Atmosphere dome.+ *+ * The dome is Nishita's single-scattering model: Rayleigh and Mie scattering through an exponential atmosphere, the sun's light+ * attenuated on its way in and the view ray attenuated on its way out, with the Rayleigh and Henyey-Greenstein phase functions+ * (Nishita et al. 1993; Scratchapixel's "Simulating the Colors of the Sky", whose constants these are). The shader integrates it+ * with 16 view steps and 4 light steps, which is what a frame can afford; the reference here integrates the same integral with+ * hundreds, so a disagreement is the shader's integration, or its structure, and not the model.+ *+ * Probes keep clear of the sun's disc and its glow, and the scenes carry no clouds, no moon and no stars (the sun is well up).+ */+import { scene, camera, mesh, probe, probeFrom, SIZE } from './scene.mjs';+import { volume } from './scene.mjs';+import { axisAngle, rotate, norm, dot, encodeLinear8, clamp01, smoothstep } from './formulas.mjs';++const R_E = 6360, R_A = 6420;+const BETA_R = [0.0058, 0.0135, 0.0331], BETA_M = 0.021, H_R = 8, H_M = 1.2, SUN_I = 22, G = 0.76;++const sphereFar = (o, d, r) => {+ const b = dot(o, d), disc = b * b - (dot(o, o) - r * r);+ return disc < 0 ? -1 : -b + Math.sqrt(disc);+};+const sphereNear = (o, d, r) => {+ const b = dot(o, d), disc = b * b - (dot(o, o) - r * r);+ return disc < 0 ? -1 : -b - Math.sqrt(disc);+};+const along = (o, d, t) => [o[0] + d[0] * t, o[1] + d[1] * t, o[2] + d[2] * t];+const height = (p) => Math.hypot(...p) - R_E;++/** The air between p and the top of the atmosphere along d as (Rayleigh, Mie) optical depth, or null when the planet is in the way. */+function lightDepth(p, d, steps) {+ if (sphereFar(p, d, R_E) > 0 && sphereNear(p, d, R_E) > 0) return null;+ const len = sphereFar(p, d, R_A), ds = len / steps;+ let r = 0, m = 0;+ for (let j = 0; j < steps; j++) {+ const h = height(along(p, d, ds * (j + 0.5)));+ r += Math.exp(-h / H_R) * ds; m += Math.exp(-h / H_M) * ds;+ }+ return [r, m];+}++/** Single-scattered sky radiance along `dir` (unit, y up) for a sun direction, camera altitude (km) and haze. */+export function scatterRef(dir, sun, alt, haze, N = 480, M = 96) {+ const o = [0, R_E + alt, 0], len = sphereFar(o, dir, R_A), ds = len / N, mu = dot(dir, sun);+ const phaseR = (3 / (16 * Math.PI)) * (1 + mu * mu);+ const phaseM = (3 / (8 * Math.PI)) * (((1 - G * G) * (1 + mu * mu)) / ((2 + G * G) * Math.pow(1 + G * G - 2 * G * mu, 1.5)));+ let odR = 0, odM = 0;+ const sumR = [0, 0, 0], sumM = [0, 0, 0];+ for (let i = 0; i < N; i++) {+ const p = along(o, dir, ds * (i + 0.5)), h = height(p);+ const dR = Math.exp(-h / H_R) * ds, dM = Math.exp(-h / H_M) * ds;+ odR += dR; odM += dM;+ const ol = lightDepth(p, sun, M);+ if (!ol) continue;+ for (let k = 0; k < 3; k++) {+ const attn = Math.exp(-(BETA_R[k] * (odR + ol[0]) + BETA_M * haze * 1.1 * (odM + ol[1])));+ sumR[k] += attn * dR; sumM[k] += attn * dM;+ }+ }+ return sumR.map((r, k) => (r * BETA_R[k] * phaseR + sumM[k] * BETA_M * haze * phaseM) * SUN_I);+}++/** What the composite shows of that radiance: x 0.55 x brightness, dimmed below the horizon (a cloud-free day, so no night glow). */+export function domeRef(dir, sun, { altitude, haze, intensity }) {+ const flat = norm([dir[0], Math.max(dir[1], 0.015), dir[2]]);+ const col = scatterRef(flat, sun, altitude, haze).map((v) => v * 0.55 * intensity);+ const below = 1 - 0.75 * smoothstep(0, -0.3, dir[1]);+ return col.map((v) => v * below);+}++const FOV = 70;+/** The world direction a pixel of a perspective camera, pitched `pitch` degrees up and turned `yaw` about Y, looks along. */+function pixelDir(i, j, pitch, yaw) {+ const t = Math.tan((FOV * Math.PI) / 360);+ const nx = (2 * (i + 0.5)) / SIZE - 1, ny = 1 - (2 * (j + 0.5)) / SIZE;+ const q = axisAngle([0, 1, 0], yaw), p = axisAngle([1, 0, 0], pitch);+ const cam = norm([nx * t, ny * t, -1]);+ return norm(rotate(q, rotate(p, cam)));+}+const cameraQuat = (pitch, yaw) => {+ const a = axisAngle([0, 1, 0], yaw), b = axisAngle([1, 0, 0], pitch);+ return { w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z, x: a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y, y: a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x, z: a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w };+};++const sunVector = (elevation, azimuth) => {+ const el = (elevation * Math.PI) / 180, az = (azimuth * Math.PI) / 180;+ return [Math.cos(el) * Math.sin(az), Math.sin(el), Math.cos(el) * Math.cos(az)];+};++/**+ * HORIZON_GAP: the shader walks a view ray in 16 equal steps. A ray near the horizon crosses a thousand kilometres of air, almost all of it+ * density in the first few hundred, so equal steps of tens of kilometres miss it: measured against the converged integral, the blue at+ * the horizon is a third of what it should be (a yellow band where the sky should pale to white), and from 10 to 25 degrees up the+ * dome is 5 to 15 percent dark. Probes below 10 degrees are left out of the strict scenes; the gap stays open and is recorded here, not asserted away.+ */+const minElevationSine = Math.sin((10 * Math.PI) / 180);++/** The sun's light by the time it reaches the viewer (the disc's colour): the transmittance along the sun's own ray. */+function sunTransmittance(sun, alt, haze) {+ const od = lightDepth([0, R_E + alt, 0], sun, 256);+ if (!od) return [0, 0, 0];+ return BETA_R.map((b) => Math.exp(-(b * od[0] + BETA_M * haze * 1.1 * od[1])));+}++function skyDome({ id, elevation, azimuth, pitch, yaw, haze = 1, intensity = 0.5, tol = 18, grid = 5, glow = false, sunBrightness = 40 }) {+ const sun = sunVector(elevation, azimuth);+ const doc = scene(id, () => [+ camera({ projectionType: 0, fov: FOV, nearPlane: 1, farPlane: 2000 }),+ volume([{ type: 'skyAtmosphere', enabled: true, uniforms: { u_clouds: 0, u_sunElevation: elevation, u_sunAzimuth: azimuth, u_haze: haze, u_intensity: intensity, u_altitude: 0.1, u_sunBrightness: sunBrightness } }]),+ ]);+ const cam = doc.entities.find((e) => e.name === 'Camera');+ cam.components[0].data.position = { x: 0, y: 0, z: 0 };+ cam.components[0].data.rotation = cameraQuat(pitch, yaw);+ const expect = [];+ for (let a = 0; a < grid; a++) {+ for (let b = 0; b < grid; b++) {+ const i = Math.round(((a + 0.5) / grid) * (SIZE - 1)), j = Math.round(((b + 0.5) / grid) * (SIZE - 1));+ const dir = pixelDir(i, j, pitch, yaw);+ if (dot(dir, sun) > Math.cos(((glow ? 1.5 : 12) * Math.PI) / 180)) continue; // the sun's disc, and its glow unless this scene is about it+ if (dir[1] < minElevationSine) continue; // see HORIZON_GAP+ const col = domeRef(dir, sun, { altitude: 0.1, haze, intensity });+ expect.push({ x: i / (SIZE - 1), y: j / (SIZE - 1), rgb: encodeLinear8(col.map(clamp01)), tol, dir });+ }+ }+ if (glow) {+ // The pixel at the middle of the frame looks along the sun: its disc, which adds the sun's own transmitted light to the dome.+ const j = SIZE / 2, dir = pixelDir(j, j, pitch, yaw), trans = sunTransmittance(sun, 0.1, haze);+ const col = domeRef(dir, sun, { altitude: 0.1, haze, intensity }).map((v, k) => v + trans[k] * sunBrightness);+ expect.push({ x: j / (SIZE - 1), y: j / (SIZE - 1), rgb: encodeLinear8(col.map(clamp01)), tol, dir });+ }+ return { id, doc, colorSpace: 'linear', expect: expect.map(({ dir, ...e }) => e), range: [Math.min(...expect.map((e) => Math.min(...e.rgb))), Math.max(...expect.map((e) => Math.max(...e.rgb)))],+ about: 'Sky dome: the single-scattering integral, converged, against the shader\'s 16 view steps' };+}+++/**+ * Cloud shadows on a floor. The shader places the cloud layer by the camera's altitude (`u_altitude`, km) and the floor's drop below+ * the eye, so where the slab stands against the floor is arithmetic: floor altitude = u_altitude - drop / u_unitsPerKm. A slab wholly+ * BELOW the floor casts nothing on it (lit = 1 exactly), and a dense one above it (overcast, so the coverage is all but total) leaves+ * `1 - 0.8` of the light: the shader's strongest shadow. Noise decides where the gaps are, so the shadowed floor is checked loosely.+ * The same two cases run under an orthographic camera and a perspective one: the answer is the floor's, not the projection's.+ */+function cloudShadow({ id, ortho, altitude, shadowed }) {+ const HEIGHT = 400, FLOOR_TOP = 5, UNITS_PER_KM = 1000;+ const doc = scene(id, () => [+ camera(ortho ? {} : { projectionType: 0, fov: 40, nearPlane: 1, farPlane: 2000 }),+ mesh('Floor', 'cube', [0, 0, 0], [1.8, 0.1, 1.8], [0.8, 0.8, 0.8], { lit: false }),+ volume([{ type: 'skyAtmosphere', enabled: true, uniforms: { u_clouds: 1, u_overcast: 1, u_cloudShadow: 1, u_unitsPerKm: UNITS_PER_KM, u_sunElevation: 40, u_sunAzimuth: 40, u_altitude: altitude, u_windSpeed: 0 } }]),+ ]);+ const floorAltitude = altitude - (HEIGHT - FLOOR_TOP) / UNITS_PER_KM;+ const grid = [-60, -20, 20, 60];+ const half = ortho ? null : (HEIGHT - FLOOR_TOP) * Math.tan((40 * Math.PI) / 360);+ const expect = [];+ for (const x of grid) {+ for (const z of grid) {+ const p = ortho ? probe(x, z) : probeFrom(x, z, HEIGHT - FLOOR_TOP, 40);+ // Unshadowed: the floor's own colour. Shadowed: 20% of it, give or take the gaps in the clouds.+ expect.push({ x: p.x, y: p.y, rgb: encodeLinear8(shadowed ? [0.16, 0.16, 0.16] : [0.8, 0.8, 0.8]), tol: shadowed ? 40 : 3 });+ }+ }+ return { id, doc, colorSpace: 'linear', expect, floorAltitude, about: `Cloud shadow, ${ortho ? 'orthographic' : 'perspective'} camera, slab ${shadowed ? 'above' : 'below'} the floor` };+}++export const SKY_SCENES = [+ skyDome({ id: 'oracle-sky-noon', elevation: 65, azimuth: 40, pitch: 35, yaw: 200 }),+ skyDome({ id: 'oracle-sky-afternoon', elevation: 35, azimuth: 40, pitch: 30, yaw: 140 }),+ skyDome({ id: 'oracle-sky-low-sun', elevation: 8, azimuth: 40, pitch: 25, yaw: 215 }),+ skyDome({ id: 'oracle-sky-sun-glow', elevation: 35, azimuth: 40, pitch: 35, yaw: 220, intensity: 0.08, sunBrightness: 1, glow: true }),+ skyDome({ id: 'oracle-sky-sun-glow-low', elevation: 14, azimuth: 40, pitch: 14, yaw: 220, intensity: 0.06, sunBrightness: 1, glow: true }),+ skyDome({ id: 'oracle-sky-hazy', elevation: 35, azimuth: 40, pitch: 30, yaw: 140, haze: 3, intensity: 0.4 }),+ // Slab 1.5 to 4.0 km. A floor at altitude 5 - 0.395 is above it, a floor at 1 - 0.395 is below its base.+ cloudShadow({ id: 'oracle-cloud-shadow-clear-ortho', ortho: true, altitude: 5, shadowed: false }),+ cloudShadow({ id: 'oracle-cloud-shadow-clear-perspective', ortho: false, altitude: 5, shadowed: false }),+ cloudShadow({ id: 'oracle-cloud-shadow-under-ortho', ortho: true, altitude: 2.2, shadowed: true }),+ cloudShadow({ id: 'oracle-cloud-shadow-under-perspective', ortho: false, altitude: 2.2, shadowed: true }),+];