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): rain and depth of field measure from the camera's plane under an orthographic camera; oracle scenes for rain, depth of field and custom sky
yhh4721da37e216
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex aca94d55a..20f43c5b3 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, 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.+- **Fog, water, sky, rain and depth of field work under an orthographic camera.** Distance Fog, Height Fog (and its volumetric pass), Underwater, Sky Atmosphere with its clouds, Rain and Depth of Field measured how far a surface is from the camera starting at 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, the cloud layer, placed by that height, stood kilometres off, so a floor above the clouds was still in their shadow, Rain drew its streak layers in front of surfaces a few units from the eye, and Depth of Field blurred what stood exactly at its focus distance. 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-custom-sky-ortho.esscene b/fixtures/scenes/oracle-custom-sky-ortho.esscenenew file mode 100644index 000000000..907473cb0--- /dev/null+++ b/fixtures/scenes/oracle-custom-sky-ortho.esscene@@ -0,0 +1,116 @@+{+ "version": 4,+ "name": "oracle-custom-sky-ortho",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 0.9254165783983234,+ "x": 0.33682408883346515,+ "y": 0.16317591116653482,+ "z": -0.0593911746138847+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Sun",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": -0.15737869562426263,+ "x": 0.07338689100003823,+ "y": 0.8925389352890299,+ "z": 0.4161977407267834+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 1,+ "color": {+ "r": 1,+ "g": 0.5,+ "b": 0.25,+ "a": 1+ },+ "intensity": 1+ }+ }+ ]+ },+ {+ "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": "oracleSky",+ "enabled": true,+ "uniforms": {+ "u_intensity": 0.9+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-custom-sky-perspective.esscene b/fixtures/scenes/oracle-custom-sky-perspective.esscenenew file mode 100644index 000000000..09af23213--- /dev/null+++ b/fixtures/scenes/oracle-custom-sky-perspective.esscene@@ -0,0 +1,117 @@+{+ "version": 4,+ "name": "oracle-custom-sky-perspective",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 0.9254165783983234,+ "x": 0.33682408883346515,+ "y": 0.16317591116653482,+ "z": -0.0593911746138847+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 2000,+ "isActive": true,+ "priority": 0,+ "fov": 70+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Sun",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": -0.15737869562426263,+ "x": 0.07338689100003823,+ "y": 0.8925389352890299,+ "z": 0.4161977407267834+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 1,+ "color": {+ "r": 1,+ "g": 0.5,+ "b": 0.25,+ "a": 1+ },+ "intensity": 1+ }+ }+ ]+ },+ {+ "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": "oracleSky",+ "enabled": true,+ "uniforms": {+ "u_intensity": 0.9+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-dof-ortho.esscene b/fixtures/scenes/oracle-dof-ortho.esscenenew file mode 100644index 000000000..abfb00a68--- /dev/null+++ b/fixtures/scenes/oracle-dof-ortho.esscene@@ -0,0 +1,243 @@+{+ "version": 4,+ "name": "oracle-dof-ortho",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 405,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 8000,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "NearBlack",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -1025,+ "y": 2.5,+ "z": 0+ },+ "scale": {+ "x": 19.5,+ "y": 0.05,+ "z": 14+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "NearWhite",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -25,+ "y": 2.5,+ "z": 0+ },+ "scale": {+ "x": 0.5,+ "y": 0.05,+ "z": 14+ }+ }+ },+ {+ "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": 3,+ "name": "FarBlack",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 25,+ "y": -597.5,+ "z": 0+ },+ "scale": {+ "x": 0.5,+ "y": 0.05,+ "z": 14+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "FarWhite",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 1025,+ "y": -597.5,+ "z": 0+ },+ "scale": {+ "x": 19.5,+ "y": 0.05,+ "z": 14+ }+ }+ },+ {+ "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": 5,+ "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": "depthOfField",+ "enabled": true,+ "uniforms": {+ "u_focusDistance": 400,+ "u_autoFocus": 0,+ "u_focusRange": 50,+ "u_aperture": 24,+ "u_maxBlur": 8,+ "u_highlight": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-dof-perspective.esscene b/fixtures/scenes/oracle-dof-perspective.esscenenew file mode 100644index 000000000..a92aa6b7f--- /dev/null+++ b/fixtures/scenes/oracle-dof-perspective.esscene@@ -0,0 +1,244 @@+{+ "version": 4,+ "name": "oracle-dof-perspective",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 405,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 8000,+ "isActive": true,+ "priority": 0,+ "fov": 40+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "NearBlack",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -1036.3970234266203,+ "y": 2.5,+ "z": 0+ },+ "scale": {+ "x": 19.272059531467598,+ "y": 0.05,+ "z": 14+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "NearWhite",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -36.39702342662024,+ "y": 2.5,+ "z": 0+ },+ "scale": {+ "x": 0.7279404685324047,+ "y": 0.05,+ "z": 14+ }+ }+ },+ {+ "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": 3,+ "name": "FarBlack",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 90.99255856655058,+ "y": -597.5,+ "z": 0+ },+ "scale": {+ "x": 1.8198511713310117,+ "y": 0.05,+ "z": 14+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "FarWhite",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 1090.9925585665505,+ "y": -597.5,+ "z": 0+ },+ "scale": {+ "x": 18.18014882866899,+ "y": 0.05,+ "z": 14+ }+ }+ },+ {+ "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": 5,+ "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": "depthOfField",+ "enabled": true,+ "uniforms": {+ "u_focusDistance": 400,+ "u_autoFocus": 0,+ "u_focusRange": 50,+ "u_aperture": 24,+ "u_maxBlur": 8,+ "u_highlight": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-rain-layers-far-ortho.esscene b/fixtures/scenes/oracle-rain-layers-far-ortho.esscenenew file mode 100644index 000000000..ef7ae2cc2--- /dev/null+++ b/fixtures/scenes/oracle-rain-layers-far-ortho.esscene@@ -0,0 +1,119 @@+{+ "version": 4,+ "name": "oracle-rain-layers-far-ortho",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 2005,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 8000,+ "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": 3.2,+ "y": 0.1,+ "z": 3.2+ }+ }+ },+ {+ "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": "rain",+ "enabled": true,+ "uniforms": {+ "u_intensity": 2,+ "u_wetness": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-rain-layers-far-perspective.esscene b/fixtures/scenes/oracle-rain-layers-far-perspective.esscenenew file mode 100644index 000000000..437721662--- /dev/null+++ b/fixtures/scenes/oracle-rain-layers-far-perspective.esscene@@ -0,0 +1,120 @@+{+ "version": 4,+ "name": "oracle-rain-layers-far-perspective",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 2005,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 8000,+ "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": 21.83821405597214,+ "y": 0.1,+ "z": 21.83821405597214+ }+ }+ },+ {+ "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": "rain",+ "enabled": true,+ "uniforms": {+ "u_intensity": 2,+ "u_wetness": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-rain-layers-near-ortho.esscene b/fixtures/scenes/oracle-rain-layers-near-ortho.esscenenew file mode 100644index 000000000..2eca26a4f--- /dev/null+++ b/fixtures/scenes/oracle-rain-layers-near-ortho.esscene@@ -0,0 +1,119 @@+{+ "version": 4,+ "name": "oracle-rain-layers-near-ortho",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 105,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 8000,+ "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": 3.2,+ "y": 0.1,+ "z": 3.2+ }+ }+ },+ {+ "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": "rain",+ "enabled": true,+ "uniforms": {+ "u_intensity": 2,+ "u_wetness": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-rain-layers-near-perspective.esscene b/fixtures/scenes/oracle-rain-layers-near-perspective.esscenenew file mode 100644index 000000000..556c6a434--- /dev/null+++ b/fixtures/scenes/oracle-rain-layers-near-perspective.esscene@@ -0,0 +1,120 @@+{+ "version": 4,+ "name": "oracle-rain-layers-near-perspective",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 105,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 8000,+ "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": 3.2,+ "y": 0.1,+ "z": 3.2+ }+ }+ },+ {+ "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": "rain",+ "enabled": true,+ "uniforms": {+ "u_intensity": 2,+ "u_wetness": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-rain-wet-ortho.esscene b/fixtures/scenes/oracle-rain-wet-ortho.esscenenew file mode 100644index 000000000..3e4c25cca--- /dev/null+++ b/fixtures/scenes/oracle-rain-wet-ortho.esscene@@ -0,0 +1,120 @@+{+ "version": 4,+ "name": "oracle-rain-wet-ortho",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 405,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 8000,+ "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": "rain",+ "enabled": true,+ "uniforms": {+ "u_intensity": 0,+ "u_wetness": 0.6,+ "u_puddles": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/oracle-rain-wet-perspective.esscene b/fixtures/scenes/oracle-rain-wet-perspective.esscenenew file mode 100644index 000000000..90855ca04--- /dev/null+++ b/fixtures/scenes/oracle-rain-wet-perspective.esscene@@ -0,0 +1,121 @@+{+ "version": 4,+ "name": "oracle-rain-wet-perspective",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 405,+ "z": 0+ },+ "rotation": {+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0,+ "w": 0.7071067811865476+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "orthoSize": 100,+ "nearPlane": 1,+ "farPlane": 8000,+ "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": "rain",+ "enabled": true,+ "uniforms": {+ "u_intensity": 0,+ "u_wetness": 0.6,+ "u_puddles": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/sdk/src/postprocess/sources/atmosphere.ts b/sdk/src/postprocess/sources/atmosphere.tsindex 8431a0e4d..91af75603 100644--- a/sdk/src/postprocess/sources/atmosphere.ts+++ b/sdk/src/postprocess/sources/atmosphere.ts@@ -2174,6 +2174,11 @@ ${BASIN_GLSL}${GBUFFER_GLSL}${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, and the layers of rain, which stand 120, 450 and 1400 units in front of+/// the camera, would all stand in front of every surface. 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); }+/// 1 where something stands over a point, as the map of the scene seen from straight above says — an awning, a roof,/// a tree — and 0 in the open. The map stores the depth the shadow maps do, so a point on the surface itself is not over it.float shelteredAt(vec3 W) {@@ -2194,7 +2199,7 @@ void main() {ivec2 size = textureSize(u_sceneDepth, 0);ivec2 c = screenTexel(v_texCoord, size);float d = depthAt(c, size);- vec3 entry = worldFromDepth(v_texCoord, 0.0);+ vec3 entry = rayStart(v_texCoord);// How far the surface here is, measured along the same ray as the streak layers are.float dist = d >= 1.0 ? 1e9 : length(worldFromDepth(uvOfTexel(c, size), d) - entry);@@ -2278,6 +2283,9 @@ ${BASIN_WGSL}${GBUFFER_WGSL}${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 shelteredAt(W : vec3f) -> f32 {if (mc.u_coverActive < 0.5) { return 0.0; }let m = mat4x4f(mc.u_coverMatrix0, mc.u_coverMatrix1, mc.u_coverMatrix2, mc.u_coverMatrix3);@@ -2299,7 +2307,7 @@ fn shelteredAt(W : vec3f) -> f32 {let size = vec2i(textureDimensions(t7, 0));let c = screenTexel(v.v_texCoord, size);let d = depthAt(c, size);- let entry = worldFromDepth(v.v_texCoord, 0.0);+ let entry = rayStart(v.v_texCoord);var dist = 1e9;if (d < 1.0) { dist = length(worldFromDepth(uvOfTexel(c, size), d) - entry); }diff --git a/sdk/src/postprocess/sources/lighting.ts b/sdk/src/postprocess/sources/lighting.tsindex 1cca729d3..f96208903 100644--- a/sdk/src/postprocess/sources/lighting.ts+++ b/sdk/src/postprocess/sources/lighting.ts@@ -1339,7 +1339,7 @@ void main() {float target = u_focusDistance;if (u_autoFocus > 0.5) {ivec2 size = textureSize(u_sceneDepth, 0);- vec3 eye = worldFromDepth(vec2(u_focusX, 1.0 - u_focusY), 0.0);+ vec3 eye = worldFromDepth(vec2(u_focusX, 1.0 - u_focusY), u_camera.w > 0.5 ? 0.0 : 0.5);// Nine taps a little apart: what is under the point, not whatever one pixel of it happens to be.float sum = 0.0;float n = 0.0;@@ -1373,7 +1373,7 @@ ${SSAO_WGSL}var target_d = mc.u_focusDistance;if (mc.u_autoFocus > 0.5) {let size = vec2i(textureDimensions(t7, 0));- let eye = worldFromDepth(vec2f(mc.u_focusX, mc.u_focusY), 0.0);+ let eye = worldFromDepth(vec2f(mc.u_focusX, mc.u_focusY), select(0.5, 0.0, frame.camera.w > 0.5));var sum = 0.0;var n = 0.0;for (var j : i32 = -1; j <= 1; j = j + 1) {@@ -1432,7 +1432,9 @@ void main() {float depth = depthAt(screenTexel(v_texCoord, size), size);float coc = min(u_aperture, u_maxBlur);if (depth < 1.0) {- vec3 eye = u_camera.w > 0.5 ? u_camera.xyz : worldFromDepth(v_texCoord, 0.0);+ // An orthographic eye has no point to measure from; its depth range runs from far behind the camera to far ahead of it (near = -far), so the plane it+ // stands in is mid-depth, and a surface is as far as it is along the view.+ vec3 eye = u_camera.w > 0.5 ? u_camera.xyz : worldFromDepth(v_texCoord, 0.5);float dist = length(worldFromDepth(v_texCoord, depth) - eye);coc = min(u_aperture * max(abs(dist - focus) - u_focusRange, 0.0) / max(dist, 1e-3), u_maxBlur);}@@ -1450,7 +1452,7 @@ ${SSAO_WGSL}let depth = depthAt(screenTexel(v.v_texCoord, size), size);var coc = min(mc.u_aperture, mc.u_maxBlur);if (depth < 1.0) {- var eye = worldFromDepth(v.v_texCoord, 0.0);+ var eye = worldFromDepth(v.v_texCoord, 0.5);if (frame.camera.w > 0.5) { eye = frame.camera.xyz; }let dist = length(worldFromDepth(v.v_texCoord, depth) - eye);coc = min(mc.u_aperture * max(abs(dist - focus) - mc.u_focusRange, 0.0) / max(dist, 1e-3), mc.u_maxBlur);diff --git a/tools/check-render-scenes.mjs b/tools/check-render-scenes.mjsindex 83abf27c0..cc9e9232c 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 && !o.twins?.pairs?.length) fail(`"${o.id}" has no probes`);+ if (!o.expect?.length && !o.twins?.pairs?.length && !o.count?.length) fail(`"${o.id}" has no probes`);}}diff --git a/tools/oracle/index.mjs b/tools/oracle/index.mjsindex f653d4835..12599b232 100644--- a/tools/oracle/index.mjs+++ b/tools/oracle/index.mjs@@ -8,8 +8,9 @@ import { LIGHT_SCENES } from './lights.mjs';import { SHADOW_SCENES } from './shadows.mjs';import { POST_SCENES } from './post.mjs';import { SKY_SCENES } from './sky.mjs';+import { LENS_SCENES } from './lens.mjs';-export const ORACLE = [...LIGHT_SCENES, ...SHADOW_SCENES, ...POST_SCENES, ...SKY_SCENES];+export const ORACLE = [...LIGHT_SCENES, ...SHADOW_SCENES, ...POST_SCENES, ...SKY_SCENES, ...LENS_SCENES];/** The renderScenes.mjs entry for one oracle scene. */export const oracleEntry = (o) => ({@@ -20,6 +21,8 @@ export const oracleEntry = (o) => ({...(o.colorSpace === 'linear' ? { ESTELLA_VERIFY_COLORSPACE: 'linear' } : {}),...(o.outputTransform ? { ESTELLA_VERIFY_OUTPUT_TRANSFORM: o.outputTransform } : {}),...(o.expect ? { ESTELLA_VERIFY_EXPECT: JSON.stringify(o.expect) } : {}),+ ...(o.count ? { ESTELLA_VERIFY_COUNT: JSON.stringify(o.count) } : {}),+ ...(o.uniform ? { ESTELLA_VERIFY_UNIFORM: '1' } : {}),...(o.play ? { ESTELLA_VERIFY_PLAY: '1' } : {}),...(o.twins ? { ESTELLA_VERIFY_TWINS: JSON.stringify(o.twins) } : {}),},diff --git a/tools/oracle/lens.mjs b/tools/oracle/lens.mjsnew file mode 100644index 000000000..c45bb2e1c--- /dev/null+++ b/tools/oracle/lens.mjs@@ -0,0 +1,114 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file lens.mjs — oracle scenes for rain and depth of field, the two effects that measure how far a surface is from the camera.+ *+ * Both are looked at by an orthographic camera and a perspective one, because "how far from the camera" has a different meaning for+ * each and the two have to agree about a surface that is plainly 100 (or 400, or 2000) units below the eye.+ */+import { scene, camera, mesh, volume, probe, probeFrom, SIZE } from './scene.mjs';+import { encodeLinear8, clamp01 } from './formulas.mjs';++const FLOOR_TOP = 5;+const FLOOR = 0.8;+const fx = (type, uniforms) => ({ type, enabled: true, uniforms });+const eye = (ortho, drop, extra = {}) => camera({ ...(ortho ? {} : { projectionType: 0, fov: 40, nearPlane: 1 }), farPlane: 8000, ...extra });+/** The camera that stands `drop` units over the floor top. */+function placeCamera(doc, drop) {+ const cam = doc.entities.find((e) => e.name === 'Camera');+ cam.components[0].data.position = { x: 0, y: FLOOR_TOP + drop, z: 0 };+}++// ---- rain ------------------------------------------------------------------------------------------------------------------------++/**+ * Wet ground. With no drops falling (intensity 0) and no puddles, rain darkens what faces up by 32% of its wetness:+ * colour x (1 - 0.32 x wetness). The floor looks straight up at the sky, so that is all that happens to it.+ */+function rainWet({ id, ortho }) {+ const drop = 400, wetness = 0.6;+ const doc = scene(id, () => [+ eye(ortho), mesh('Floor', 'cube', [0, 0, 0], [1.8, 0.1, 1.8], [FLOOR, FLOOR, FLOOR], { lit: false }),+ volume([fx('rain', { u_intensity: 0, u_wetness: wetness, u_puddles: 0 })]),+ ]);+ placeCamera(doc, drop);+ const level = FLOOR * (1 - 0.32 * wetness);+ const expect = [];+ for (const x of [-60, -20, 20, 60]) {+ for (const z of [-60, -20, 20, 60]) {+ const p = ortho ? probe(x, z) : probeFrom(x, z, drop, 40);+ expect.push({ x: p.x, y: p.y, rgb: encodeLinear8([level, level, level]), tol: 3 });+ }+ }+ return { id, doc, colorSpace: 'linear', expect, about: `Rain wets what faces up: colour x (1 - 0.32 x wetness), ${ortho ? 'orthographic' : 'perspective'}` };+}++/**+ * The streak layers stand 120, 450 and 1400 units in front of the camera, and a layer is drawn only over a surface farther than it.+ * A floor 100 units below the eye has all three behind it, so with the heaviest rain there is not one streak anywhere and the whole+ * frame is the floor's colour. A floor 2000 units down has all three in front of it, so streaks are drawn across it.+ */+function rainLayers({ id, ortho, drop, streaks }) {+ const size = ortho ? 3.2 : Math.max(3.2, ((drop * Math.tan((40 * Math.PI) / 360)) / 100) * 3);+ const doc = scene(id, () => [+ eye(ortho), mesh('Floor', 'cube', [0, 0, 0], [size, 0.1, size], [FLOOR, FLOOR, FLOOR], { lit: false }),+ volume([fx('rain', { u_intensity: 2, u_wetness: 0 })]),+ ]);+ placeCamera(doc, drop);+ const total = SIZE * SIZE, rgb = encodeLinear8([FLOOR, FLOOR, FLOOR]);+ // Streaks add light, so a streaked pixel is brighter than the floor: count the pixels that are exactly the floor.+ const count = streaks ? [{ rgb, tol: 2, atMost: Math.floor(total * 0.98) }] : [{ rgb, tol: 2, atLeast: total }];+ return { id, doc, colorSpace: 'linear', count, uniform: !streaks,+ about: `Rain layers ${streaks ? 'in front of' : 'behind'} a floor ${drop} units down, ${ortho ? 'orthographic' : 'perspective'}` };+}++// ---- depth of field --------------------------------------------------------------------------------------------------------------++/**+ * Two planes seen at once, the near one 400 units below the eye and the far one 1000, each cut in two by a black / white edge. The+ * lens focuses on 400 with a slab of 50 around it, so the near edge is sharp and the far one is blurred by+ * min(aperture x (|distance - focus| - range) / distance, maxBlur) pixels. A step edge seen through a disc of that radius r gives, at a+ * pixel s pixels onto the white side, the white share 0.5 + (asin(s / r) + (s / r) x sqrt(1 - (s / r)^2)) / pi.+ */+function depthOfField({ id, ortho }) {+ const DROP_NEAR = 400, DROP_FAR = 1000, FOCUS = 400, RANGE = 50, APERTURE = 24, MAX_BLUR = 8;+ const half = (drop) => (ortho ? 100 : drop * Math.tan((40 * Math.PI) / 360));+ // The world x of the frame's pixel boundary `px` on a plane `drop` below the camera.+ const worldX = (px, drop) => (px / SIZE - 0.5) * 2 * half(drop);+ const NEAR_EDGE = worldX(64, DROP_NEAR), FAR_EDGE = worldX(192, DROP_FAR);+ const cubeSpan = (name, top, bottom, x0, x1, c) =>+ mesh(name, 'cube', [(x0 + x1) / 2, (top + bottom) / 2, 0], [(x1 - x0) / 100, (top - bottom) / 100, 14], [c, c, c], { lit: false });+ const nearTop = FLOOR_TOP, farTop = FLOOR_TOP + DROP_NEAR - DROP_FAR; // the camera stands DROP_NEAR over the near plane+ const doc = scene(id, () => [+ eye(ortho),+ cubeSpan('NearBlack', nearTop, nearTop - 5, -2000, NEAR_EDGE, 0.0), cubeSpan('NearWhite', nearTop, nearTop - 5, NEAR_EDGE, 0, FLOOR),+ cubeSpan('FarBlack', farTop, farTop - 5, 0, FAR_EDGE, 0.0), cubeSpan('FarWhite', farTop, farTop - 5, FAR_EDGE, 2000, FLOOR),+ volume([fx('depthOfField', { u_focusDistance: FOCUS, u_autoFocus: 0, u_focusRange: RANGE, u_aperture: APERTURE, u_maxBlur: MAX_BLUR, u_highlight: 0 })]),+ ]);+ placeCamera(doc, DROP_NEAR);+ const row = Math.floor(SIZE / 2);+ const dist = (drop) => drop; // along the optical axis, which is where the edge rows are+ const coc = (drop) => Math.min((APERTURE * Math.max(Math.abs(dist(drop) - FOCUS) - RANGE, 0)) / dist(drop), MAX_BLUR);+ const share = (s, r) => (r < 0.01 ? (s > 0 ? 1 : 0) : s <= -r ? 0 : s >= r ? 1 : 0.5 + (Math.asin(s / r) + (s / r) * Math.sqrt(1 - (s / r) ** 2)) / Math.PI);+ const expect = [];+ const probeEdge = (edgePx, drop, offsets) => {+ for (const i of offsets) {+ const s = i + 0.5 - edgePx, w = share(s, coc(drop));+ expect.push({ x: i / (SIZE - 1), y: row / (SIZE - 1), rgb: encodeLinear8([FLOOR * w, FLOOR * w, FLOOR * w]), tol: drop === DROP_NEAR ? 6 : 24 });+ }+ };+ probeEdge(64, DROP_NEAR, [60, 63, 64, 67]); // sharp: black, black, white, white+ probeEdge(192, DROP_FAR, [184, 188, 191, 192, 196, 200]); // blurred over 8 pixels+ return { id, doc, colorSpace: 'linear', expect, about: `Depth of field, ${ortho ? 'orthographic' : 'perspective'}: the in-focus edge is sharp, the far one is blurred by the circle of confusion` };+}++export const LENS_SCENES = [+ rainWet({ id: 'oracle-rain-wet-ortho', ortho: true }),+ rainWet({ id: 'oracle-rain-wet-perspective', ortho: false }),+ rainLayers({ id: 'oracle-rain-layers-near-ortho', ortho: true, drop: 100, streaks: false }),+ rainLayers({ id: 'oracle-rain-layers-near-perspective', ortho: false, drop: 100, streaks: false }),+ rainLayers({ id: 'oracle-rain-layers-far-ortho', ortho: true, drop: 2000, streaks: true }),+ rainLayers({ id: 'oracle-rain-layers-far-perspective', ortho: false, drop: 2000, streaks: true }),+ depthOfField({ id: 'oracle-dof-ortho', ortho: true }),+ depthOfField({ id: 'oracle-dof-perspective', ortho: false }),+];diff --git a/tools/oracle/sky.mjs b/tools/oracle/sky.mjsindex 24d2fc96b..a054ea4f5 100644--- a/tools/oracle/sky.mjs+++ b/tools/oracle/sky.mjs@@ -11,9 +11,9 @@** 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 { scene, camera, mesh, sun, probe, probeFrom, SIZE } from './scene.mjs';import { volume } from './scene.mjs';-import { axisAngle, rotate, norm, dot, encodeLinear8, clamp01, smoothstep } from './formulas.mjs';+import { axisAngle, rotate, norm, dot, encodeLinear8, clamp01, smoothstep, srgbDecode, sunAim } 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;@@ -163,6 +163,43 @@ function cloudShadow({ id, ortho, altitude, shadowed }) {return { id, doc, colorSpace: 'linear', expect, floorAltitude, about: `Cloud shadow, ${ortho ? 'orthographic' : 'perspective'} camera, slab ${shadowed ? 'above' : 'below'} the floor` };}++/**+ * A custom sky is the user's own radiance function of the view direction, laid under the scene the way the built-in dome is. The host's+ * `oracleSky` is a gradient by height plus the sun's light in a lobe round the sun, so a pixel is that sum exactly. An orthographic camera's+ * rays are parallel, so all of its pixels look along one direction and must be one colour.+ */+function customSky({ id, ortho, pitch, yaw, sunPitch, sunYaw, intensity = 0.9 }) {+ const aim = sunAim(sunPitch, sunYaw), sunColour = [1, 0.5, 0.25], sunI = 1;+ const doc = scene(id, () => [+ camera(ortho ? {} : { projectionType: 0, fov: FOV, nearPlane: 1, farPlane: 2000 }),+ sun(aim, sunI, sunColour),+ volume([{ type: 'oracleSky', enabled: true, uniforms: { u_intensity: intensity } }]),+ ]);+ 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 sunLinear = sunColour.map(srgbDecode).map((c) => c * sunI);+ const radiance = (dir) => {+ const t = clamp01(dir[1] * 0.5 + 0.5), g = Math.pow(Math.max(dot(dir, aim.toLight), 0), 64) * 0.5;+ return [0.6, 0.3, 0.1].map((h, k) => ([0.1, 0.3, 0.8][k] - h) * t + h + sunLinear[k] * g).map((v) => v * intensity);+ };+ const expect = [];+ const grid = 6;+ 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 = ortho ? pixelDirOrtho(pitch, yaw) : pixelDir(i, j, pitch, yaw);+ expect.push({ x: i / (SIZE - 1), y: j / (SIZE - 1), rgb: encodeLinear8(radiance(dir).map(clamp01)), tol: 4 });+ }+ }+ // Every pixel one colour is the point of the orthographic case, and the harness wants that said: the colour, and all of the frame's pixels.+ const uniform = ortho ? { uniform: true, count: [{ rgb: expect[0].rgb, tol: 4, atLeast: SIZE * SIZE }] } : {};+ return { id, doc, colorSpace: 'linear', expect, ...uniform, about: `Custom sky: gradient + sun lobe, ${ortho ? 'orthographic (one direction, one colour)' : 'perspective'}` };+}+/** The one direction every ray of an orthographic camera looks along. */+const pixelDirOrtho = (pitch, yaw) => norm(rotate(axisAngle([0, 1, 0], yaw), rotate(axisAngle([1, 0, 0], pitch), [0, 0, -1])));+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 }),@@ -175,4 +212,7 @@ export const SKY_SCENES = [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 }),+ // The sun is 50 degrees up toward yaw 20; the camera looks 40 up toward it, so the lobe is on screen 10 degrees above the middle.+ customSky({ id: 'oracle-custom-sky-perspective', ortho: false, pitch: 40, yaw: 20, sunPitch: 50, sunYaw: 200 }),+ customSky({ id: 'oracle-custom-sky-ortho', ortho: true, pitch: 40, yaw: 20, sunPitch: 50, sunYaw: 200 }),];diff --git a/tools/render-host/host.ts b/tools/render-host/host.tsindex ffa9c56c5..e91b8a6d5 100644--- a/tools/render-host/host.ts+++ b/tools/render-host/host.ts@@ -95,6 +95,21 @@ defineSkyEffect({}`,});+// A sky with a known formula, for the oracle scenes (tools/oracle/sky.mjs): a gradient from a warm horizon to a blue zenith by the+// height of the view direction, and the sun's colour in a narrow lobe round the sun, so that what a pixel shows is a sum a test can write.+defineSkyEffect({+ type: 'oracleSky',+ label: 'Oracle Sky',+ glsl: `vec3 skyRadiance(vec3 dir, vec3 sun, vec3 sunColor, float env) {+ float t = clamp(dir.y * 0.5 + 0.5, 0.0, 1.0);+ return mix(vec3(0.6, 0.3, 0.1), vec3(0.1, 0.3, 0.8), t) + sunColor * pow(max(dot(dir, sun), 0.0), 64.0) * 0.5;+}`,+ wgsl: `fn skyRadiance(dir : vec3f, sun : vec3f, sunColor : vec3f, env : f32) -> vec3f {+ let t = clamp(dir.y * 0.5 + 0.5, 0.0, 1.0);+ return mix(vec3f(0.6, 0.3, 0.1), vec3f(0.1, 0.3, 0.8), t) + sunColor * pow(max(dot(dir, sun), 0.0), 64.0) * 0.5;+}`,+});+async function boot(): Promise<void> {canvas = document.createElement('canvas');canvas.id = 'canvas';