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
feat(environment): a directional light can be the environment's sun
esengine18991d26b7fc
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 23d3285d9..5e3c3dbe9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,12 +16,16 @@ published separately; it ships inside the editor.### Added+- **A directional light can be the environment's sun.** An HDRI with a sun in it lit a scene twice when the scene also had a sun — once in the environment's diffuse light, spread across the whole sky and into every shadow, and once from the light — and the two pointed wherever each was set. Importing a `.hdr` now finds its sun: the compact region around its brightest texel, when it carries a real share of the light. The `.esenv` keeps the full irradiance and adds the sun's direction, its strength and the sky's irradiance without it. A Directional light with **Follow Environment Sun** takes its direction and strength from that sun, turned with the environment and scaled by the ambient light as the panorama is; its own colour and intensity scale it on top. The environment then lights with the sky alone. The editor draws the light along the sun, and a light following an environment with no sun is left out of the frame with the reason in the Inspector. Bakes resolve it the same way. Under ORCA Bistro's HDRI the sunlit street's colour now matches the reference render, and its shadows are blue sky rather than warm sun. Reimport a `.hdr` to add its sun.+- **Baked light is a lit surface's indirect light.** A lit renderer — every imported model's is — reads its patch of the atlas in place of the environment's diffuse light and a probe volume's, and keeps its lamps, shadows and reflections live. The bake holds the sky as it reaches each point past whatever stands in the way, plus what the surfaces around give off, over as many bounces as asked: under ORCA Bistro's awnings and in its side streets the sky is now mostly hidden, where before every point got all of it. Before, a model's material never read the atlas at all, and a mesh drawn without one added it on top of the sky and the lamps and was lit twice. The sky a bake gathers is the environment's own irradiance, turned and tinted as the frame reads it, so an open floor bakes to exactly what the frame would light it with. An atlas holds light up to eight times a flat ambient of one, where eight plain bits stopped at one. A cutout lets the share of rays that meets its holes through, both faces of a two-sided surface give off light, and a layer lying closer above a surface than half a lumel — a decal, a wet sheen — no longer walls it off from the sky. A scene baked before reads as stale: its atlas is in the old encoding and must be baked again.- **A bake uses every core, in C++.** The ray casting runs in a compiled kernel (`build-tools/lightmap`, built from `tools/lightmap-wasm`) on every core, with a tree built for tracing rather than for building quickly. Its rules are the TypeScript solve's, rounding included, and a gate holds the two to the same atlas bytes; any thread count writes the same bytes. ORCA Bistro — 1.2 million lumels, 2.8 million triangles — bakes in 44 s on a 20-thread machine, where a pool of worker threads took 312 s and one thread twenty-five to fifty-five minutes; the solve itself is 36 s of that. The kernel also decodes the textures a surface's colour is averaged from, side by side: Bistro's 132 took 2 s instead of 20. The editor and `bake-scene` both use it. Two triangles a ray meets at the same distance now go to the lower-numbered one, so the answer no longer depends on how a tree is built; physics-3d's committed bake moved by one step in two texels.- **A model whose second UV set cannot be baked into gets a lightmap UV in its place.** One that covers under 5% of its square pays for the empty rest — ORCA Bistro's road, 3533 m² in 0.5% of it, asked for more atlas than the rest of the town together — and one that lies on itself gives every copy the same texel's light: Bistro's curbs share one strip eighty layers deep, and a building's facades a hundred. Import unwraps either instead and says why; `import-model --lightmap-uv` turns generation on from the command line. A bake names a surface whose UVs overlap, and one that does not fit names the three surfaces taking the most room and how much of their square their UVs cover.### Fixed+- **`bake-scene` refuses a scene made of prefab instances instead of crashing on it.** It cannot expand an instance, so it found nothing to bake and then threw on the instance entity; it now says to bake such a scene in the editor, as it already did for parented entities.+- **An environment is no longer mirrored.** A panorama was read with its left and right swapped, so a camera facing its centre saw what the photographer saw on the left on its right — in the sky, in reflections and in the light the environment casts. ORCA Bistro's HDRI put its sun on the wrong side of the street. The sky, reflections and irradiance now read a panorama as it was shot, through one mapping, and a gate draws a panorama that is red left of its centre and blue right of it. Reimport a `.hdr` to pick it up; a scene that was turned to suit the mirror needs its `environmentRotation` set again.- **A baked atlas ships at the size it was baked.** Its import settings took the texture default of a 2048 cap, so a 4096 bake was halved on export and each object's light ran into its neighbours'. A bake now owns the atlas's import settings — linear, uncompressed, clamped, and never capped below the atlas — and puts them back on every bake, keeping the file's id.diff --git a/desktop b/desktopindex a760cc652..969a0fae8 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit a760cc652259e1c5a03d9f218b5f1f7e8a01fb4d+Subproject commit 969a0fae843b68ddb54b5634dd9882111a2ab476diff --git a/fixtures/scenes/environment-sun.esscene b/fixtures/scenes/environment-sun.esscenenew file mode 100644index 000000000..1e2113d55--- /dev/null+++ b/fixtures/scenes/environment-sun.esscene@@ -0,0 +1,202 @@+{+ "version": 4,+ "name": "EnvironmentSun",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -150.0,+ "y": 260.0,+ "z": 260.0+ },+ "rotation": {+ "w": 0.8963317066047576,+ "x": -0.316678121858697,+ "y": -0.2926043897956301,+ "z": -0.1033784791113607+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "fov": 45.0,+ "nearPlane": 10,+ "farPlane": 3000,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Ground",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 0.7071067811865476,+ "x": -0.7071067811865476,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 800,+ "y": 800,+ "z": 1+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "/scenes/shadow-quad.esmesh",+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "lit": true,+ "opaque": true,+ "enabled": true,+ "cullBackfaces": false+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Board",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 100,+ "z": 0+ },+ "rotation": {+ "w": 0.7071067811865476,+ "x": 0,+ "y": -0.7071067811865476,+ "z": 0+ },+ "scale": {+ "x": 40,+ "y": 200,+ "z": 1+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "/scenes/shadow-quad.esmesh",+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "lit": true,+ "opaque": true,+ "enabled": true,+ "cullBackfaces": false+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "Sun",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "intensity": 1,+ "meshShadows": true,+ "followEnvironmentSun": true+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "Sky",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 2,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "intensity": 1,+ "environment": "/scenes/sun-sky.esenv",+ "environmentRotation": 90.0+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/environment-sun.esscene.meta b/fixtures/scenes/environment-sun.esscene.metanew file mode 100644index 000000000..abb7117e6--- /dev/null+++ b/fixtures/scenes/environment-sun.esscene.meta@@ -0,0 +1,4 @@+{+ "uuid": "992c6b45-b39e-4dc3-abc8-e8ccb5d74713",+ "type": "scene"+}diff --git a/fixtures/scenes/sun-sky.esenv b/fixtures/scenes/sun-sky.esenvnew file mode 100644index 000000000..06534d549--- /dev/null+++ b/fixtures/scenes/sun-sky.esenv@@ -0,0 +1,77 @@+{+ "version": 1,+ "irradiance": [+ 1.1830618381500244,+ 1.1830618381500244,+ 1.1830618381500244,+ 0.9661282896995544,+ 0.9661282896995544,+ 0.9661282896995544,+ 0.3140670955181122,+ 0.3140670955181122,+ 0.3140670955181122,+ 0.4959662854671478,+ 0.4959662854671478,+ 0.4959662854671478,+ 0.3400169312953949,+ 0.3400169312953949,+ 0.3400169312953949,+ 0.2153133600950241,+ 0.2153133600950241,+ 0.2153133600950241,+ -0.17653414607048035,+ -0.17653414607048035,+ -0.17653414607048035,+ 0.1281142234802246,+ 0.1281142234802246,+ 0.1281142234802246,+ -0.18458040058612823,+ -0.18458040058612823,+ -0.18458040058612823+ ],+ "specular": "sun-sky_env.png",+ "faceSize": 32,+ "mipCount": 3,+ "maxRange": 8,+ "sun": {+ "direction": [+ 0.4864736034193525,+ 0.8175848131515838,+ 0.3080560119200414+ ],+ "color": [+ 0.9963383771443479,+ 0.9963383771443479,+ 0.9963383771443479+ ],+ "skyIrradiance": [+ 0.3001233637332916,+ 0.3001233637332916,+ 0.3001233637332916,+ 0.1325940638780594,+ 0.1325940638780594,+ 0.1325940638780594,+ -3.573217000063522e-10,+ -3.573217000063522e-10,+ -3.573217000063522e-10,+ 9.747006535221203e-10,+ 9.747006535221203e-10,+ 9.747006535221203e-10,+ -1.4746449894520453e-10,+ -1.4746449894520453e-10,+ -1.4746449894520453e-10,+ -7.244330829658807e-11,+ -7.244330829658807e-11,+ -7.244330829658807e-11,+ -8.36777235235786e-06,+ -8.36777235235786e-06,+ -8.36777235235786e-06,+ -9.076692522591578e-12,+ -9.076692522591578e-12,+ -9.076692522591578e-12,+ -1.4714895769429859e-05,+ -1.4714895769429859e-05,+ -1.4714895769429859e-05+ ]+ }+}diff --git a/fixtures/scenes/sun-sky.esenv.meta b/fixtures/scenes/sun-sky.esenv.metanew file mode 100644index 000000000..8960fd7ec--- /dev/null+++ b/fixtures/scenes/sun-sky.esenv.meta@@ -0,0 +1,6 @@+{+ "uuid": "a389b937-09e4-487c-b97e-8f3192eaadc3",+ "version": "2.0",+ "type": "environment",+ "importer": {}+}diff --git a/fixtures/scenes/sun-sky.hdr b/fixtures/scenes/sun-sky.hdrnew file mode 100644index 000000000..9b26e6813--- /dev/null+++ b/fixtures/scenes/sun-sky.hdr@@ -0,0 +1,5 @@+#?RADIANCE+FORMAT=32-bit_rle_rgbe++-Y 64 +X 128+���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~�������~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���~���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{���{\ No newline at end of filediff --git a/fixtures/scenes/sun-sky_env.png b/fixtures/scenes/sun-sky_env.pngnew file mode 100644index 000000000..a5936e4d7Binary files /dev/null and b/fixtures/scenes/sun-sky_env.png differdiff --git a/fixtures/scenes/sun-sky_env.png.meta b/fixtures/scenes/sun-sky_env.png.metanew file mode 100644index 000000000..80e37b130--- /dev/null+++ b/fixtures/scenes/sun-sky_env.png.meta@@ -0,0 +1,26 @@+{+ "uuid": "cea648cc-adc0-42f3-8815-6f1328b04717",+ "version": "2.0",+ "type": "texture",+ "importer": {+ "maxSize": 2048,+ "compress": false,+ "compressFormat": "uastc",+ "filterMode": "linear",+ "wrapMode": "clamp",+ "sRGB": false,+ "mipCoverage": 0,+ "sliceBorder": {+ "left": 0,+ "right": 0,+ "top": 0,+ "bottom": 0+ },+ "sheet": {+ "cellWidth": 0,+ "cellHeight": 0,+ "margin": 0,+ "spacing": 0+ }+ }+}diff --git a/pipeline/src/assets/environmentImport.ts b/pipeline/src/assets/environmentImport.tsindex 075b5bcf0..7bc6feb93 100644--- a/pipeline/src/assets/environmentImport.ts+++ b/pipeline/src/assets/environmentImport.ts@@ -44,6 +44,21 @@ export interface EnvironmentAssetData {/** The panorama itself, for drawing the sky: equirectangular, row 0 up, RGBM* under the same `maxRange`. Absent draws the sky from the atlas' mip 0. */sky?: string;+ /** The sun, when the panorama has one: what a directional light following the+ * environment casts. Absent for a sky with no compact source bright enough. */+ sun?: EnvironmentSun;+}++/** A panorama's sun, separated from its sky. */+export interface EnvironmentSun {+ /** Toward the sun, in the panorama's frame, unit length. */+ direction: [number, number, number];+ /** Its irradiance over π per channel: the unit `irradiance` is in, and what a+ * light's colour times intensity is. */+ color: [number, number, number];+ /** `irradiance` with the sun's texels filled from the sky around them — what+ * the environment lights with while a light casts the sun. */+ skyIrradiance: number[];}export const ENVIRONMENT_FORMAT_VERSION = 1;@@ -436,6 +451,111 @@ export function encodeSkyPanorama(env: Panorama, maxWidth = ENV_SKY_MAX_WIDTH,return { width, height, rgba };}+/** Past this solid angle a bright region is a patch of sky, not a sun: the real+ * disc is 7e-5 sr, and this leaves room for the halo a photograph gives it. */+const SUN_MAX_SOLID_ANGLE = 0.005;+/** A texel belongs to the sun above this fraction of the brightest one... */+const SUN_EDGE_OF_PEAK = 0.002;+/** ...and above this many times the panorama's median, so a flat sky has none. */+const SUN_OVER_MEDIAN = 20;+/** The least share of the panorama's light a sun must carry to be worth a light. */+const SUN_MIN_SHARE = 0.05;++/**+ * Find the panorama's sun and take it out of the sky, or null when it has none.+ *+ * The region around the brightest texel, bright against both peak and sky: too+ * wide is a lit patch of sky, too faint a highlight. Its irradiance is summed, not+ * fitted, so the light replacing it gives what the texels gave.+ */+export function separateSun(env: Panorama): EnvironmentSun | null {+ const { width: W, height: H, rgb } = env;+ const n = W * H;+ const lum = new Float32Array(n);+ let peak = 0, at = -1;+ for (let i = 0; i < n; i++) {+ const l = 0.2126 * rgb[i * 3]! + 0.7152 * rgb[i * 3 + 1]! + 0.0722 * rgb[i * 3 + 2]!;+ lum[i] = l;+ if (l > peak) { peak = l; at = i; }+ }+ if (!(peak > 0)) return null;+ const median = Float32Array.from(lum).sort()[n >> 1]!;+ const edge = Math.max(peak * SUN_EDGE_OF_PEAK, median * SUN_OVER_MEDIAN);+ if (!(peak > edge)) return null;++ const dTheta = Math.PI / H, dPhi = (2 * Math.PI) / W;+ const solidAngle = (y: number): number => Math.sin((y + 0.5) * dTheta) * dTheta * dPhi;+ let total = 0;+ for (let y = 0; y < H; y++) {+ const sa = solidAngle(y);+ for (let x = 0; x < W; x++) total += lum[y * W + x]! * sa;+ }++ const inSun = new Uint8Array(n);+ const region: number[] = [];+ const stack = [at];+ inSun[at] = 1;+ let omega = 0;+ while (stack.length > 0) {+ const i = stack.pop()!;+ region.push(i);+ const x = i % W, y = (i - x) / W;+ omega += solidAngle(y);+ if (omega > SUN_MAX_SOLID_ANGLE) return null;+ for (let dy = -1; dy <= 1; dy++) {+ const ny = y + dy;+ if (ny < 0 || ny >= H) continue;+ for (let dx = -1; dx <= 1; dx++) {+ const j = ny * W + ((x + dx + W) % W);+ if (!inSun[j] && lum[j]! > edge) { inSun[j] = 1; stack.push(j); }+ }+ }+ }++ const energy = [0, 0, 0];+ const toward = [0, 0, 0];+ let power = 0;+ for (const i of region) {+ const x = i % W, y = (i - x) / W;+ const sa = solidAngle(y);+ for (let c = 0; c < 3; c++) energy[c]! += rgb[i * 3 + c]! * sa;+ const d = panoramaDirection((x + 0.5) / W, (y + 0.5) / H);+ const w = lum[i]! * sa;+ power += w;+ for (let c = 0; c < 3; c++) toward[c]! += d[c]! * w;+ }+ if (power < total * SUN_MIN_SHARE) return null;+ const length = Math.hypot(toward[0]!, toward[1]!, toward[2]!);+ if (!(length > 0)) return null;++ // The hole is filled with the sky that rims it, so the coefficients keep the+ // brightness around the sun and lose only the sun.+ const ring = [0, 0, 0];+ let rim = 0;+ for (const i of region) {+ const x = i % W, y = (i - x) / W;+ for (let dy = -1; dy <= 1; dy++) {+ const ny = y + dy;+ if (ny < 0 || ny >= H) continue;+ for (let dx = -1; dx <= 1; dx++) {+ const j = ny * W + ((x + dx + W) % W);+ if (inSun[j]) continue;+ for (let c = 0; c < 3; c++) ring[c]! += rgb[j * 3 + c]!;+ rim++;+ }+ }+ }+ const sky = Float32Array.from(rgb);+ for (const i of region) {+ for (let c = 0; c < 3; c++) sky[i * 3 + c] = rim > 0 ? ring[c]! / rim : 0;+ }+ return {+ direction: [toward[0]! / length, toward[1]! / length, toward[2]! / length],+ color: [energy[0]! / Math.PI, energy[1]! / Math.PI, energy[2]! / Math.PI],+ skyIrradiance: Array.from(projectIrradianceSH({ width: W, height: H, rgb: sky })),+ };+}+/** Everything a `.hdr` becomes, less the reference the caller has to resolve. */export interface ImportedEnvironment {/** `<stem>_env.png` — the octahedral atlas. */@@ -470,6 +590,7 @@ export function importEnvironment(bytes: Uint8Array, stem: string,+ ' equirectangular projection is; it was wrapped as if it were');}const irradiance = projectIrradianceSH(panorama);+ const sun = separateSun(panorama);const atlas = prefilterOctahedral(panorama, faceSize, mipCount, ENV_MAX_RANGE);const skyWidth = options.skyWidth ?? ENV_SKY_MAX_WIDTH;const sky = skyWidth > 0 ? encodeSkyPanorama(panorama, skyWidth, ENV_MAX_RANGE) : null;@@ -485,6 +606,7 @@ export function importEnvironment(bytes: Uint8Array, stem: string,faceSize,mipCount,maxRange: ENV_MAX_RANGE,+ ...(sun ? { sun } : {}),},};}diff --git a/pipeline/src/assets/lightmapBake.ts b/pipeline/src/assets/lightmapBake.tsindex 33a49bbed..24bc6a80d 100644--- a/pipeline/src/assets/lightmapBake.ts+++ b/pipeline/src/assets/lightmapBake.ts@@ -318,6 +318,39 @@ export async function bakeSceneLightmapParallel(input: SceneBakeInput,}}+/**+ * A light following the environment's sun given that sun — turned with the+ * environment, scaled by the ambient light as the panorama is — and the sky without+ * it, as the frame does. A follower with no sun is left out, and said to be.+ */+export function resolveEnvironmentSun(lights: readonly BakeLight[],+ environment: BakeEnvironment | null | undefined,+ ambient: readonly [number, number, number],+ warnings: string[]):+ { lights: BakeLight[]; environment: BakeEnvironment | null | undefined } {+ if (!lights.some((l) => l.followsEnvironmentSun)) return { lights: [...lights], environment };+ const sun = environment?.document.sun;+ if (!environment || !sun) {+ warnings.push('a light follows the environment\'s sun, and '+ + (environment ? 'the environment has none' : 'the scene has no environment')+ + ' — it is left out of the bake');+ return { lights: lights.filter((l) => !l.followsEnvironmentSun), environment };+ }+ const a = ((environment.rotation ?? 0) * Math.PI) / 180;+ const c = Math.cos(a), s = Math.sin(a);+ const [x, y, z] = sun.direction;+ const toward: [number, number, number] = [c * x + s * z, y, -s * x + c * z];+ return {+ lights: lights.map((l) => (!l.followsEnvironmentSun ? l : {+ ...l,+ direction: [-toward[0], -toward[1], -toward[2]] as const,+ color: [sun.color[0] * ambient[0] * l.color[0], sun.color[1] * ambient[1] * l.color[1],+ sun.color[2] * ambient[2] * l.color[2]] as const,+ })),+ environment: { ...environment, document: { ...environment.document, irradiance: sun.skyIrradiance } },+ };+}+/*** @param averages One decode per texture however many objects share it: a bake* reads these once and a scene reuses the same few across most of its@@ -326,6 +359,8 @@ export async function bakeSceneLightmapParallel(input: SceneBakeInput,function* sceneBakeSteps(input: SceneBakeInput, averages = new Map<string, TextureStats | null>(),cutoffs = new Map<string, number>()): Generator<BakeStep, SceneBakeResult, void> {const warnings: string[] = [];+ const { lights, environment } = resolveEnvironmentSun(input.lights, input.environment,+ input.options?.ambient ?? [0, 0, 0], warnings);const surfaces: BakeSurface[] = [];const slot: number[] = [];let moving = 0;@@ -398,12 +433,12 @@ function* sceneBakeSteps(input: SceneBakeInput, averages = new Map<string, Textuconst reflectionProbes = input.reflectionProbes ?? [];const reflectionOptions = {reflectionProbes: reflectionProbes.map((p) => p.center),- reflectionSky: bakeSky(input.environment, ambient),- sky: irradianceSky(input.environment, ambient),+ reflectionSky: bakeSky(environment, ambient),+ sky: irradianceSky(environment, ambient),};const packReflections = (panoramas: CapturedPanorama[]): ReflectionBakeResult | null => {if (reflectionProbes.length === 0) return null;- const packed = bakeSceneReflections({ panoramas, environment: input.environment, ambient });+ const packed = bakeSceneReflections({ panoramas, environment: environment, ambient });for (const w of packed.warnings) warnings.push(w);return packed;};@@ -417,7 +452,7 @@ function* sceneBakeSteps(input: SceneBakeInput, averages = new Map<string, Textuwarnings.push('nothing in this scene can receive baked light');// The volumes are still solved: a scene whose only light is ambient has// nothing to bake into an atlas and still has somewhere to stand.- const empty = yield* bakeLightmapSteps([], input.lights,+ const empty = yield* bakeLightmapSteps([], lights,{ ...input.options, probeGrids: grids, ...reflectionOptions });gridSlot.forEach((at, k) => { probes[at] = asDocument(grids[k], empty.probes[k]); });return {@@ -429,7 +464,7 @@ function* sceneBakeSteps(input: SceneBakeInput, averages = new Map<string, Textu};}- const result = yield* bakeLightmapSteps(surfaces, input.lights,+ const result = yield* bakeLightmapSteps(surfaces, lights,{ ...input.options, probeGrids: grids, ...reflectionOptions });result.shared.forEach((share, k) => {if (share > 0.25) {diff --git a/pipeline/tests/environment-import.test.ts b/pipeline/tests/environment-import.test.tsindex cb6146297..e63a0c232 100644--- a/pipeline/tests/environment-import.test.ts+++ b/pipeline/tests/environment-import.test.ts@@ -14,7 +14,7 @@ import { describe, it, expect } from 'vitest';import {decodeRadianceHdr, projectIrradianceSH, evalIrradianceSH, samplePanorama,octEncode, octDecode, encodeRgbm, decodeRgbm, atlasLayout, prefilterOctahedral,- importEnvironment, mipCountFor, ENV_MAX_RANGE, encodeSkyPanorama,+ importEnvironment, mipCountFor, ENV_MAX_RANGE, encodeSkyPanorama, separateSun,type Panorama,} from '../src/assets/environmentImport';@@ -295,3 +295,42 @@ describe('panorama sampling', () => {expect(out[0]).toBeCloseTo(3.5, 1);});});++describe('the sun an import separates from its sky', () => {+ const W = 128, H = 64;+ // One texel of sun above a dim sky, sized to give irradiance/pi of 1 facing it.+ const sunAt = [43, 12] as const;+ const sa = Math.sin((sunAt[1] + 0.5) * Math.PI / H) * (Math.PI / H) * (2 * Math.PI / W);+ const sky = (x: number, y: number): [number, number, number] =>+ x === sunAt[0] && y === sunAt[1] ? [Math.PI / sa, 0.5 * Math.PI / sa, 0.25 * Math.PI / sa]+ : y < H / 2 ? [0.15, 0.15, 0.15] : [0.02, 0.02, 0.02];++ it('finds it where it is, as bright as it is, and leaves the sky without it', () => {+ const doc = importEnvironment(flatHdr(W, H, sky), 'sunny', { faceSize: 8, skyWidth: 0 }).document;+ const sun = doc.sun!;+ const phi = ((sunAt[0] + 0.5) / W - 0.5) * 2 * Math.PI, theta = (sunAt[1] + 0.5) / H * Math.PI;+ const toward = [-Math.sin(theta) * Math.sin(phi), Math.cos(theta), Math.sin(theta) * Math.cos(phi)];+ toward.forEach((c, i) => expect(sun.direction[i]).toBeCloseTo(c, 4));+ // RGBE keeps eight bits of mantissa, so the texel comes back within a percent.+ [1, 0.5, 0.25].forEach((c, i) => expect(sun.color[i]! / c).toBeCloseTo(1, 1));+ // Up-facing, the sky alone is its radiance: what is left once the sun is out.+ expect(sun.skyIrradiance[0]).toBeLessThan(doc.irradiance[0]! * 0.5);+ const noSun = importEnvironment(flatHdr(W, H, (_x, y) => (y < H / 2 ? [0.15, 0.15, 0.15] : [0.02, 0.02, 0.02])),+ 'overcast', { faceSize: 8, skyWidth: 0 }).document;+ for (let i = 0; i < 27; i++) expect(sun.skyIrradiance[i]).toBeCloseTo(noSun.irradiance[i]!, 2);+ });++ it('is not found in a sky with no compact source', () => {+ const overcast = importEnvironment(flatHdr(W, H, (_x, y) => (y < H / 2 ? [1, 1, 1] : [0.1, 0.1, 0.1])),+ 'overcast', { faceSize: 8, skyWidth: 0 });+ expect(overcast.document.sun).toBeUndefined();+ // A bright WINDOW is a patch of sky: too wide for one direction to stand in for it.+ const window = { rgb: new Float32Array(W * H * 3), width: W, height: H };+ for (let y = 0; y < H; y++) for (let x = 0; x < W; x++) {+ const v = x > 40 && x < 80 && y > 10 && y < 30 ? 50 : 0.1;+ window.rgb.set([v, v, v], (y * W + x) * 3);+ }+ expect(separateSun(window)).toBeNull();+ });+});+diff --git a/pipeline/tests/lightmap-bake.test.ts b/pipeline/tests/lightmap-bake.test.tsindex fc9daed28..73fa06546 100644--- a/pipeline/tests/lightmap-bake.test.ts+++ b/pipeline/tests/lightmap-bake.test.ts@@ -13,7 +13,7 @@ import { tmpdir } from 'node:os';import path from 'node:path';import { encodeMesh, unwrapLightmapUV, decodeLightmap, MeshChannel, MeshChannelType,type MeshData, type BakeLight } from 'esengine';-import { bakeSceneLightmap, claimLightmapImage, type SceneBakeSurface } from '../src/assets/lightmapBake';+import { bakeSceneLightmap, claimLightmapImage, resolveEnvironmentSun, type SceneBakeSurface } from '../src/assets/lightmapBake';import { encodeRgbaPng } from '../src/assets/png';import { decodeRgbaPng } from '../src/assets/tilesetExtrude';@@ -261,3 +261,40 @@ describe('the atlas file a bake writes', () => {expect((await meta()).importer.maxSize).toBe(4096);});});++describe('a light following the environment\'s sun, in a bake', () => {+ const sky = Array.from({ length: 27 }, (_, i) => i / 10);+ const withoutSun = Array.from({ length: 27 }, (_, i) => i / 100);+ const environment = {+ document: { version: 1, irradiance: sky, specular: '', faceSize: 8, mipCount: 1, maxRange: 8,+ sun: { direction: [0.6, 0.8, 0] as [number, number, number], color: [2, 1, 0.5] as [number, number, number],+ skyIrradiance: withoutSun } },+ atlasPng: new Uint8Array(), rotation: 90,+ };+ const follower = { kind: 'directional' as const, direction: [0, 0, -1] as const, color: [1, 1, 1] as const,+ intensity: 3, followsEnvironmentSun: true };+ const lamp = { kind: 'point' as const, position: [0, 0, 0] as const, color: [1, 1, 1] as const, intensity: 1 };++ it('casts the sun as the frame does, and bakes the sky without it', () => {+ const warnings: string[] = [];+ const out = resolveEnvironmentSun([follower, lamp], environment, [0.5, 0.5, 0.5], warnings);+ // Turned 90 degrees about +Y the sun stands toward -Z; the light travels away from it.+ const [x, y, z] = out.lights[0]!.direction!;+ expect([x, y, z].map((v) => Math.round(v * 1e6) / 1e6)).toEqual([-0, -0.8, 0.6]);+ expect(out.lights[0]!.color).toEqual([1, 0.5, 0.25]);+ expect(out.lights[0]!.intensity).toBe(3);+ expect(out.lights[1]).toEqual(lamp);+ expect(out.environment!.document.irradiance).toBe(withoutSun);+ expect(warnings).toEqual([]);+ });++ it('leaves a follower out, and says so, where the environment has no sun', () => {+ const warnings: string[] = [];+ const noSun = { ...environment, document: { ...environment.document, sun: undefined } };+ const out = resolveEnvironmentSun([follower, lamp], noSun, [1, 1, 1], warnings);+ expect(out.lights).toEqual([lamp]);+ expect(out.environment!.document.irradiance).toBe(sky);+ expect(warnings[0]).toMatch(/environment has none/);+ });+});+diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex a5d511b0c..32805dd4f 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -5,7 +5,7 @@ Symbols: 115 public · 91 beta · 1526 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```-"101981b3fea145cb"+"73d45f32834f0b85"```## ANCHOR_AXES — const @experimental@@ -1324,6 +1324,7 @@ type: "audio"```color: { r?: number; g?: number; b?: number; } | undefinedenabled: boolean | undefined+followEnvironmentSun: boolean | undefinedinnerAngle: number | undefinedintensity: number | undefinedouterAngle: number | undefined@@ -1404,6 +1405,7 @@ volumes: readonly { center: readonly [number, number, number]; halfExtents: read```color: readonly [number, number, number]direction: readonly [number, number, number] | undefined+followsEnvironmentSun: boolean | undefinedinnerCos: number | undefinedintensity: numberkind: "directional" | "point" | "spot"@@ -4541,6 +4543,7 @@ enabled: booleanenvironment: numberenvironmentRotation: numberfalloff: number+followEnvironmentSun: booleaninnerAngle: numberinnerRadius: numberintensity: number@@ -4572,7 +4575,7 @@ spacing: number```accepted: booleanlimit: number-refusal: "none" | "capacity"+refusal: "none" | "capacity" | "no-environment-sun"refusedCount: numberrequested: number```diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 7a334409b..bdf22cf26 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -5,7 +5,7 @@ Symbols: 115 public · 96 beta · 1545 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```-"101981b3fea145cb"+"73d45f32834f0b85"```## ANCHOR_AXES — const @experimental@@ -1324,6 +1324,7 @@ type: "audio"```color: { r?: number; g?: number; b?: number; } | undefinedenabled: boolean | undefined+followEnvironmentSun: boolean | undefinedinnerAngle: number | undefinedintensity: number | undefinedouterAngle: number | undefined@@ -1404,6 +1405,7 @@ volumes: readonly { center: readonly [number, number, number]; halfExtents: read```color: readonly [number, number, number]direction: readonly [number, number, number] | undefined+followsEnvironmentSun: boolean | undefinedinnerCos: number | undefinedintensity: numberkind: "directional" | "point" | "spot"@@ -4549,6 +4551,7 @@ enabled: booleanenvironment: numberenvironmentRotation: numberfalloff: number+followEnvironmentSun: booleaninnerAngle: numberinnerRadius: numberintensity: number@@ -4580,7 +4583,7 @@ spacing: number```accepted: booleanlimit: number-refusal: "none" | "capacity"+refusal: "none" | "capacity" | "no-environment-sun"refusedCount: numberrequested: number```diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 0328c4b70..f1e128497 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -1319,6 +1319,7 @@ type: "audio"```color: { r?: number; g?: number; b?: number; } | undefinedenabled: boolean | undefined+followEnvironmentSun: boolean | undefinedinnerAngle: number | undefinedintensity: number | undefinedouterAngle: number | undefined@@ -1399,6 +1400,7 @@ volumes: readonly { center: readonly [number, number, number]; halfExtents: read```color: readonly [number, number, number]direction: readonly [number, number, number] | undefined+followsEnvironmentSun: boolean | undefinedinnerCos: number | undefinedintensity: numberkind: "directional" | "point" | "spot"@@ -4536,6 +4538,7 @@ enabled: booleanenvironment: numberenvironmentRotation: numberfalloff: number+followEnvironmentSun: booleaninnerAngle: numberinnerRadius: numberintensity: number@@ -4567,7 +4570,7 @@ spacing: number```accepted: booleanlimit: number-refusal: "none" | "capacity"+refusal: "none" | "capacity" | "no-environment-sun"refusedCount: numberrequested: number```diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex d7a2483cd..1e95a6e55 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -1319,6 +1319,7 @@ type: "audio"```color: { r?: number; g?: number; b?: number; } | undefinedenabled: boolean | undefined+followEnvironmentSun: boolean | undefinedinnerAngle: number | undefinedintensity: number | undefinedouterAngle: number | undefined@@ -1399,6 +1400,7 @@ volumes: readonly { center: readonly [number, number, number]; halfExtents: read```color: readonly [number, number, number]direction: readonly [number, number, number] | undefined+followsEnvironmentSun: boolean | undefinedinnerCos: number | undefinedintensity: numberkind: "directional" | "point" | "spot"@@ -4536,6 +4538,7 @@ enabled: booleanenvironment: numberenvironmentRotation: numberfalloff: number+followEnvironmentSun: booleaninnerAngle: numberinnerRadius: numberintensity: number@@ -4567,7 +4570,7 @@ spacing: number```accepted: booleanlimit: number-refusal: "none" | "capacity"+refusal: "none" | "capacity" | "no-environment-sun"refusedCount: numberrequested: number```diff --git a/sdk/etc/wasm.api.md b/sdk/etc/wasm.api.mdindex 45341c628..4d81556a7 100644--- a/sdk/etc/wasm.api.md+++ b/sdk/etc/wasm.api.md@@ -306,6 +306,7 @@ engine_setRandomSeed: ((seed: number) => void) | undefinedenvironment_create: ((shPtr: number, specularHandle: number, faceSize: number, mipCount: number, maxRange: number, columns: number) => number) | undefinedenvironment_release: ((environmentHandle: number) => void) | undefinedenvironment_setSky: ((environmentHandle: number, skyHandle: number) => void) | undefined+environment_setSun: ((environmentHandle: number, skyShPtr: number, dx: number, dy: number, dz: number, r: number, g: number, b: number) => void) | undefinedes_getMallocBytes: (() => number) | undefinedesshader_cookInfo: (source: string, featuresCsv: string) => { valid: boolean; error?: string; name: string; domain: string; hasWgslVertex: boolean; hasWgslFragment: boolean; hasSwitches: boolean; vertGlsl: string; fragGlsl: string; textures: Array<{ name: string; unit: number; }>; }geometry_create: () => numberdiff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex 51394069c..7a9a32274 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -1319,6 +1319,7 @@ type: "audio"```color: { r?: number; g?: number; b?: number; } | undefinedenabled: boolean | undefined+followEnvironmentSun: boolean | undefinedinnerAngle: number | undefinedintensity: number | undefinedouterAngle: number | undefined@@ -1399,6 +1400,7 @@ volumes: readonly { center: readonly [number, number, number]; halfExtents: read```color: readonly [number, number, number]direction: readonly [number, number, number] | undefined+followsEnvironmentSun: boolean | undefinedinnerCos: number | undefinedintensity: numberkind: "directional" | "point" | "spot"@@ -4543,6 +4545,7 @@ enabled: booleanenvironment: numberenvironmentRotation: numberfalloff: number+followEnvironmentSun: booleaninnerAngle: numberinnerRadius: numberintensity: number@@ -4574,7 +4577,7 @@ spacing: number```accepted: booleanlimit: number-refusal: "none" | "capacity"+refusal: "none" | "capacity" | "no-environment-sun"refusedCount: numberrequested: number```diff --git a/sdk/src/asset/loaders/EnvironmentAssetLoader.ts b/sdk/src/asset/loaders/EnvironmentAssetLoader.tsindex 615e47152..bb114acc9 100644--- a/sdk/src/asset/loaders/EnvironmentAssetLoader.ts+++ b/sdk/src/asset/loaders/EnvironmentAssetLoader.ts@@ -21,6 +21,15 @@ interface EnvironmentAssetData {columns?: number;/** The panorama the sky is drawn from, a sibling of the document. */sky?: string;+ /** The sun the importer separated from the sky, for a Light to follow. */+ sun?: {+ /** Toward the sun, in the panorama's frame. */+ direction: number[];+ /** Its irradiance over pi. */+ color: number[];+ /** The nine coefficients without it. */+ skyIrradiance: number[];+ };}/** A baked environment, named by the handle a Light references. */@@ -82,6 +91,20 @@ export class EnvironmentAssetLoader implements AssetLoader<EnvironmentResult> {throw new Error(`the engine rejected the environment in ${path}`);}+ const sun = data.sun;+ if (sun && m.environment_setSun) {+ if (sun.skyIrradiance?.length === 27 && sun.direction?.length === 3 && sun.color?.length === 3) {+ withScratch(m, (alloc) => {+ const shPtr = alloc(27 * 4);+ m.HEAPF32.set(Float32Array.from(sun.skyIrradiance), shPtr >> 2);+ m.environment_setSun!(handle, shPtr, sun.direction[0]!, sun.direction[1]!,+ sun.direction[2]!, sun.color[0]!, sun.color[1]!, sun.color[2]!);+ });+ } else {+ log.warn('asset', `${path}: a sun needs a direction, a colour and nine sky coefficients`);+ }+ }+// Missing, the sky falls back to the atlas: coarser, never absent.if (data.sky && m.environment_setSky) {const resolved = resolveDocumentRef(path, data.sky);diff --git a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts b/sdk/src/ecs/bridge/nativeEngineApi.generated.tsindex 7cd86bebd..48b1152c2 100644--- a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts+++ b/sdk/src/ecs/bridge/nativeEngineApi.generated.ts@@ -54,6 +54,7 @@ export interface NativeEngineApi {environment_create?(shPtr: number, specularHandle: number, faceSize: number, mipCount: number, maxRange: number, columns: number): number;environment_release?(environmentHandle: number): void;environment_setSky?(environmentHandle: number, skyHandle: number): void;+ environment_setSun?(environmentHandle: number, skyShPtr: number, dx: number, dy: number, dz: number, r: number, g: number, b: number): void;geometry_create?(): number;geometry_init?(handle: number, verticesPtr: number, vertexCount: number, layoutPtr: number, layoutCount: number, dynamic: boolean): void;geometry_isValid?(handle: number): boolean;@@ -331,6 +332,7 @@ export function createNativeEngineApi(bind('environment_create', 'es_environment_create', false);bind('environment_release', 'es_environment_release', false);bind('environment_setSky', 'es_environment_setSky', false);+ bind('environment_setSun', 'es_environment_setSun', false);bind('geometry_create', 'es_geometry_create', false);bind('geometry_init', 'es_geometry_init', false);bind('geometry_isValid', 'es_geometry_isValid', false);diff --git a/sdk/src/ecs/bridge/nativeRenderer.ts b/sdk/src/ecs/bridge/nativeRenderer.tsindex 9517233db..e3932fa45 100644--- a/sdk/src/ecs/bridge/nativeRenderer.ts+++ b/sdk/src/ecs/bridge/nativeRenderer.ts@@ -20,6 +20,7 @@ import type { CppRegistry } from '../../wasm';import type { RendererBackend, RenderStats } from '../../render/renderer';import { RENDERER_BINDINGS, RENDERER_OPTIONAL_BINDINGS, RENDERER_STATS_BINDINGS } from './nativeBindings';import { createNativeHeap, type NativeHeap } from './nativeHeap';+import { ATLAS_REFUSAL, LIGHT_REFUSAL } from '../../render/refusals';/** Invoke a host-provided global by name; throws if the host did not bind it* (these are the frame contract — a missing one is a broken host, not a@@ -66,7 +67,7 @@ export function createNativeRendererBackend(if (lodScratch) return lodScratch;const heap = createNativeHeap(scope);if (!heap) return null;- lodScratch = { heap, ptr: heap._malloc(5 * 4) };+ lodScratch = { heap, ptr: heap._malloc(9 * 4) };return lodScratch;};return {@@ -156,7 +157,7 @@ export function createNativeRendererBackend(if (!(fn as (e: number, p: number) => number)(entity >>> 0, heap.ptr)) return null;const f = heap.heap.HEAPF32;const i = heap.ptr >> 2;- const refusal = (['none', 'tile-budget', 'tile-too-large', 'atlas-full'] as const)[f[i + 2]!];+ const refusal = ATLAS_REFUSAL[f[i + 2]!];return {requested: f[i]!, granted: f[i + 1]!, refusal: refusal ?? 'none',deniedCasters: f[i + 3]!, reducedCasters: f[i + 4]!,@@ -171,8 +172,9 @@ export function createNativeRendererBackend(const i = heap.ptr >> 2;return {accepted: f[i] === 1,- refusal: f[i + 1] === 1 ? 'capacity' : 'none',+ refusal: LIGHT_REFUSAL[f[i + 1]!] ?? 'none',limit: f[i + 2]!, requested: f[i + 3]!, refusedCount: f[i + 4]!,+ environmentSunAim: f[i + 5] === 1 ? [f[i + 6]!, f[i + 7]!, f[i + 8]!] : null,};},setLodPreview: (view, entity, level): void => {diff --git a/sdk/src/ecs/bridge/ptrAccessors.generated.ts b/sdk/src/ecs/bridge/ptrAccessors.generated.tsindex aa0729edb..bb3770b7c 100644--- a/sdk/src/ecs/bridge/ptrAccessors.generated.ts+++ b/sdk/src/ecs/bridge/ptrAccessors.generated.ts@@ -814,6 +814,7 @@ export interface LightPtrData {shadowDistance: number;meshShadows: boolean;shadowExtent: number;+ followEnvironmentSun: boolean;environment: number;environmentRotation: number;drawEnvironment: boolean;@@ -840,10 +841,11 @@ export function fillLight(out.shadowDistance = f32[(ptr + 68) >> 2];out.meshShadows = u8[ptr + 72] !== 0;out.shadowExtent = f32[(ptr + 76) >> 2];- out.environment = u32[(ptr + 80) >> 2];- out.environmentRotation = f32[(ptr + 84) >> 2];- out.drawEnvironment = u8[ptr + 88] !== 0;- out.enabled = u8[ptr + 89] !== 0;+ out.followEnvironmentSun = u8[ptr + 80] !== 0;+ out.environment = u32[(ptr + 84) >> 2];+ out.environmentRotation = f32[(ptr + 88) >> 2];+ out.drawEnvironment = u8[ptr + 92] !== 0;+ out.enabled = u8[ptr + 93] !== 0;}export function writeLight(@@ -866,10 +868,11 @@ export function writeLight(f32[(ptr + 68) >> 2] = data.shadowDistance;u8[ptr + 72] = data.meshShadows ? 1 : 0;f32[(ptr + 76) >> 2] = data.shadowExtent;- u32[(ptr + 80) >> 2] = data.environment;- f32[(ptr + 84) >> 2] = data.environmentRotation;- u8[ptr + 88] = data.drawEnvironment ? 1 : 0;- u8[ptr + 89] = data.enabled ? 1 : 0;+ u8[ptr + 80] = data.followEnvironmentSun ? 1 : 0;+ u32[(ptr + 84) >> 2] = data.environment;+ f32[(ptr + 88) >> 2] = data.environmentRotation;+ u8[ptr + 92] = data.drawEnvironment ? 1 : 0;+ u8[ptr + 93] = data.enabled ? 1 : 0;}export function createLightData(): LightPtrData {@@ -890,6 +893,7 @@ export function createLightData(): LightPtrData {shadowDistance: 0,meshShadows: false,shadowExtent: 0,+ followEnvironmentSun: false,environment: 0,environmentRotation: 0,drawEnvironment: false,diff --git a/sdk/src/ecs/component.generated.ts b/sdk/src/ecs/component.generated.tsindex 0292e3cdb..3b0cf2936 100644--- a/sdk/src/ecs/component.generated.ts+++ b/sdk/src/ecs/component.generated.ts@@ -15,7 +15,7 @@ import type { AlignContent, AlignItems, AlignSelf, BodyType, CanvasScaleMode, Cl* getAbiLayoutHash(); BuiltinBridge.connect() compares them and refuses to* run on mismatch, because mismatched offsets read the wrong heap bytes.*/-export const ABI_LAYOUT_HASH = '101981b3fea145cb';+export const ABI_LAYOUT_HASH = '73d45f32834f0b85';/*** One asset-valued field of a component: which field, and what kind of@@ -475,6 +475,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {shadowDistance: 0,meshShadows: false,shadowExtent: 0,+ followEnvironmentSun: false,environment: 0,environmentRotation: 0,drawEnvironment: false,@@ -501,6 +502,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {shadowDistance: { min: 0, tooltip: "Directional shadow distance; 0 = no directional shadow.", advanced: true, shownWhen: { field: "type", values: [1] } },meshShadows: { tooltip: "Cast a shadow map over 3D meshes (Directional, Spot, Point).", shownWhen: { field: "type", values: [0, 1, 3] } },shadowExtent: { min: 0, tooltip: "Shadow map coverage radius; 0 = fit the view.", advanced: true, shownWhen: { field: "type", values: [1] } },+ followEnvironmentSun: { tooltip: "Take direction and strength from the environment's sun, and light the sky without it.", shownWhen: { field: "type", values: [1] } },environment: { tooltip: "Baked environment (.esenv) this Ambient light casts.", shownWhen: { field: "type", values: [2] } },environmentRotation: { unit: "deg", tooltip: "Turn the environment about the up axis, in degrees.", shownWhen: { field: "type", values: [2] } },drawEnvironment: { tooltip: "Draw this environment as the sky behind the scene.", shownWhen: { field: "type", values: [2] } },@@ -1449,6 +1451,7 @@ export interface LightData {shadowDistance: number;meshShadows: boolean;shadowExtent: number;+ followEnvironmentSun: boolean;environment: number;environmentRotation: number;drawEnvironment: boolean;diff --git a/sdk/src/lightmap/fingerprint.ts b/sdk/src/lightmap/fingerprint.tsindex 7046bd59f..439d3783e 100644--- a/sdk/src/lightmap/fingerprint.ts+++ b/sdk/src/lightmap/fingerprint.ts@@ -78,7 +78,8 @@ export function bakeFingerprint(inputs: BakeInputs): string {}for (const l of inputs.lights) {lines.push(`l|${l.kind}|${nums(l.position)}|${nums(l.direction)}|${nums(l.color)}`- + `|${num(l.intensity)}|${num(l.radius)}|${num(l.innerCos)}|${num(l.outerCos)}`);+ + `|${num(l.intensity)}|${num(l.radius)}|${num(l.innerCos)}|${num(l.outerCos)}`+ + `${l.followsEnvironmentSun ? '|sun' : ''}`);}for (const v of inputs.volumes) {lines.push(`v|${nums(v.center)}|${nums(v.halfExtents)}|${num(v.spacing)}`);diff --git a/sdk/src/lightmap/lights.ts b/sdk/src/lightmap/lights.tsindex 1e5066dba..2ec67071c 100644--- a/sdk/src/lightmap/lights.ts+++ b/sdk/src/lightmap/lights.ts@@ -22,6 +22,7 @@ export interface AuthoredLight {radius?: number;innerAngle?: number;outerAngle?: number;+ followEnvironmentSun?: boolean;enabled?: boolean;}@@ -78,6 +79,7 @@ export function bakeLightOf(authored: AuthoredLight | undefined,radius: kind === 'directional' ? undefined : (v.radius ?? 200),innerCos: cos(v.innerAngle ?? 30),outerCos: cos(v.outerAngle ?? 45),+ ...(kind === 'directional' && v.followEnvironmentSun ? { followsEnvironmentSun: true } : {}),},};}diff --git a/sdk/src/lightmap/solve.ts b/sdk/src/lightmap/solve.tsindex c48cf8275..6ca8c1acf 100644--- a/sdk/src/lightmap/solve.ts+++ b/sdk/src/lightmap/solve.ts@@ -28,6 +28,9 @@ export interface BakeLight {/** Cosines of the half angles a spot falls off between. */innerCos?: number;outerCos?: number;+ /** Directional only: this light is the environment's sun. The bake takes its+ * direction and colour from there, and the sky without it. */+ followsEnvironmentSun?: boolean;}/** Where a ray that hit triangle `t` lands in the atlas, and what it reflects. */diff --git a/sdk/src/render/refusals.ts b/sdk/src/render/refusals.tsnew file mode 100644index 000000000..0f1e7c6bb--- /dev/null+++ b/sdk/src/render/refusals.ts@@ -0,0 +1,16 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file refusals.ts+ * @brief The engine's refusal codes as the words a reader gets.+ *+ * Indexed by the number the engine writes, in the order of its enums+ * (LightRefusal in LightPlan.hpp, the atlas refusal in ShadowPlan). The web and+ * native backends read the same codes, so they read them through one table.+ */++/** Why a light did not reach the frame. */+export const LIGHT_REFUSAL = ['none', 'capacity', 'no-environment-sun'] as const;++/** Why a shadow caster got fewer tiles than it asked for. */+export const ATLAS_REFUSAL = ['none', 'tile-budget', 'tile-too-large', 'atlas-full'] as const;diff --git a/sdk/src/render/renderer.ts b/sdk/src/render/renderer.tsindex c19537958..3865c8ece 100644--- a/sdk/src/render/renderer.ts+++ b/sdk/src/render/renderer.ts@@ -9,6 +9,7 @@ import { findWebGL2Context } from '../asset/glTextureUpload';import { log } from '../util/logger';import { decodeFrameCapture, replayToDrawCall as replayToDrawCallImpl, getSnapshotImageData as getSnapshotImpl, snapshotMatchesCapture as snapshotMatchesImpl, type FrameCaptureData } from './frameCapture';import { acquireWebGPUDevice } from './webgpuBoot';+import { ATLAS_REFUSAL, LIGHT_REFUSAL } from './refusals';export enum RenderStage {Background = 0,@@ -96,7 +97,7 @@ export interface ShadowStatus {* `atlas-full` is fixed by a bigger atlas, and `tile-budget` is the shader's* array bound, which no size changes.*/- refusal: 'none' | 'tile-budget' | 'tile-too-large' | 'atlas-full';+ refusal: (typeof ATLAS_REFUSAL)[number];/** Casters the frame denied outright, for a reader that wants the total. */deniedCasters: number;/** Casters that kept fewer tiles than they asked for. */@@ -114,13 +115,16 @@ export interface ShadowStatus {export interface LightStatus {accepted: boolean;/** Why not, when `accepted` is false; `none` otherwise. */- refusal: 'none' | 'capacity';+ refusal: (typeof LIGHT_REFUSAL)[number];/** The shader's array bound — what `accepted` lights can never exceed. */limit: number;/** Lights that asked this frame. */requested: number;/** How many the frame turned away, for a reader that wants the total. */refusedCount: number;+ /** Where the environment's sun shone this frame, when a light followed it —+ * the aim such a light takes instead of its Transform's. */+ environmentSunAim: [number, number, number] | null;}/**@@ -154,7 +158,6 @@ let lodInspectPtr: number = 0;* through. One buffer: neither answer outlives the call that asks. */let lightStatusPtr: number = 0;/** AtlasRefusal, in the order ShadowAtlas.hpp declares it. */-const ATLAS_REFUSAL: ShadowStatus['refusal'][] = ['none', 'tile-budget', 'tile-too-large', 'atlas-full'];let backend: RendererBackend | null = null;/** The wasm backend: every call marshals through the module's heap, exactly as@@ -263,11 +266,12 @@ function wasmBackend(m: ESEngineModule): RendererBackend {lightStatus: (entity) => {if (!m.renderer_lightStatus || !lightStatusPtr) return null;if (!m.renderer_lightStatus(entity >>> 0, lightStatusPtr)) return null;- const f = m.HEAPF32.subarray(lightStatusPtr >> 2, (lightStatusPtr >> 2) + 5);+ const f = m.HEAPF32.subarray(lightStatusPtr >> 2, (lightStatusPtr >> 2) + 9);return {accepted: f[0] === 1,- refusal: f[1] === 1 ? 'capacity' : 'none',+ refusal: LIGHT_REFUSAL[f[1]!] ?? 'none',limit: f[2]!, requested: f[3]!, refusedCount: f[4]!,+ environmentSunAim: f[5] === 1 ? [f[6]!, f[7]!, f[8]!] : null,};},getStats: () => ({@@ -499,7 +503,7 @@ export function initRendererAPI(wasmModule: ESEngineModule): void {installContextLossGuard(module);viewProjectionPtr = module._malloc(16 * 4);lodInspectPtr = module._malloc(4 * 4);- lightStatusPtr = module._malloc(5 * 4);+ lightStatusPtr = module._malloc(9 * 4);backend = wasmBackend(module);}diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.tsindex c40398b83..4744784ed 100644--- a/sdk/src/wasm.ts+++ b/sdk/src/wasm.ts@@ -341,6 +341,13 @@ export interface ESEngineModule {/** Release an environment; its atlas is an ordinary texture and outlives it. */environment_release?(environmentHandle: number): void;environment_setSky?(environmentHandle: number, skyHandle: number): void;+ /**+ * Give an environment the sun its importer separated from the sky: 27 floats of+ * irradiance without it, the direction toward it (panorama frame) and its+ * irradiance over pi — what a Light following it casts.+ */+ environment_setSun?(environmentHandle: number, skyShPtr: number, dx: number, dy: number,+ dz: number, r: number, g: number, b: number): void;/*** Register a grid of baked irradiance: `resX*resY*resZ*27` floats, nine RGB* coefficients per probe with x varying fastest. The same nine an environmentdiff --git a/sdk/src/wasm/ptrLayouts.generated.ts b/sdk/src/wasm/ptrLayouts.generated.tsindex be61b6125..7820ff4ea 100644--- a/sdk/src/wasm/ptrLayouts.generated.ts+++ b/sdk/src/wasm/ptrLayouts.generated.ts@@ -243,10 +243,11 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {{ name: 'shadowDistance', type: 'f32', offset: 68 },{ name: 'meshShadows', type: 'bool', offset: 72 },{ name: 'shadowExtent', type: 'f32', offset: 76 },- { name: 'environment', type: 'u32', offset: 80 },- { name: 'environmentRotation', type: 'f32', offset: 84 },- { name: 'drawEnvironment', type: 'bool', offset: 88 },- { name: 'enabled', type: 'bool', offset: 89 },+ { name: 'followEnvironmentSun', type: 'bool', offset: 80 },+ { name: 'environment', type: 'u32', offset: 84 },+ { name: 'environmentRotation', type: 'f32', offset: 88 },+ { name: 'drawEnvironment', type: 'bool', offset: 92 },+ { name: 'enabled', type: 'bool', offset: 93 },],},LightProbeVolume: {diff --git a/sdk/src/wasm/wasm.generated.ts b/sdk/src/wasm/wasm.generated.tsindex 6b2c3f572..dbb6092f7 100644--- a/sdk/src/wasm/wasm.generated.ts+++ b/sdk/src/wasm/wasm.generated.ts@@ -577,6 +577,7 @@ export interface Light {shadowDistance: number;meshShadows: boolean;shadowExtent: number;+ followEnvironmentSun: boolean;environment: number;environmentRotation: number;drawEnvironment: boolean;diff --git a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snapindex ac00c9e52..80be1a570 100644--- a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap+++ b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap@@ -278,6 +278,15 @@ exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapsho},"tooltip": "Falloff shape: 1 = linear, higher pools near the light, lower reaches further.",},+ "followEnvironmentSun": {+ "shownWhen": {+ "field": "type",+ "values": [+ 1,+ ],+ },+ "tooltip": "Take direction and strength from the environment's sun, and light the sky without it.",+ },"innerAngle": {"advanced": true,"max": 180,diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cppindex 081672bb0..f98f2da10 100644--- a/src/esengine/bindings/EditorAPI.generated.cpp+++ b/src/esengine/bindings/EditorAPI.generated.cpp@@ -2,10 +2,10 @@* @file EditorAPI.generated.cpp* @brief Auto-generated editor API with string-dispatched component access* @details Generated by EHT - DO NOT EDIT- * @schema_hash 0e795e9f8a75e456+ * @schema_hash 0687add0b330ecdc*/-#define ES_EDITOR_API_SCHEMA_HASH "0e795e9f8a75e456"+#define ES_EDITOR_API_SCHEMA_HASH "0687add0b330ecdc"#include <emscripten/bind.h>#include <string>@@ -349,6 +349,7 @@ std::string editor_getComponentSchema(const std::string& name) {{"key":"shadowDistance","type":"float","group":"Light"},{"key":"meshShadows","type":"bool","group":"Light"},{"key":"shadowExtent","type":"float","group":"Light"},+ {"key":"followEnvironmentSun","type":"bool","group":"Light"},{"key":"environment","type":"asset","group":"Light"},{"key":"environmentRotation","type":"float","group":"Light"},{"key":"drawEnvironment","type":"bool","group":"Light"},@@ -2754,6 +2755,7 @@ bool editor_setBool(Registry& reg, u32 e, const std::string& comp, const std::stif (!reg.has<esengine::ecs::Light>(entity)) return false;auto& c = reg.get<esengine::ecs::Light>(entity);if (field == "meshShadows") { c.meshShadows = value; }+ else if (field == "followEnvironmentSun") { c.followEnvironmentSun = value; }else if (field == "drawEnvironment") { c.drawEnvironment = value; }else if (field == "enabled") { c.enabled = value; }else { return false; }@@ -3009,6 +3011,7 @@ bool editor_getBool(Registry& reg, u32 e, const std::string& comp, const std::stif (!reg.has<esengine::ecs::Light>(entity)) return false;const auto& c = reg.get<esengine::ecs::Light>(entity);if (field == "meshShadows") { return c.meshShadows; }+ else if (field == "followEnvironmentSun") { return c.followEnvironmentSun; }else if (field == "drawEnvironment") { return c.drawEnvironment; }else if (field == "enabled") { return c.enabled; }} else if (comp == "LightProbeVolume") {diff --git a/src/esengine/bindings/RendererBindings.cpp b/src/esengine/bindings/RendererBindings.cppindex dcc32536a..e6d8f745e 100644--- a/src/esengine/bindings/RendererBindings.cpp+++ b/src/esengine/bindings/RendererBindings.cpp@@ -433,6 +433,31 @@ void environment_setSky(u32 environmentHandle, u32 skyHandle) {}}+/**+ * @brief Gives an environment the sun its importer separated from the sky.+ * @param skyShPtr 27 floats — the irradiance with the sun taken out.+ * @param dx,dy,dz Toward the sun, in the panorama's frame.+ * @param r,g,b The sun's irradiance over pi.+ */+void environment_setSun(u32 environmentHandle, uintptr_t skyShPtr, f32 dx, f32 dy, f32 dz,+ f32 r, f32 g, f32 b) {+ auto* rm = ctx().tryGet<resource::ResourceManager>();+ if (!rm) return;+ const f32* sh = boundarySpan<f32>(skyShPtr, 27, "environment_setSun.skyIrradiance");+ if (!sh) return;+ Environment* environment = rm->getEnvironment(resource::EnvironmentHandle(environmentHandle));+ if (!environment) return;+ const glm::vec3 toward(dx, dy, dz);+ const f32 length = glm::length(toward);+ if (!(length > 0.0f)) return;+ for (usize i = 0; i < 9; ++i) {+ environment->skyIrradiance[i] = glm::vec3(sh[i * 3], sh[i * 3 + 1], sh[i * 3 + 2]);+ }+ environment->sunDirection = toward / length;+ environment->sunColor = glm::max(glm::vec3(r, g, b), glm::vec3(0.0f));+ environment->hasSun = true;+}+/** @brief Releases an environment. Its atlas is an ordinary texture and outlives it. */void environment_release(u32 environmentHandle) {if (auto* rm = ctx().tryGet<resource::ResourceManager>()) {@@ -1028,9 +1053,9 @@ void renderer_setLodPreview(u32 view, u32 entity, i32 level) {}i32 renderer_lightStatus(u32 entity, uintptr_t outPtr) {- auto* out = boundarySpanMut<f32>(outPtr, 5, "renderer_lightStatus.out");+ auto* out = boundarySpanMut<f32>(outPtr, 9, "renderer_lightStatus.out");if (!out) return 0;- for (u32 i = 0; i < 5; ++i) out[i] = 0.0f;+ for (u32 i = 0; i < 9; ++i) out[i] = 0.0f;if (!g_renderFrame) return 0;const LightCapReport& cap = g_renderFrame->lightCap();if (cap.limit == 0) return 0; // no frame has decided anything yet@@ -1040,6 +1065,10 @@ i32 renderer_lightStatus(u32 entity, uintptr_t outPtr) {out[2] = static_cast<f32>(cap.limit);out[3] = static_cast<f32>(cap.requested);out[4] = static_cast<f32>(cap.refused.size());+ out[5] = cap.environmentSun ? 1.0f : 0.0f;+ out[6] = cap.environmentSunAim.x;+ out[7] = cap.environmentSunAim.y;+ out[8] = cap.environmentSunAim.z;return 1;}diff --git a/src/esengine/bindings/RendererBindings.hpp b/src/esengine/bindings/RendererBindings.hppindex 0a2c96064..2d1e61056 100644--- a/src/esengine/bindings/RendererBindings.hpp+++ b/src/esengine/bindings/RendererBindings.hpp@@ -100,6 +100,10 @@ void mesh_release(u32 meshHandle);u32 environment_create(uintptr_t shPtr, u32 specularHandle, f32 faceSize, u32 mipCount,f32 maxRange, u32 columns);void environment_setSky(u32 environmentHandle, u32 skyHandle);+/** @brief Gives an environment its separated sun: the sky's irradiance without it+ * (27 floats), the direction toward it and its irradiance over pi. */+void environment_setSun(u32 environmentHandle, uintptr_t skyShPtr, f32 dx, f32 dy, f32 dz,+ f32 r, f32 g, f32 b);/** @brief Releases an environment; its atlas is an ordinary texture and outlives it. */void environment_release(u32 environmentHandle);@@ -207,12 +211,12 @@ i32 renderer_lodInspect(u32 view, u32 entity, uintptr_t outPtr);void renderer_setLodPreview(u32 view, u32 entity, i32 level);/**- * @brief What the light cap did to @p entity last frame, into five floats at- * @p outPtr: accepted, refusal, limit, requested, refusedCount.+ * @brief What the light cap did to @p entity last frame, into nine floats at+ * @p outPtr: accepted, refusal, limit, requested, refusedCount, then whether+ * a light cast the environment's sun and the aim it took.*- * @details One call answers both "why is this light dark" and "how many went- * dark". Returns 0 before any frame has collected lights, which is not- * a frame that refused none.+ * @details Returns 0 before any frame has collected lights, which is not a frame+ * that refused none.*/i32 renderer_lightStatus(u32 entity, uintptr_t outPtr);diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cppindex 3f05f86f0..3d10118ff 100644--- a/src/esengine/bindings/WebBindings.generated.cpp+++ b/src/esengine/bindings/WebBindings.generated.cpp@@ -600,6 +600,7 @@ struct LightJS {f32 shadowDistance;bool meshShadows;f32 shadowExtent;+ bool followEnvironmentSun;u32 environment;f32 environmentRotation;bool drawEnvironment;@@ -623,6 +624,7 @@ void lightApplyJS(esengine::ecs::Light& c, const LightJS& js) {c.shadowDistance = js.shadowDistance;c.meshShadows = js.meshShadows;c.shadowExtent = js.shadowExtent;+ c.followEnvironmentSun = js.followEnvironmentSun;c.environment = resource::EnvironmentHandle(js.environment);c.environmentRotation = js.environmentRotation;c.drawEnvironment = js.drawEnvironment;@@ -653,6 +655,7 @@ LightJS lightToJS(const esengine::ecs::Light& c) {js.shadowDistance = c.shadowDistance;js.meshShadows = c.meshShadows;js.shadowExtent = c.shadowExtent;+ js.followEnvironmentSun = c.followEnvironmentSun;js.environment = c.environment.id();js.environmentRotation = c.environmentRotation;js.drawEnvironment = c.drawEnvironment;@@ -1722,6 +1725,7 @@ EMSCRIPTEN_BINDINGS(esengine_components) {.field("shadowDistance", &LightJS::shadowDistance).field("meshShadows", &LightJS::meshShadows).field("shadowExtent", &LightJS::shadowExtent)+ .field("followEnvironmentSun", &LightJS::followEnvironmentSun).field("environment", &LightJS::environment).field("environmentRotation", &LightJS::environmentRotation).field("drawEnvironment", &LightJS::drawEnvironment)@@ -3343,10 +3347,11 @@ static_assert(offsetof(esengine::ecs::Light, sourceAngle) == 64, "ABI offset dristatic_assert(offsetof(esengine::ecs::Light, shadowDistance) == 68, "ABI offset drift: esengine::ecs::Light.shadowDistance (EHT expected 68)");static_assert(offsetof(esengine::ecs::Light, meshShadows) == 72, "ABI offset drift: esengine::ecs::Light.meshShadows (EHT expected 72)");static_assert(offsetof(esengine::ecs::Light, shadowExtent) == 76, "ABI offset drift: esengine::ecs::Light.shadowExtent (EHT expected 76)");-static_assert(offsetof(esengine::ecs::Light, environment) == 80, "ABI offset drift: esengine::ecs::Light.environment (EHT expected 80)");-static_assert(offsetof(esengine::ecs::Light, environmentRotation) == 84, "ABI offset drift: esengine::ecs::Light.environmentRotation (EHT expected 84)");-static_assert(offsetof(esengine::ecs::Light, drawEnvironment) == 88, "ABI offset drift: esengine::ecs::Light.drawEnvironment (EHT expected 88)");-static_assert(offsetof(esengine::ecs::Light, enabled) == 89, "ABI offset drift: esengine::ecs::Light.enabled (EHT expected 89)");+static_assert(offsetof(esengine::ecs::Light, followEnvironmentSun) == 80, "ABI offset drift: esengine::ecs::Light.followEnvironmentSun (EHT expected 80)");+static_assert(offsetof(esengine::ecs::Light, environment) == 84, "ABI offset drift: esengine::ecs::Light.environment (EHT expected 84)");+static_assert(offsetof(esengine::ecs::Light, environmentRotation) == 88, "ABI offset drift: esengine::ecs::Light.environmentRotation (EHT expected 88)");+static_assert(offsetof(esengine::ecs::Light, drawEnvironment) == 92, "ABI offset drift: esengine::ecs::Light.drawEnvironment (EHT expected 92)");+static_assert(offsetof(esengine::ecs::Light, enabled) == 93, "ABI offset drift: esengine::ecs::Light.enabled (EHT expected 93)");static_assert(offsetof(esengine::ecs::LightProbeVolume, probes) == 0, "ABI offset drift: esengine::ecs::LightProbeVolume.probes (EHT expected 0)");static_assert(offsetof(esengine::ecs::LightProbeVolume, halfExtents) == 4, "ABI offset drift: esengine::ecs::LightProbeVolume.halfExtents (EHT expected 4)");static_assert(offsetof(esengine::ecs::LightProbeVolume, spacing) == 16, "ABI offset drift: esengine::ecs::LightProbeVolume.spacing (EHT expected 16)");@@ -3602,7 +3607,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif// ABI Hash -- runtime handshake against the SDK bundle// =============================================================================-static const char* kEsAbiLayoutHash = "101981b3fea145cb";+static const char* kEsAbiLayoutHash = "73d45f32834f0b85";std::string esengineGetAbiLayoutHash() {return std::string(kEsAbiLayoutHash);diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cppindex 0822b4af9..1767fc566 100644--- a/src/esengine/bindings/WebSDKEntry.cpp+++ b/src/esengine/bindings/WebSDKEntry.cpp@@ -527,6 +527,7 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {emscripten::function("mesh_release", &esengine::mesh_release);emscripten::function("environment_create", &esengine::environment_create);emscripten::function("environment_setSky", &esengine::environment_setSky);+ emscripten::function("environment_setSun", &esengine::environment_setSun);emscripten::function("environment_release", &esengine::environment_release);emscripten::function("probe_volume_create", &esengine::probe_volume_create);emscripten::function("probe_volume_release", &esengine::probe_volume_release);diff --git a/src/esengine/ecs/components/Light.hpp b/src/esengine/ecs/components/Light.hppindex 654a82c22..95417cbe0 100644--- a/src/esengine/ecs/components/Light.hpp+++ b/src/esengine/ecs/components/Light.hpp@@ -159,6 +159,15 @@ struct Light {tooltip="Shadow map coverage radius; 0 = fit the view.")f32 shadowExtent{0.0f};+ /** @brief Be the sun of the frame's environment. The direction and strength come+ * from the panorama, turned with it; @ref color and @ref intensity scale+ * what it gives and the Transform's aim is not read. The environment then+ * lights with its sky alone, since the sun is this light's to cast. A+ * panorama without a sun leaves the light out of the frame, and says so. */+ ES_PROPERTY(shown_when=type:Directional,+ tooltip="Take direction and strength from the environment's sun, and light the sky without it.")+ bool followEnvironmentSun{false};+/** @brief What this Ambient light IS, when it is more than one colour: a baked* panorama's irradiance and reflection. Without one the light stays the* flat term it has always been — the same lighting, at order zero.diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cppindex fb614c971..173d99c5a 100644--- a/src/esengine/renderer/frame/RenderFrame.cpp+++ b/src/esengine/renderer/frame/RenderFrame.cpp@@ -1218,14 +1218,53 @@ void RenderFrame::collectReflections(ecs::Registry& registry) {boxes, highest);}+/// A direction in an environment's own frame, in the world's: the inverse of the+/// shaders' envDirection, which turns a world direction by -yaw about +Y.+static glm::vec3 environmentToWorld(const glm::vec3& d, f32 yawDegrees) {+ const f32 a = glm::radians(yawDegrees);+ const f32 c = std::cos(a), s = std::sin(a);+ return {c * d.x + s * d.z, d.y, -s * d.x + c * d.z};+}+void RenderFrame::collectLights(ecs::Registry& registry) {LightStore& lights = context_.lights();lights.clear();shadow_casters_.clear();+ light_cap_.clear();environment_texture_id_ = 0;sky_texture_id_ = 0;draw_sky_ = false;+ // The frame's environment is decided before any light is: a directional light+ // following its sun needs it, and whether one does decides which irradiance+ // the environment lights with — so the answer cannot depend on registry order.+ auto view = registry.view<ecs::Light>();+ Entity skyLight{};+ const Environment* sky = nullptr;+ glm::vec3 skyScale(0.0f);+ f32 skyYaw = 0.0f;+ bool sunFollowed = false;+ for (auto entity : view) {+ const auto& light = view.get(entity);+ if (!light.enabled || light.intensity <= 0.0f) continue;+ const auto type = static_cast<ecs::LightType>(light.type);+ if (type == ecs::LightType::Directional && light.followEnvironmentSun) sunFollowed = true;+ if (sky || type != ecs::LightType::Ambient || !light.environment.isValid()) continue;+ if (const Environment* environment = resource_manager_.getEnvironment(light.environment)) {+ sky = environment;+ skyLight = entity;+ const glm::vec3 rgb = linear_color_ ? srgbToLinearCpu(glm::vec3{light.color})+ : glm::vec3{light.color};+ skyScale = rgb * light.intensity;+ skyYaw = light.environmentRotation;+ }+ }+ const bool sunCast = sunFollowed && sky && sky->hasSun;+ if (sunCast) {+ light_cap_.environmentSun = true;+ light_cap_.environmentSunAim = -environmentToWorld(sky->sunDirection, skyYaw);+ }+// Gather non-ambient lights, then (if over the UBO's cap) keep the most intense — the// brightest contribute most, and an explicit importance cull beats silently dropping// whichever happened to come last in iteration order. Ambient lights sum without a cap.@@ -1236,7 +1275,6 @@ void RenderFrame::collectLights(ecs::Registry& registry) {// A light's Transform need is type-dependent. Ambient is a flat scene-wide term and// reads none of it; Directional takes only the rotation, so it works without one and// aims into the screen; Point/Spot need a position and are skipped without one.- auto view = registry.view<ecs::Light>();for (auto entity : view) {const auto& light = view.get(entity);if (!light.enabled || light.intensity <= 0.0f) continue;@@ -1250,16 +1288,26 @@ void RenderFrame::collectLights(ecs::Registry& registry) {// An environment REPLACES this light's flat term rather than adding to// it: its coefficients already carry the same colour, and summing both// would light the scene twice from one source.- if (collectEnvironment(light, rgb * light.intensity)) continue;+ if (collectEnvironment(light, rgb * light.intensity,+ sunCast && entity == skyLight)) continue;lights.addAmbient(rgb * light.intensity);continue;}+ const bool followsSun = type == ecs::LightType::Directional && light.followEnvironmentSun;+ if (followsSun && !sunCast) {+ light_cap_.refused.push_back({entity, static_cast<u8>(type), light.intensity,+ LightRefusal::NoEnvironmentSun});+ continue;+ }+GpuLight gpu;bool castsMeshShadow = false;ShadowCaster caster;caster.light = entity;- gpu.color = glm::vec4(rgb, light.intensity);+ // The sun is the environment's, so the ambient light's colour and intensity+ // scale it as they scale the rest of the panorama; this light's own scale on top.+ gpu.color = glm::vec4(followsSun ? sky->sunColor * skyScale * rgb : rgb, light.intensity);// shadow.x = penumbra softness (all types); shadow.y = directional march distance (only the// directional branch of shadowFactor2D reads it; 0 keeps directional shadows off).gpu.shadow = glm::vec4(std::max(light.shadowSoftness, 0.0f),@@ -1274,7 +1322,8 @@ void RenderFrame::collectLights(ecs::Registry& registry) {// z=1 flags directional (no attenuation) in the shader; w carries the aim's third// component, which only a directional light has a use for — point and spot spend// that slot on their falloff radius.- const glm::vec3 aim = lightForward(registry.tryGet<ecs::Transform>(entity));+ const glm::vec3 aim = followsSun ? light_cap_.environmentSunAim+ : lightForward(registry.tryGet<ecs::Transform>(entity));gpu.posDir = glm::vec4(aim.x, aim.y, 1.0f, aim.z);// A source infinitely far away has no half-extent a map can divide by a// distance, so what it carries is the angle it subtends — as its tangent,@@ -1329,9 +1378,8 @@ void RenderFrame::collectLights(ecs::Registry& registry) {collected.push_back({gpu, castsMeshShadow, caster});}- light_cap_.clear();light_cap_.limit = MAX_LIGHTS;- light_cap_.requested = static_cast<u32>(collected.size());+ light_cap_.requested = static_cast<u32>(collected.size() + light_cap_.refused.size());if (collected.size() > MAX_LIGHTS) {std::partial_sort(collected.begin(), collected.begin() + MAX_LIGHTS, collected.end(),[](const CollectedLight& a, const CollectedLight& b) {@@ -1367,7 +1415,8 @@ void RenderFrame::collectLights(ecs::Registry& registry) {collectShape2D(registry);}-bool RenderFrame::collectEnvironment(const ecs::Light& light, const glm::vec3& scale) {+bool RenderFrame::collectEnvironment(const ecs::Light& light, const glm::vec3& scale,+ bool withoutSun) {if (!light.environment.isValid()) return false;const Environment* environment = resource_manager_.getEnvironment(light.environment);if (!environment) return false;@@ -1381,7 +1430,8 @@ bool RenderFrame::collectEnvironment(const ecs::Light& light, const glm::vec3& sconst glm::vec4 params{textureId != 0 ? 1.0f : 0.0f, environment->maxRange,static_cast<f32>(environment->mipCount) - 1.0f,environment->faceSize};- if (!context_.lights().setEnvironment(environment->irradiance.data(), params, scale,+ const auto& irradiance = withoutSun ? environment->skyIrradiance : environment->irradiance;+ if (!context_.lights().setEnvironment(irradiance.data(), params, scale,glm::radians(light.environmentRotation))) {return false;}diff --git a/src/esengine/renderer/frame/RenderFrame.hpp b/src/esengine/renderer/frame/RenderFrame.hppindex 8e2baf118..70778278c 100644--- a/src/esengine/renderer/frame/RenderFrame.hpp+++ b/src/esengine/renderer/frame/RenderFrame.hpp@@ -612,10 +612,10 @@ private:void collectReflections(ecs::Registry& registry);/// Makes this ambient light the frame's environment, when it names one that is- /// loaded. `scale` is the light's colour times its intensity, folded into the- /// coefficients — an environment is what the light casts, not a second source.+ /// loaded; `scale` (colour times intensity) is folded into the coefficients.+ /// @p withoutSun lights with the sky alone, where a light casts its sun./// @return false when it names none, leaving the caller to add a flat term.- bool collectEnvironment(const ecs::Light& light, const glm::vec3& scale);+ bool collectEnvironment(const ecs::Light& light, const glm::vec3& scale, bool withoutSun);/*** @brief Decides what the shadow pass will draw, without drawing any of it.*diff --git a/src/esengine/renderer/store/LightPlan.hpp b/src/esengine/renderer/store/LightPlan.hppindex e0e96d71e..2cbb72c85 100644--- a/src/esengine/renderer/store/LightPlan.hpp+++ b/src/esengine/renderer/store/LightPlan.hpp@@ -15,6 +15,7 @@#pragma once#include "../../core/Types.hpp"+#include "../../math/Math.hpp"#include <vector>@@ -25,13 +26,16 @@ enum class LightRefusal : u8 {None = 0,/// More lights in view than the shader's arrays hold; the dimmest gave way.Capacity,+ /// Follows the environment's sun, and the frame's environment has none.+ NoEnvironmentSun,};/** @brief The refusal as a word, for a log line and for a reader. */inline const char* lightRefusalName(LightRefusal why) {switch (why) {- case LightRefusal::Capacity: return "light capacity";- case LightRefusal::None: break;+ case LightRefusal::Capacity: return "light capacity";+ case LightRefusal::NoEnvironmentSun: return "no environment sun";+ case LightRefusal::None: break;}return "none";}@@ -60,11 +64,18 @@ struct LightCapReport {/// question this answers is "why is this one dark", and a list of everything/// that worked is a list nobody reads.std::vector<LightGrant> refused;+ /// Whether a light cast the environment's sun this frame, and along what: the+ /// aim such a light takes is the panorama's and not its Transform's, and an+ /// editor drawing it from the Transform would point the wrong way.+ bool environmentSun = false;+ glm::vec3 environmentSunAim{0.0f};void clear() {requested = 0;accepted = 0;refused.clear();+ environmentSun = false;+ environmentSunAim = glm::vec3(0.0f);}/** @brief What `entity` was told, or None when it was not refused. */diff --git a/src/esengine/resource/Environment.hpp b/src/esengine/resource/Environment.hppindex 2583edaf8..6a5994a99 100644--- a/src/esengine/resource/Environment.hpp+++ b/src/esengine/resource/Environment.hpp@@ -44,6 +44,19 @@ public:* reflection probe each — so one bound texture serves them all. */u32 columns = 1;+ /** @brief The sun the importer found in the panorama: the one compact source+ * a directional light can stand in for. The irradiance above still carries+ * it, so a scene without such a light is lit as the photograph was; one with+ * a light following it takes @ref skyIrradiance instead, or the sun counts twice. */+ bool hasSun = false;+ /** Toward the sun, in the panorama's own frame (before any environment rotation). */+ glm::vec3 sunDirection{0.0f, 1.0f, 0.0f};+ /** The sun's irradiance over pi per channel — what a surface facing it adds to+ * albedo, the unit the coefficients are in and a light's colour times intensity is. */+ glm::vec3 sunColor{0.0f};+ /** The same nine coefficients with the sun's texels replaced by the sky around it. */+ std::array<glm::vec3, 9> skyIrradiance{};+bool hasSpecular() const { return specular.isValid() && mipCount > 0 && faceSize > 0.0f; }};diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex d6a2a8a6d..c954fdc62 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -1298,6 +1298,12 @@ export const NOTED = {{ note: 'A baked atlas ships at the size it was baked' },'fix(environment): a panorama is read as it was shot, not mirrored':{ note: 'An environment is no longer mirrored' },+ 'feat(environment): a directional light can be the environment\'s sun':+ { note: 'A directional light can be the environment\'s sun' },+ 'feat(editor): a light following the environment\'s sun is drawn along it':+ { note: 'A directional light can be the environment\'s sun' },+ 'fix(bake-scene): a scene of prefab instances is refused, not crashed on':+ { note: '`bake-scene` refuses a scene made of prefab instances instead of crashing on it' },'fix(bake): a coloured light bakes the colour it lights with':{ note: 'A coloured light bakes the colour it lights with' },'fix(bake): the collector reads the colour space from the engine host':diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjsindex 50c56b069..144ae5f0d 100644--- a/tools/renderScenes.mjs+++ b/tools/renderScenes.mjs@@ -242,6 +242,10 @@ export const SCENES = [// Y up, as a 3D scene is: ground in XZ, a board standing on it, a sun coming DOWN// with a depth component. Every gate above aims its sun in the view plane.{ id: "mesh-shadow-yup", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mesh-shadow-yup.esscene", ESTELLA_VERIFY_W: "512", ESTELLA_VERIFY_H: "512", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.396,\"y\":0.713,\"rgb\":[0,0,0],\"tol\":25},{\"x\":0.549,\"y\":0.891,\"rgb\":[210,210,210],\"tol\":25},{\"x\":0.598,\"y\":0.414,\"rgb\":[210,210,210],\"tol\":25}]" } },+ // A light FOLLOWING the environment's sun: its Transform aims level with the ground,+ // so only the panorama's sun, turned with it, throws the board's shadow — and inside+ // that shadow is the sky alone, without the sun the environment gave away.+ { id: "environment-sun", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/environment-sun.esscene", ESTELLA_VERIFY_W: "512", ESTELLA_VERIFY_H: "512", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.402,\"y\":0.709,\"rgb\":[39,39,39],\"tol\":12},{\"x\":0.556,\"y\":0.884,\"rgb\":[249,249,249],\"tol\":16},{\"x\":0.598,\"y\":0.414,\"rgb\":[249,249,249],\"tol\":16}]" } },// A lamp 120 units ABOVE a panel, a height only real geometry measures against.// Hand-derived, 255·NdotL·atten: 224 under it and 101 at world +200, where the// plane's convention reads 255 and 200.