A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix: preserve tiled lights in planar reflections
yhh7b8ec6b25f36
diff --git a/fixtures/scenes/planar-tiled-lights.esscene b/fixtures/scenes/planar-tiled-lights.esscenenew file mode 100644index 000000000..664442261--- /dev/null+++ b/fixtures/scenes/planar-tiled-lights.esscene@@ -0,0 +1,826 @@+{+ "version": 4,+ "name": "Planar Tiled Lights",+ "entities": [+ {+ "id": 1,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 3,+ "z": 6+ },+ "rotation": {+ "x": -0.22975292,+ "y": 0,+ "z": 0,+ "w": 0.97324899+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 6,+ "isActive": true,+ "clearFlags": 3,+ "nearPlane": 0.1,+ "farPlane": 100+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Mirror",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "rotation": {+ "x": -0.70710678,+ "y": 0,+ "z": 0,+ "w": 0.70710678+ },+ "scale": {+ "x": 7,+ "y": 7,+ "z": 1+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "/scenes/shadow-quad.esmesh",+ "material": "/scenes/mat-planar/mirror.esmaterial",+ "opaque": true,+ "lit": true,+ "enabled": true+ }+ },+ {+ "type": "PlanarReflection",+ "data": {+ "axis": 2,+ "quality": 1,+ "resolutionScale": 1,+ "maxSize": 512,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "Red",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -1.3,+ "y": 1,+ "z": 0+ },+ "scale": {+ "x": 0.01,+ "y": 0.01,+ "z": 0.01+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "opaque": true,+ "cullBackfaces": true,+ "lit": true,+ "layer": 1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ }+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "Green",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 1.3,+ "y": 0.7,+ "z": -0.8+ },+ "scale": {+ "x": 0.007,+ "y": 0.007,+ "z": 0.007+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "opaque": true,+ "cullBackfaces": true,+ "lit": false,+ "layer": 2,+ "color": {+ "r": 0,+ "g": 1,+ "b": 0,+ "a": 1+ }+ }+ }+ ]+ },+ {+ "id": 5,+ "name": "Below plane",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": -1,+ "z": 0+ },+ "scale": {+ "x": 0.007,+ "y": 0.007,+ "z": 0.007+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "opaque": true,+ "lit": false,+ "color": {+ "r": 0,+ "g": 0,+ "b": 1,+ "a": 1+ }+ }+ }+ ]+ },+ {+ "id": 6,+ "name": "Second camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 1.5,+ "y": 3,+ "z": 6+ },+ "rotation": {+ "x": -0.22975292,+ "y": 0,+ "z": 0,+ "w": 0.97324899+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 6,+ "isActive": false,+ "clearFlags": 3,+ "nearPlane": 0.1,+ "farPlane": 100,+ "priority": 1,+ "viewport": {+ "x": 0.5,+ "y": 0,+ "z": 0.5,+ "w": 1+ }+ }+ }+ ]+ },+ {+ "id": 100,+ "name": "Distant light 0",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 100,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 101,+ "name": "Distant light 1",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 101,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 102,+ "name": "Distant light 2",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 102,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 103,+ "name": "Distant light 3",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 103,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 104,+ "name": "Distant light 4",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 104,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 105,+ "name": "Distant light 5",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 105,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 106,+ "name": "Distant light 6",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 106,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 107,+ "name": "Distant light 7",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 107,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 108,+ "name": "Distant light 8",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 108,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 109,+ "name": "Distant light 9",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 109,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 110,+ "name": "Distant light 10",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 110,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 111,+ "name": "Distant light 11",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 111,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 112,+ "name": "Distant light 12",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 112,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 113,+ "name": "Distant light 13",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 113,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 114,+ "name": "Distant light 14",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 114,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 115,+ "name": "Distant light 15",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 115,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 10,+ "radius": 0.1,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 116,+ "name": "Local red light",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -1.3,+ "y": 1,+ "z": 1+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 0,+ "intensity": 8,+ "radius": 1,+ "color": {+ "r": 1,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "enabled": true+ }+ }+ ]+ }+ ]+}diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cppindex 74867c5db..45fef0350 100644--- a/src/esengine/renderer/frame/RenderFrame.cpp+++ b/src/esengine/renderer/frame/RenderFrame.cpp@@ -1818,8 +1818,7 @@ void RenderFrame::collectLights(ecs::Registry& registry) {lights.addLight(collected[slot].gpu);}for (const CollectedLight& light : tiled) {- const glm::vec3 position(light.gpu.posDir.x, light.gpu.posDir.y, light.gpu.shadow.z);- lights.addTiledLight(light.gpu, view_projection_, position, std::max(light.gpu.posDir.w, 0.0f));+ lights.addTiledLight(light.gpu, view_projection_);}// Last, because which lights the mask can carry is a question about the array thediff --git a/src/esengine/renderer/frame/RenderFramePlanar.cpp b/src/esengine/renderer/frame/RenderFramePlanar.cppindex 941a109fc..597a33620 100644--- a/src/esengine/renderer/frame/RenderFramePlanar.cpp+++ b/src/esengine/renderer/frame/RenderFramePlanar.cpp@@ -167,11 +167,12 @@ void RenderFrame::executePlanarReflection(ecs::Registry& registry, u32 view) {planar_pool_.upload();context_.useFrameConstants(capture.frameUbo,toClipDepthRange(capture.camera.projection, device_.clipDepthRange()));- // The tiled lights' masks are for the camera the scene is seen from; this one looks from the mirror.- context_.lights().suspendTiled(true);- context_.lights().uploadAndBind();+ auto& lights = context_.lights();+ lights.setTiledView(capture.camera.projection);+ lights.uploadAndBind();submitColorList(planar_list_, planar_pool_, nullptr, DrawList::Phase::All, "render.planar.prepass.draws");- context_.lights().suspendTiled(false);+ lights.setTiledView(view_projection_);+ ES_PROFILE_COUNTER("render.planar.tiledLights", lights.tiledCount());capture.valid = true;capture.lastTime = planar_elapsed_;capture.draws = planar_list_.mergedDrawCallCount();diff --git a/src/esengine/renderer/store/LightStore.hpp b/src/esengine/renderer/store/LightStore.hppindex 2dc732f6a..9d1a7bde4 100644--- a/src/esengine/renderer/store/LightStore.hpp+++ b/src/esengine/renderer/store/LightStore.hpp@@ -20,6 +20,7 @@#include "../rhi/GfxEnums.hpp"#include "./LightConstants.hpp"+#include <algorithm>#include <cmath>#include <glm/glm.hpp>@@ -73,24 +74,24 @@ public:dirty_ = true;}- /// Appends a light the loop's sixteen did not have room for, to be read through the tile masks: it marks every tile of- /// @p viewProjection its sphere (@p position, @p radius) can reach. Returns false past MAX_TILED_LIGHTS.- bool addTiledLight(const GpuLight& light, const glm::mat4& viewProjection, const glm::vec3& position, f32 radius) {+ /// Appends a positional light past the loop's sixteen and marks the tiles its sphere reaches through @p viewProjection.+ /// Returns false past MAX_TILED_LIGHTS.+ bool addTiledLight(const GpuLight& light, const glm::mat4& viewProjection) {if (tiledCount_ >= MAX_TILED_LIGHTS) return false;data_.tiledLights[tiledCount_] = light;- markLightTiles(viewProjection, position, radius, tiledCount_, reinterpret_cast<u32(*)[4]>(data_.tileMask));+ markTiledLight(tiledCount_, viewProjection);++tiledCount_;data_.tileInfo = glm::vec4(static_cast<f32>(tiledCount_), static_cast<f32>(TILE_COLUMNS), static_cast<f32>(TILE_ROWS), 0.0f);dirty_ = true;return true;}- /// Hides the tiled lights from the passes that follow, which draw through another camera (a planar reflection): their masks- /// were made for the camera this frame is seen from and would be read by pixels they mean nothing to. A false brings them back.- void suspendTiled(bool suspended) {- const f32 count = suspended ? 0.0f : static_cast<f32>(tiledCount_);- if (data_.tileInfo.x == count) return;- data_.tileInfo.x = count;+ /// Reprojects the collected lights for another view without changing their identity, illumination or shadow assignments.+ /// Call again with the source view after drawing a reflection; its post-processing also reads this block.+ void setTiledView(const glm::mat4& viewProjection) {+ if (tiledCount_ == 0) return;+ std::fill_n(data_.tileMask, TILE_COLUMNS * TILE_ROWS, glm::uvec4(0u));+ for (u32 i = 0; i < tiledCount_; ++i) markTiledLight(i, viewProjection);dirty_ = true;}@@ -213,6 +214,13 @@ public:const LightConstants& data() const { return data_; }private:+ void markTiledLight(u32 index, const glm::mat4& viewProjection) {+ const auto& light = data_.tiledLights[index];+ const glm::vec3 position(light.posDir.x, light.posDir.y, light.shadow.z);+ markLightTiles(viewProjection, position, std::max(light.posDir.w, 0.0f), index,+ reinterpret_cast<u32(*)[4]>(data_.tileMask));+ }+LightConstants data_{};u32 count_ = 0;u32 tiledCount_ = 0;diff --git a/tests/renderer/test_tiled_lights.cpp b/tests/renderer/test_tiled_lights.cppindex 376826bba..1bb4ab0a7 100644--- a/tests/renderer/test_tiled_lights.cpp+++ b/tests/renderer/test_tiled_lights.cpp@@ -122,27 +122,60 @@ int main() {CHECK(tilesWithBit(masks, 3) == kTiles, "and one bigger than the view marks them all");}- // --- the store carries what the tiles name, up to its cap, and a reflection pass can hide them+ // --- the store carries what the tiles name, up to its cap, across view changes{LightStore store;store.clear();GpuLight light;- light.posDir = glm::vec4(0.0f, 0.0f, 0.0f, 10.0f);+ light.posDir = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);+ light.shadow.z = -50.0f;light.color = glm::vec4(1.0f, 0.0f, 0.0f, 2.0f);for (u32 i = 0; i < MAX_TILED_LIGHTS; ++i) {- if (!store.addTiledLight(light, vp, glm::vec3(0.0f, 0.0f, -50.0f), 1.0f)) { CHECK(false, "a tiled light was refused under the cap"); break; }+ if (!store.addTiledLight(light, vp)) { CHECK(false, "a tiled light was refused under the cap"); break; }}CHECK(store.tiledCount() == MAX_TILED_LIGHTS && store.data().tileInfo.x == static_cast<f32>(MAX_TILED_LIGHTS),"the store holds a full set of tiled lights and says how many");- CHECK(!store.addTiledLight(light, vp, glm::vec3(0.0f, 0.0f, -50.0f), 1.0f), "and refuses the next");+ CHECK(!store.addTiledLight(light, vp), "and refuses the next");CHECK(store.data().tileInfo.y == static_cast<f32>(TILE_COLUMNS) && store.data().tileInfo.z == static_cast<f32>(TILE_ROWS),"it says the tile grid's size");- store.suspendTiled(true);- CHECK(store.data().tileInfo.x == 0.0f, "suspended, the shader's loop does not run");- store.suspendTiled(false);- CHECK(store.data().tileInfo.x == static_cast<f32>(MAX_TILED_LIGHTS), "and resumed, it does");+ store.setTiledView(vp);+ const auto& centre = store.data().tileMask[(TILE_ROWS / 2) * TILE_COLUMNS + TILE_COLUMNS / 2];+ CHECK(centre.x == 0xffffffffu && centre.y == 0xffffffffu && centre.z == 0xffffffffu && centre.w == 0,+ "reprojection retains all ninety-six light indices across the three mask words");+ CHECK(store.data().tileInfo.x == static_cast<f32>(MAX_TILED_LIGHTS), "another view keeps the full light count");store.clear();+ store.setTiledView(vp);CHECK(store.tiledCount() == 0 && store.data().tileInfo.x == 0.0f, "a new frame starts with none");+ bool empty = true;+ for (const auto& mask : store.data().tileMask) empty &= mask == glm::uvec4(0u);+ CHECK(empty, "an empty view cannot retain the previous frame's light masks");+ }++ // --- reflected coordinates replace the source grid, which can be restored for the source camera and its post-processing+ {+ LightStore store;+ const glm::mat4 source = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, 0.1f, 100.0f);+ const glm::mat4 reflected = source * glm::scale(glm::mat4(1.0f), glm::vec3(-1.0f, 1.0f, 1.0f));+ GpuLight point;+ point.posDir = {-5.0f, -5.0f, 0.0f, 0.25f};+ point.shadow.z = -50.0f;+ point.color = {1.0f, 0.0f, 0.0f, 2.0f};+ GpuLight spot = point;+ spot.posDir = {5.0f, 5.0f, 2.0f, 0.25f};+ spot.spot = {0.0f, 0.0f, 0.9f, 0.5f};+ CHECK(store.addTiledLight(point, source) && store.addTiledLight(spot, source), "point and spot share the view grid");+ const LightConstants original = store.data();+ CHECK((original.tileMask[2 * TILE_COLUMNS + 3].x & 1u) != 0, "the point starts in the lower-left source tiles");+ CHECK((original.tileMask[8 * TILE_COLUMNS + 11].x & 2u) != 0, "the spot starts in the upper-right source tiles");+ store.setTiledView(reflected);+ CHECK((store.data().tileMask[2 * TILE_COLUMNS + 12].x & 1u) != 0, "the point reaches the lower-right reflected tiles");+ CHECK((store.data().tileMask[9 * TILE_COLUMNS + 4].x & 2u) != 0, "the spot reaches the upper-left reflected tiles");+ CHECK((store.data().tileMask[2 * TILE_COLUMNS + 3].x & 1u) == 0, "source tiles are cleared rather than accumulated");+ CHECK(std::memcmp(original.tiledLights, store.data().tiledLights, sizeof(original.tiledLights)) == 0,+ "view changes preserve positions, radii, colours and spot parameters");+ store.setTiledView(source);+ CHECK(std::memcmp(original.tileMask, store.data().tileMask, sizeof(original.tileMask)) == 0,+ "restoring the source view recovers its exact tile masks");}CHECK(sizeof(LightConstants) <= 16384, "the whole block fits the 16 KB a uniform block is guaranteed");diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjsindex f5f0faef8..846affe23 100644--- a/tools/renderScenes.mjs+++ b/tools/renderScenes.mjs@@ -56,6 +56,18 @@ export function sceneWatchdogMs(backend, host) {* verbatim — an empty one is the default sprite scene.*/export const SCENES = [+ {+ id: 'planar-tiled-lights', tier: 'pr', webgpu: true,+ env: {+ ESTELLA_VERIFY_SCENE: '/scenes/planar-tiled-lights.esscene',+ ESTELLA_VERIFY_W: '512', ESTELLA_VERIFY_H: '512', ESTELLA_VERIFY_STEPS: '3',+ ESTELLA_VERIFY_EXPECT: JSON.stringify([+ { x: 200 / 512, y: 210 / 512, rgb: [255, 0, 0], tol: 25 },+ { x: 200 / 512, y: 290 / 512, rgb: [255, 0, 0], tol: 25 },+ ]),+ ESTELLA_VERIFY_COUNTERS: JSON.stringify({ 'render.planar.tiledLights': 1 }),+ },+ },// Full 8x8 corner blocks: native Sprite, 5x-wide Sprite, and shared UI geometry.{ id: 'sprite-nine-slice', tier: 'pr', webgpu: true, env: {ESTELLA_VERIFY_SCENE: '/scenes/sprite-nine-slice.esscene',@@ -979,6 +991,7 @@ const PREPASS_TWINS = [// Scenes that draw opaque meshes already.'mesh-opaque', 'mesh-instanced', 'prepass-hook', 'corpus-cutout-edge', 'mesh-normalmap', 'mesh-shadow-cutout', 'mesh-shadow', 'sun-shadow',{ id: 'planar-reflection', counters: { 'render.planar.prepass.draws': 1 } },+ { id: 'planar-tiled-lights', counters: { 'render.planar.prepass.draws': 2 } },// The same scenes with their meshes made opaque (fixtures/scenes/*-opaque.esscene), for what a mesh can be besides a rigid one that is lit:// skinned, morphing.{ id: 'mesh-skin', scene: 'mesh-skin-opaque.esscene' }, { id: 'mesh-morph-shaped', scene: 'mesh-morph-opaque.esscene' },diff --git a/tools/tests/planar-reflection.e2e.mjs b/tools/tests/planar-reflection.e2e.mjsindex aafeafa54..67b4b5155 100644--- a/tools/tests/planar-reflection.e2e.mjs+++ b/tools/tests/planar-reflection.e2e.mjs@@ -62,10 +62,10 @@ try {await writeFile(path.join(out, `${backend}-${name}.png`), PNG.sync.write(image));return image;};- const changed = (a,b,startY=0) => {+ const changed = (a,b,startY=0,tolerance=40) => {let count=0;for(let i=startY*a.width*4;i<a.data.length;i+=4) {- if(Math.abs(a.data[i]-b.data[i])+Math.abs(a.data[i+1]-b.data[i+1])+Math.abs(a.data[i+2]-b.data[i+2])>40) count++;+ if(Math.abs(a.data[i]-b.data[i])+Math.abs(a.data[i+1]-b.data[i+1])+Math.abs(a.data[i+2]-b.data[i+2])>tolerance) count++;}return count;};@@ -157,7 +157,55 @@ try {assert.ok(pixel(split,72,290)[0]>230,'first view must keep its own reflection');assert.ok(pixel(split,375,268)[1]>230,'second view must capture from its own camera');assert.deepEqual(errors,[]);- report.checks.push({backend,ready,drawsOn,drawsOff,prepassDraws,reflectionPixels:changed(on,off,256),movingPixels:changed(on,moved,256),recovery,secondView,lossLogs,errors});++ // A fresh world: sixteen brighter lights outside the scene move the local light into the tiled list without changing its illumination.+ await page.reload();+ await page.evaluate(async () => { await window.__estellaHeadless.ready; });+ await page.evaluate(() => window.__estellaHeadless.api.setCpuProfiling(true));+ const tiledLoad = await page.evaluate(() => window.__estellaHeadless.api.loadScene('/scenes/planar-tiled-lights.esscene'));+ assert.deepEqual(tiledLoad.missing, []);+ const lightDifference = (a,b) => changed(a,b,0,3);+ const distant = async enabled => {+ for (let id=100;id<116;id++) await field(id,'Light','enabled',enabled);+ await step(3);+ };+ await distant(false);+ const directLight = await capture('direct-light-reference');+ assert.ok(pixel(directLight,200,210)[0]>80,'the reference source must be lit');+ assert.ok(pixel(directLight,200,290)[0]>80,'the reference reflection must be lit');+ await distant(true);+ const tiledLight = await capture('tiled-light');+ const tiledCounters = await page.evaluate(() => window.__estellaHeadless.api.getCounters());+ assert.equal(tiledCounters['render.planar.tiledLights'],1,'the reflection must consume the additional light');+ assert.equal(lightDifference(directLight,tiledLight),0,'moving a light into the tiled list must preserve source and reflected illumination');+ await field(116,'Light','type',3);+ await field(116,'Light','innerAngle',60);+ await field(116,'Light','outerAngle',90);+ await step(3);+ const tiledSpot = await capture('tiled-spot');+ await distant(false);+ const directSpot = await capture('direct-spot');+ assert.ok(pixel(directSpot,200,290)[0]>80,'the reference spot reflection must be lit');+ assert.equal(lightDifference(directSpot,tiledSpot),0,'a spot must preserve its cone and reflected illumination in the tiled list');+ await field(116,'Light','type',0);+ await distant(true);+ await field(116,'Transform','position.x',1.3);+ await field(3,'Transform','position.x',1.3);+ await step(3);+ const tiledMoved = await capture('tiled-light-moved');+ await distant(false);+ const directMoved = await capture('direct-light-moved');+ assert.equal(lightDifference(directMoved,tiledMoved),0,'moving geometry and light must rebuild both views of the light grid');+ assert.ok(changed(directLight,tiledMoved,256)>100,'the reflected light must move with the object');+ await field(1,'Camera','viewport',{x:0,y:0,z:0.5,w:1});+ await field(6,'Camera','isActive',true); await step(3);+ const directSplit = await capture('direct-light-two-cameras');+ await distant(true);+ const tiledSplit = await capture('tiled-light-two-cameras');+ assert.equal(lightDifference(directSplit,tiledSplit),0,'each split-screen camera must restore its own light grid after its reflection');+ assert.deepEqual(errors,[]);+ report.checks.push({backend,ready,drawsOn,drawsOff,prepassDraws,reflectionPixels:changed(on,off,256),movingPixels:changed(on,moved,256),recovery,secondView,lossLogs,errors,+ tiledLights:{count:tiledCounters['render.planar.tiledLights'],pixelRgbSumTolerance:3,source:pixel(tiledLight,200,210),reflection:pixel(tiledLight,200,290),singleViewPixels:lightDifference(directLight,tiledLight),spotPixels:lightDifference(directSpot,tiledSpot),movedPixels:lightDifference(directMoved,tiledMoved),splitViewPixels:lightDifference(directSplit,tiledSplit)}});await page.close();}report.status = 'checks-passed';