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): height fog and underwater start their ray at the camera's plane under an orthographic camera; oracle scenes for both
yhh470dab42b556
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4e19af00b..7dfe09c4d 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.-- **Distance Fog works under an orthographic camera.** The pass measured 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), so every surface read as past the fog's end and a scene was fogged to its full colour at any near and far. It now measures 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 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.### Changeddiff --git a/fixtures/scenes/oracle-height-fog-perspective.esscene b/fixtures/scenes/oracle-height-fog-perspective.esscenenew file mode 100644index 000000000..ec9f870da--- /dev/null+++ b/fixtures/scenes/oracle-height-fog-perspective.esscene@@ -0,0 +1,411 @@+{+ "version": 4,+ "name": "oracle-height-fog-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": "Patch0",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -75,+ "y": 2.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 0.05,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.10800000000000001,+ "g": 0.10800000000000001,+ "b": 0.10800000000000001,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Patch1",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -25,+ "y": 22.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 0.45,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.14,+ "g": 0.14,+ "b": 0.14,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "Patch2",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 25,+ "y": 42.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 0.85,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.244,+ "g": 0.244,+ "b": 0.244,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "Patch3",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 75,+ "y": 62.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 1.25,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.5,+ "g": 0.5,+ "b": 0.5,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 5,+ "name": "Patch4",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -75,+ "y": 82.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 1.65,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 6,+ "name": "Patch5",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -25,+ "y": 102.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 2.05,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 7,+ "name": "Patch6",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 25,+ "y": 122.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 2.45,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 8,+ "name": "Patch7",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 75,+ "y": 142.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 2.85,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 9,+ "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": "heightFog",+ "enabled": true,+ "uniforms": {+ "u_density": 0.004,+ "u_heightFalloff": 0.002,+ "u_baseHeight": 0,+ "u_inscatter": 0,+ "u_skyFog": 0.8+ },+ "colors": {+ "u_fogColor": {+ "r": 0.55,+ "g": 0.65,+ "b": 0.8,+ "a": 1+ }+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-height-fog.esscene b/fixtures/scenes/oracle-height-fog.esscenenew file mode 100644index 000000000..7a763244f--- /dev/null+++ b/fixtures/scenes/oracle-height-fog.esscene@@ -0,0 +1,410 @@+{+ "version": 4,+ "name": "oracle-height-fog",+ "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": "Patch0",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -75,+ "y": 2.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 0.05,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.10800000000000001,+ "g": 0.10800000000000001,+ "b": 0.10800000000000001,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Patch1",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -25,+ "y": 22.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 0.45,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.14,+ "g": 0.14,+ "b": 0.14,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "Patch2",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 25,+ "y": 42.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 0.85,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.244,+ "g": 0.244,+ "b": 0.244,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "Patch3",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 75,+ "y": 62.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 1.25,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.5,+ "g": 0.5,+ "b": 0.5,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 5,+ "name": "Patch4",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -75,+ "y": 82.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 1.65,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 6,+ "name": "Patch5",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -25,+ "y": 102.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 2.05,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 7,+ "name": "Patch6",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 25,+ "y": 122.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 2.45,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 8,+ "name": "Patch7",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 75,+ "y": 142.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 2.85,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 9,+ "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": "heightFog",+ "enabled": true,+ "uniforms": {+ "u_density": 0.004,+ "u_heightFalloff": 0.002,+ "u_baseHeight": 0,+ "u_inscatter": 0,+ "u_skyFog": 0.8+ },+ "colors": {+ "u_fogColor": {+ "r": 0.55,+ "g": 0.65,+ "b": 0.8,+ "a": 1+ }+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-underwater.esscene b/fixtures/scenes/oracle-underwater.esscenenew file mode 100644index 000000000..400c9ae99--- /dev/null+++ b/fixtures/scenes/oracle-underwater.esscene@@ -0,0 +1,418 @@+{+ "version": 4,+ "name": "oracle-underwater",+ "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": "Patch0",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -75,+ "y": 2.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 0.05,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.10800000000000001,+ "g": 0.10800000000000001,+ "b": 0.10800000000000001,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Patch1",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -25,+ "y": 22.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 0.45,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.14,+ "g": 0.14,+ "b": 0.14,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "Patch2",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 25,+ "y": 42.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 0.85,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.244,+ "g": 0.244,+ "b": 0.244,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "Patch3",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 75,+ "y": 62.5,+ "z": -50+ },+ "scale": {+ "x": 0.4,+ "y": 1.25,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.5,+ "g": 0.5,+ "b": 0.5,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 5,+ "name": "Patch4",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -75,+ "y": 82.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 1.65,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 6,+ "name": "Patch5",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -25,+ "y": 102.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 2.05,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 7,+ "name": "Patch6",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 25,+ "y": 122.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 2.45,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 8,+ "name": "Patch7",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 75,+ "y": 142.5,+ "z": 50+ },+ "scale": {+ "x": 0.4,+ "y": 2.85,+ "z": 0.4+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0.9,+ "g": 0.9,+ "b": 0.9,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 9,+ "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": "underwater",+ "enabled": true,+ "uniforms": {+ "u_density": 0.003,+ "u_planeNx": 0,+ "u_planeNy": 1,+ "u_planeNz": 0,+ "u_planeD": 450,+ "u_cameraDepth": 0,+ "u_range": 4000+ },+ "colors": {+ "u_absorption": {+ "r": 0.45,+ "g": 0.09,+ "b": 0.05,+ "a": 1+ },+ "u_scatterColor": {+ "r": 0.03,+ "g": 0.2,+ "b": 0.28,+ "a": 1+ }+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/sdk/src/postprocess/sources/atmosphere.ts b/sdk/src/postprocess/sources/atmosphere.tsindex 15a9553be..b519a56e6 100644--- a/sdk/src/postprocess/sources/atmosphere.ts+++ b/sdk/src/postprocess/sources/atmosphere.ts@@ -1352,6 +1352,10 @@ out vec4 fragColor;${SSAO_GLSL}const float FAR_RAY = 100000.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 2D content behind the camera plane still draws), so depth 0 is that far-behind plane, and a ray measured+/// from it carries a camera-length of air that is not in front of the camera. Mid-depth is the plane the camera stands in.+vec3 rayStart(vec2 uv) { return worldFromDepth(uv, u_camera.w > 0.5 ? 0.0 : 0.5); }const int VOLUME_STEPS = 24;float ign(vec2 p) {@@ -1472,7 +1476,7 @@ bool upsampledVolume(float len, out vec3 add) {ivec2 t = clamp(base + o, ivec2(0), hsize - ivec2(1));vec2 uv = uvOfTexel(t, hsize);float dj = depthAt(screenTexel(uv, dsize), dsize);- float lj = dj >= 1.0 ? FAR_RAY : length(worldFromDepth(uv, dj) - worldFromDepth(uv, 0.0));+ float lj = dj >= 1.0 ? FAR_RAY : length(worldFromDepth(uv, dj) - rayStart(uv));float bw = (o.x == 1 ? fr.x : 1.0 - fr.x) * (o.y == 1 ? fr.y : 1.0 - fr.y);float rel = abs(lj - len) / max(len, 1.0);float w = bw / (1.0 + 400.0 * rel * rel);@@ -1489,9 +1493,8 @@ void main() {float depth = texelFetch(u_sceneDepth, clamp(ivec2(v_texCoord * vec2(size)), ivec2(0), size - ivec2(1)), 0).r;bool sky = depth >= 1.0;- // The ray starts on the near plane, which is the one place that is a point under a- // perspective camera and under an orthographic one alike.- vec3 entry = worldFromDepth(v_texCoord, 0.0);+ // The ray starts where the eye is: the near plane under a perspective camera, the plane the camera stands in under an orthographic one.+ vec3 entry = rayStart(v_texCoord);vec3 target = worldFromDepth(v_texCoord, sky ? 1.0 : depth);vec3 dir = normalize(target - entry);float len = sky ? FAR_RAY : length(target - entry);@@ -1543,6 +1546,8 @@ void main() {#pragma fragment wgsl${SSAO_WGSL}const FAR_RAY : f32 = 100000.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)); }const VOLUME_STEPS : i32 = 24;fn ign(p : vec2f) -> f32 {@@ -1657,7 +1662,7 @@ fn upsampledVolume(uv : vec2f, len : f32) -> VolumeRead {let tuv = uvOfTexel(t, hsize);let dj = depthAt(screenTexel(tuv, dsize), dsize);var lj = FAR_RAY;- if (dj < 1.0) { lj = length(worldFromDepth(tuv, dj) - worldFromDepth(tuv, 0.0)); }+ if (dj < 1.0) { lj = length(worldFromDepth(tuv, dj) - rayStart(tuv)); }var bx = 1.0 - fr.x;if (o.x == 1) { bx = fr.x; }var by = 1.0 - fr.y;@@ -1678,7 +1683,7 @@ fn upsampledVolume(uv : vec2f, len : f32) -> VolumeRead {let depth = textureLoad(t7, clamp(vec2i(v.v_texCoord * vec2f(size)), vec2i(0), size - vec2i(1)), 0);let sky = depth >= 1.0;- let entry = worldFromDepth(v.v_texCoord, 0.0);+ let entry = rayStart(v.v_texCoord);var d = depth;if (sky) { d = 1.0; }let tgt = worldFromDepth(v.v_texCoord, d);@@ -1785,6 +1790,10 @@ uniform highp sampler2D u_sceneDepth;out vec4 fragColor;const float FAR_RAY = 100000.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 2D content behind the camera plane still draws), so depth 0 is that far-behind plane, and a ray measured+/// from it carries a camera-length of air that is not in front of the camera. Mid-depth is the plane the camera stands in.+vec3 rayStart(vec2 uv) { return worldFromDepth(uv, u_camera.w > 0.5 ? 0.0 : 0.5); }const int VOLUME_STEPS = 24;float ign(vec2 p) {@@ -1894,9 +1903,8 @@ void main() {float depth = texelFetch(u_sceneDepth, clamp(ivec2(v_texCoord * vec2(size)), ivec2(0), size - ivec2(1)), 0).r;bool sky = depth >= 1.0;- // The ray starts on the near plane, which is the one place that is a point under a- // perspective camera and under an orthographic one alike.- vec3 entry = worldFromDepth(v_texCoord, 0.0);+ // The ray starts where the eye is: the near plane under a perspective camera, the plane the camera stands in under an orthographic one.+ vec3 entry = rayStart(v_texCoord);vec3 target = worldFromDepth(v_texCoord, sky ? 1.0 : depth);vec3 dir = normalize(target - entry);float len = sky ? FAR_RAY : length(target - entry);@@ -1928,6 +1936,8 @@ void main() {#pragma fragment wgslconst FAR_RAY : f32 = 100000.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)); }const VOLUME_STEPS : i32 = 24;fn ign(p : vec2f) -> f32 {@@ -2028,7 +2038,7 @@ fn volumeLight(entry : vec3f, dir : vec3f, len : f32, sky : bool, sun : vec3f, flet depth = textureLoad(t7, clamp(vec2i(v.v_texCoord * vec2f(size)), vec2i(0), size - vec2i(1)), 0);let sky = depth >= 1.0;- let entry = worldFromDepth(v.v_texCoord, 0.0);+ let entry = rayStart(v.v_texCoord);var d = depth;if (sky) { d = 1.0; }let tgt = worldFromDepth(v.v_texCoord, d);diff --git a/sdk/src/water/underwater.ts b/sdk/src/water/underwater.tsindex 6cd583021..287dc760d 100644--- a/sdk/src/water/underwater.ts+++ b/sdk/src/water/underwater.ts@@ -59,6 +59,10 @@ out vec4 fragColor;const int SHAFT_STEPS = 24;${CAUSTICS_GLSL}+/// 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, above the water for a camera under it; mid-depth is the plane+/// the camera stands in.+vec3 rayStart(vec2 uv) { return worldFromDepth(uv, u_camera.w > 0.5 ? 0.0 : 0.5); }float ign(vec2 p) {return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715))));}@@ -73,7 +77,7 @@ void main() {ivec2 size = textureSize(u_sceneDepth, 0);float depth = texelFetch(u_sceneDepth, clamp(ivec2(v_texCoord * vec2(size)), ivec2(0), size - ivec2(1)), 0).r;bool sky = depth >= 1.0;- vec3 entry = worldFromDepth(v_texCoord, 0.0);+ vec3 entry = rayStart(v_texCoord);vec3 target = worldFromDepth(v_texCoord, sky ? 1.0 : depth);// The face of what is seen, from how the picture's own world positions change from one pixel to the next (taken here, before any branch).vec3 facing = cross(dFdx(target), dFdy(target));@@ -144,6 +148,8 @@ void main() {const SHAFT_STEPS : i32 = 24;${CAUSTICS_WGSL}+/// 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 ign(p : vec2f) -> f32 {return fract(52.9829189 * fract(dot(p, vec2f(0.06711056, 0.00583715))));}@@ -157,7 +163,7 @@ fn phaseHG(cosine : f32) -> f32 {let size = vec2i(textureDimensions(t7, 0));let depth = textureLoad(t7, clamp(vec2i(v.v_texCoord * vec2f(size)), vec2i(0), size - vec2i(1)), 0);let sky = depth >= 1.0;- let entry = worldFromDepth(v.v_texCoord, 0.0);+ let entry = rayStart(v.v_texCoord);var d = depth;if (sky) { d = 1.0; }let hit = worldFromDepth(v.v_texCoord, d);diff --git a/tools/oracle/post.mjs b/tools/oracle/post.mjsindex c7082a80f..3367ff723 100644--- a/tools/oracle/post.mjs+++ b/tools/oracle/post.mjs@@ -7,7 +7,7 @@* `unlit colour -> effects -> output transform -> sRGB encode`. Each expectation applies the published curve (or, for the* engine's own effects, the formula their shader source states) to the patch colour; no frame was read to write it.*/-import { scene, camera, mesh, volume, probe } from './scene.mjs';+import { scene, camera, mesh, volume, probe, probeFrom } from './scene.mjs';import { encodeLinear8, clamp01, acesNarkowicz, pbrNeutral, srgbDecode, scale } from './formulas.mjs';const SLOTS = [[-75, -50], [-25, -50], [25, -50], [75, -50], [-75, 50], [-25, 50], [25, 50], [75, 50]];@@ -21,9 +21,9 @@ const COLOURS = [[0.8, 0.1, 0.05], [0.05, 0.6, 0.1], [0.05, 0.1, 0.9], [0.9, 0.7* @param tops patch heights above the floor line; the camera looks down at each patch's top face* @param out (linear rgb, slot index) -> linear rgb the frame should end as, before the sRGB encode*/-function patches({ id, colours, tops, effects, outputTransform, out, tol = 3, about }) {+function patches({ id, colours, tops, effects, outputTransform, out, tol = 3, about, perspective = false }) {const doc = scene(id, () => [- camera(),+ camera(perspective ? { projectionType: 0, fov: 40 } : {}),...colours.map((c, i) => {const top = tops?.[i] ?? 10;return mesh(`Patch${i}`, 'cube', [SLOTS[i][0], top / 2, SLOTS[i][1]], [0.4, top / 100, 0.4], c, { lit: false });@@ -31,8 +31,8 @@ function patches({ id, colours, tops, effects, outputTransform, out, tol = 3, ab...(effects ? [volume(effects)] : []),]);const expect = colours.map((c, i) => {- const p = probe(...SLOTS[i]);- return { x: p.x, y: p.y, rgb: encodeLinear8(out(c, i)), tol };+ const p = perspective ? probeFrom(...SLOTS[i], 400 - (tops?.[i] ?? 10), 40) : probe(...SLOTS[i]);+ return { x: p.x, y: p.y, rgb: encodeLinear8(out(c, i, SLOTS[i])), tol };});return { id, doc, colorSpace: 'linear', outputTransform, expect, about };}@@ -61,6 +61,46 @@ const fogMix = (c, top) => {return c.map((x, k) => x + (fog[k] - x) * t);};++// Height fog: an exponential-density slab, rho(y) = density * exp(-falloff * (y - base)), integrated along the view ray. The camera looks+// straight down, so the ray runs from the eye plane (y = 400) to the patch top and the optical depth is closed form:+// tau = density / falloff * (exp(-falloff * (top - base)) - exp(-falloff * (400 - base))), and the fog covers 1 - exp(-tau).+// The fall-off is slow on purpose: the part of the ray between the camera plane and a start far behind it is thin air only when the+// density has died away by then, and this one has not, so a ray that begins too far back shows as too much fog.+const HEIGHT_FOG = { density: 0.004, falloff: 0.002, base: 0, colour: [0.55, 0.65, 0.8] };+const heightFogMix = (c, top) => {+ const tau = (HEIGHT_FOG.density / HEIGHT_FOG.falloff) * (Math.exp(-HEIGHT_FOG.falloff * (top - HEIGHT_FOG.base)) - Math.exp(-HEIGHT_FOG.falloff * (400 - HEIGHT_FOG.base)));+ const amount = 1 - Math.exp(-tau);+ const fog = HEIGHT_FOG.colour.map(srgbDecode);+ return c.map((x, k) => x + (fog[k] - x) * amount);+};+++/**+ * The same fog under a perspective camera 400 units up with its near plane at 1: the ray starts on the near plane (y = 399) and+ * climbs by dirY over len, and tau = density(start) * len * (1 - exp(-falloff * dirY * len)) / (falloff * dirY * len).+ */+function heightFogPerspective(c, top, [x, z]) {+ const eye = [0, 400, 0], p = [x, top, z], toP = [p[0] - eye[0], p[1] - eye[1], p[2] - eye[2]];+ const full = Math.hypot(...toP), s = 1 / (400 - top), len = (1 - s) * full, dirY = toP[1] / full, startY = 400 - s * (400 - top);+ const dens = HEIGHT_FOG.density * Math.exp(-HEIGHT_FOG.falloff * (startY - HEIGHT_FOG.base));+ const kd = HEIGHT_FOG.falloff * dirY * len;+ const tau = dens * len * (Math.abs(kd) < 1e-4 ? 1 : (1 - Math.exp(-kd)) / kd);+ const amount = 1 - Math.exp(-tau), fog = HEIGHT_FOG.colour.map(srgbDecode);+ return c.map((v, k) => v + (fog[k] - v) * amount);+}+++// Underwater: the camera (y = 400) is under a water plane at y = 450. With no sun there are no caustics or shafts, so a surface seen+// through `len` of water is colour * T + scatter * (1 - mean(T)), T = exp(-absorption * density * len), len the drop to the surface.+const WATER = { absorption: [0.45, 0.09, 0.05], scatter: [0.03, 0.2, 0.28], density: 0.003, planeD: 450 };+const waterMix = (c, top) => {+ const len = 400 - top;+ const T = WATER.absorption.map((a) => Math.exp(-a * WATER.density * len));+ const mean = (T[0] + T[1] + T[2]) / 3, scatter = WATER.scatter.map(srgbDecode);+ return c.map((v, k) => v * T[k] + scatter[k] * (1 - mean));+};+export const POST_SCENES = [patches({ id: 'oracle-encode-linear', colours: GREYS, out: perChannel(clamp01), about: 'No tone map: the linear value is sRGB-encoded as it is, clamped at 1' }),patches({ id: 'oracle-output-aces', colours: GREYS, outputTransform: 'aces', out: perChannel(acesNarkowicz), about: 'Output transform ACES: Narkowicz fit, then the sRGB encode' }),@@ -79,4 +119,23 @@ export const POST_SCENES = [out: (c, i) => fogMix(c, FOG_TOPS[i]).map(clamp01),about: 'Distance fog: mix(colour, fog, clamp((distance - near) / (far - near)) x intensity)',}),+ patches({+ id: 'oracle-height-fog', colours: GREYS.map((g) => g.map((v) => Math.min(v, 1) * 0.8 + 0.1)), tops: FOG_TOPS, tol: 4,+ effects: [fx('heightFog', { u_density: HEIGHT_FOG.density, u_heightFalloff: HEIGHT_FOG.falloff, u_baseHeight: HEIGHT_FOG.base, u_inscatter: 0, u_skyFog: 0.8 }, { u_fogColor: { r: HEIGHT_FOG.colour[0], g: HEIGHT_FOG.colour[1], b: HEIGHT_FOG.colour[2], a: 1 } })],+ out: (c, i) => heightFogMix(c, FOG_TOPS[i]).map(clamp01),+ about: 'Height fog: coverage 1 - exp(-tau), tau the exponential density integrated from the eye plane to the surface',+ }),+ patches({+ id: 'oracle-height-fog-perspective', perspective: true, colours: GREYS.map((g) => g.map((v) => Math.min(v, 1) * 0.8 + 0.1)), tops: FOG_TOPS, tol: 4,+ effects: [fx('heightFog', { u_density: HEIGHT_FOG.density, u_heightFalloff: HEIGHT_FOG.falloff, u_baseHeight: HEIGHT_FOG.base, u_inscatter: 0, u_skyFog: 0.8 }, { u_fogColor: { r: HEIGHT_FOG.colour[0], g: HEIGHT_FOG.colour[1], b: HEIGHT_FOG.colour[2], a: 1 } })],+ out: (c, i, slot) => heightFogPerspective(c, FOG_TOPS[i], slot).map(clamp01),+ about: 'Height fog under a perspective camera: the ray starts on the near plane',+ }),+ patches({+ id: 'oracle-underwater', colours: GREYS.map((g) => g.map((v) => Math.min(v, 1) * 0.8 + 0.1)), tops: FOG_TOPS, tol: 4,+ effects: [fx('underwater', { u_density: WATER.density, u_planeNx: 0, u_planeNy: 1, u_planeNz: 0, u_planeD: WATER.planeD, u_cameraDepth: 0, u_range: 4000 },+ { u_absorption: { r: WATER.absorption[0], g: WATER.absorption[1], b: WATER.absorption[2], a: 1 }, u_scatterColor: { r: WATER.scatter[0], g: WATER.scatter[1], b: WATER.scatter[2], a: 1 } })],+ out: (c, i) => waterMix(c, FOG_TOPS[i]).map(clamp01),+ about: 'Underwater fog: Beer-Lambert absorption over the drop to the surface, plus the colour of the water itself',+ }),];diff --git a/tools/oracle/scene.mjs b/tools/oracle/scene.mjsindex ddfcb1ef7..6481d01f0 100644--- a/tools/oracle/scene.mjs+++ b/tools/oracle/scene.mjs@@ -26,6 +26,16 @@ export function probe(x, z) {return { x: px.i / (SIZE - 1), y: pz.i / (SIZE - 1), at: [px.world, pz.world] };}+/**+ * A frame probe for the point (x, z) on a horizontal surface `drop` units below a perspective camera that looks straight down with+ * vertical field of view `fov` degrees: the surface's half-width in view is drop * tan(fov / 2), so x and z scale by it.+ */+export function probeFrom(x, z, drop, fov) {+ const half = drop * Math.tan((fov * Math.PI) / 360);+ const at = (w) => Math.min(SIZE - 1, Math.max(0, Math.floor((w / (2 * half) + 0.5) * SIZE)));+ return { x: at(x) / (SIZE - 1), y: at(z) / (SIZE - 1) };+}+let nextId;const entity = (name, components) => ({ id: nextId++, name, parent: null, children: [], visible: true, components });const transform = (position, rotation, scale) => ({