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(render): a frame carries 112 lights, the lights past the sixteenth lighting their pixels through screen tiles
yhh1661b5928609
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 1b2d619f7..f8d22c1cf 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -30,7 +30,7 @@ env:test_hierarchy_links test_entity_activity test_transform_traversal test_ui_tree test_tween_activitytest_shader_device test_draw_params test_per_draw_blocks test_texture_fb test_buffer_devicetest_compressed_format test_batch_builder test_skeletal_batch_color test_boundary_span test_webgpu_device- test_clip_depth test_planar_reflection test_sort_key test_sprite_mask_range test_sprite_draw_mode test_shadow_atlas test_particle_shapes test_lod_selection test_view_shading test_mesh_edges test_hdr_format test_probe_store test_occlusion_view test_reflection_store+ test_clip_depth test_planar_reflection test_sort_key test_sprite_mask_range test_sprite_draw_mode test_shadow_atlas test_particle_shapes test_lod_selection test_view_shading test_mesh_edges test_hdr_format test_probe_store test_occlusion_view test_reflection_store test_tiled_lightstest_text_edit test_render_graph test_device_loss test_physics_interpolationtest_bitmap_font test_texture_cache test_material_shader_lifetime test_mesh_recovery test_aot_host test_aot_conformancetest_touch_streamdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex dd2ca3ba7..60e4cee97 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,6 +17,7 @@ published separately; it ships inside the editor.### Added- **Contact shadows and screen-space bounce light.** Contact Shadows and Screen Space GI effects add small sharp shadows at contacts and one bounce of colour between surfaces, and the weather softens the sun's shadows. `contactShadows` marches a short ray toward the scene's sun in the depth buffer; `ssgi` gathers eight rays a pixel over the G-buffer's normals at half size into a float target and averages the neighbours on the same surface before laying the light, times the receiver's colour, over the picture. The Weather component raises the sun's `sourceAngle` and lowers its `shadowStrength` as the sky clouds over.+- **Many lights.** A frame now carries up to 112 lights: sixteen are read for every pixel and the rest are tiled, so a street of lamps lights what each one reaches. The sun, the lights that cast a shadow and then the brightest go in the lighting loop as before; every other point and spot light without a shadow map is recorded per screen tile (16 x 12) and shaded only by the pixels it reaches, so the cost follows the lights near a pixel and not the lights in the scene. Tiled lights do not cast shadows, and the whole lighting block still fits the 16 KB a uniform block is guaranteed, so it runs on WebGL2 and WebGPU alike.- **Play on WebGPU.** Play runs the game on the graphics backend the project asks for, so a WebGPU project is played on WebGPU and its compute effects and Voxel GI are seen in the editor. Until now Play always ran on WebGL2 whatever the project asked for; it now follows `features.rendering.backend` the way a shipped build does, and falls back to WebGL2 on a machine with no WebGPU.- **Voxel GI.** Voxel GI adds diffuse bounce light from a world-space voxel cache the camera remembers, on WebGPU. The cache is a voxel grid around the camera that each frame takes in the lit picture (the radiance and facing of the surfaces it sees) and fades what it held; light is gathered by marching cosine-weighted rays through it, so a wall that has left the screen still tints the floor beside it and a moving light lights its surroundings, which Screen Space GI cannot do. It holds only what the camera has seen, at the voxel's size, with one diffuse bounce: it is not a trace of the scene's geometry, and not Lumen. A device with no compute stage goes without it.- **Compute effects.** A post-process effect can be a WGSL compute shader over the picture, run on WebGPU and left out on WebGL2, and Sharpen is the first. An effect registers with `compute` instead of `factory`; it is handed the picture so far, a storage texture to write, its parameters, the size and the scene's depth. Sharpen pushes each pixel away from its neighbours and holds it inside their range, so an edge steepens without a halo. A compute effect refines a picture that is already whole, so a device with no compute stage simply goes without it.diff --git a/desktop b/desktopindex 943eccf54..87edafec7 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 943eccf547c53565d9364f308980540f4afae93b+Subproject commit 87edafec7c5c2c46012c358f11a99f1829bd584cdiff --git a/docs/astro/src/content/docs/graphics/lighting.mdx b/docs/astro/src/content/docs/graphics/lighting.mdxindex ca4c8d748..b6fd0742c 100644--- a/docs/astro/src/content/docs/graphics/lighting.mdx+++ b/docs/astro/src/content/docs/graphics/lighting.mdx@@ -80,6 +80,24 @@ const addSun = defineSystem([Commands()], (cmds) => {.insert(Light, { type: LightType.Ambient, intensity: 0.25 });```+## Many lights++A frame carries **112 lights** at once: sixteen the lighting loop reads for every pixel, and up to 96 more that are **tiled**. A street at night with+a lamp every few metres, a corridor of neon, a room of candles — each is just a point or spot `Light`, and all of them light what they reach.++How it works, so that you can predict it: the sixteen the loop reads directly are the sun (directional lights), then anything that casts a+shadow, then the brightest. Every other point or spot light **without a shadow map** goes into the tiled set. The screen is divided into a 16 × 12 grid; for+each tile the engine records which lights' spheres (`radius`) can reach it, and a pixel shades only the lights recorded for its own tile. The cost+follows the lights near a pixel, not the lights in the scene — a hundred lamps cost what the handful in view cost.++What to keep in mind:++- **Tiled lights do not cast shadows.** A shadow-casting light that does not make the sixteen is turned away (the Light Status in the editor says so), since the loop is the only+ place a shadow map is read. Give the lights that matter shadows and let the many be the glow.+- **`radius` is the reach.** The tile masks are built from it; a light with a huge radius touches every tile and costs like it.+- Planar reflections are drawn with the sixteen only: their camera is not the one the tiles were made for.+- 2D lights ride the same set, so a 2D scene with fifty torches is lit too.+## Shaping the falloffA Point or Spot light fades from its own centre to nothing at `radius`, in a straightdiff --git a/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx b/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdxindex 905dbe924..0e48307a3 100644--- a/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx+++ b/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx@@ -73,6 +73,22 @@ const addSun = defineSystem([Commands()], (cmds) => {.insert(Light, { type: LightType.Ambient, intensity: 0.25 });```+## 大量光源++一帧可以同时携带 **112 盏光**:光照循环对每个像素都读取的 16 盏,以及最多 96 盏**分块(tiled)**光。夜晚每隔几米一盏路灯的街道、一条霓虹走廊、+一屋子的蜡烛——每一盏都只是一个点光或聚光 `Light`,它们都会照亮自己够得着的东西。++它怎么工作,便于你预判:循环直接读取的 16 盏依次是太阳(方向光),然后是投射阴影的光,再然后是最亮的。其余**没有阴影图**的点光和聚光进入分块集合。+屏幕被分成 16 × 12 的格子;引擎为每个格子记录哪些光的球(`radius`)够得着它,一个像素只对记录在自己格子里的光做着色。开销取决于像素附近的光,+而不是场景里的光——一百盏灯的代价就是视野里那几盏的代价。++需要记住的:++- **分块光不投射阴影。** 没挤进 16 盏的投影光会被拒绝(编辑器里的 Light Status 会说明),因为阴影图只在这个循环里读取。让重要的光有阴影,让大量的光做氛围。+- **`radius` 就是够得着的范围。** 分块掩码由它生成;半径巨大的光会碰到每个格子,开销也就像它那么大。+- 平面反射只用那 16 盏绘制:它的相机不是分块所对应的那个相机。+- 2D 光也走同一个集合,所以有五十支火把的 2D 场景同样被照亮。+## 让渲染器接受光照默认情况下,一个 `Sprite` 用**不受光**材质绘制,会忽略每一盏灯。让它受光最简单的方式是diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cppindex a529ac5c7..ae87c32e4 100644--- a/src/esengine/renderer/frame/RenderFrame.cpp+++ b/src/esengine/renderer/frame/RenderFrame.cpp@@ -1478,28 +1478,42 @@ void RenderFrame::collectLights(ecs::Registry& registry) {collected.push_back({gpu, castsMeshShadow, caster});}- light_cap_.limit = MAX_LIGHTS;+ light_cap_.limit = MAX_LIGHTS + MAX_TILED_LIGHTS;light_cap_.requested = static_cast<u32>(collected.size() + light_cap_.refused.size());+ // The lights past the loop's sixteen that can still be carried: point and spot lights with no shadow map, which a tile mask+ // can hand to the fragments they reach. Everything else turned away is refused as it always was.+ std::vector<CollectedLight> tiled;if (collected.size() > MAX_LIGHTS) {- std::partial_sort(collected.begin(), collected.begin() + MAX_LIGHTS, collected.end(),- [](const CollectedLight& a, const CollectedLight& b) {- return a.gpu.color.a > b.gpu.color.a;- });- // Recorded AFTER the sort and BEFORE the resize: this is the one moment- // the frame knows which lights it is about to stop carrying, and it used- // to spend that moment printing how many.+ // Which sixteen the loop reads: the sun, and what casts a shadow (the loop is the only place a shadow is read), first;+ // then the brightest. Sorted whole, since what is left over is read in this order too.+ const auto rank = [](const CollectedLight& l) {+ const bool directional = l.gpu.posDir.z > 0.5f && l.gpu.posDir.z < 1.5f;+ return directional ? 0 : (l.castsMeshShadow ? 1 : 2);+ };+ std::stable_sort(collected.begin(), collected.end(), [&rank](const CollectedLight& a, const CollectedLight& b) {+ const int ra = rank(a), rb = rank(b);+ if (ra != rb) return ra < rb;+ return a.gpu.color.a > b.gpu.color.a;+ });for (usize i = MAX_LIGHTS; i < collected.size(); ++i) {- const CollectedLight& dropped = collected[i];- light_cap_.refused.push_back({dropped.caster.light,- static_cast<u8>(dropped.gpu.posDir.z),- dropped.gpu.color.a, LightRefusal::Capacity});- ES_LOG_WARN("collectLights: light {} is not in this frame ({}); {} of {} kept, brightest first",- dropped.caster.light.raw, lightRefusalName(LightRefusal::Capacity),- MAX_LIGHTS, collected.size());+ CollectedLight& rest = collected[i];+ const bool positional = rest.gpu.posDir.z < 0.5f || rest.gpu.posDir.z > 1.5f;+ if (positional && !rest.castsMeshShadow && tiled.size() < MAX_TILED_LIGHTS) {+ tiled.push_back(rest);+ continue;+ }+ // Recorded AFTER the sort and BEFORE the resize: this is the one moment+ // the frame knows which lights it is about to stop carrying, and it used+ // to spend that moment printing how many.+ light_cap_.refused.push_back({rest.caster.light, static_cast<u8>(rest.gpu.posDir.z),+ rest.gpu.color.a, LightRefusal::Capacity});+ ES_LOG_WARN("collectLights: light {} is not in this frame ({}); {} kept of {}, brightest first",+ rest.caster.light.raw, lightRefusalName(LightRefusal::Capacity),+ MAX_LIGHTS + tiled.size(), collected.size());}collected.resize(MAX_LIGHTS);}- light_cap_.accepted = static_cast<u32>(collected.size());+ light_cap_.accepted = static_cast<u32>(collected.size() + tiled.size());for (u32 slot = 0; slot < collected.size(); ++slot) {if (collected[slot].castsMeshShadow) {ShadowCaster caster = collected[slot].caster;@@ -1508,6 +1522,10 @@ 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));+ }// Last, because which lights the mask can carry is a question about the array the// loop above just filled.diff --git a/src/esengine/renderer/frame/RenderFramePlanar.cpp b/src/esengine/renderer/frame/RenderFramePlanar.cppindex 2c5ae0526..02cb53a18 100644--- a/src/esengine/renderer/frame/RenderFramePlanar.cpp+++ b/src/esengine/renderer/frame/RenderFramePlanar.cpp@@ -167,9 +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();planar_list_.execute(device_, planar_pool_, context_.materials(),context_.getWhiteTextureId(), nullptr, context_.perDrawBlocks());+ context_.lights().suspendTiled(false);capture.valid = true;capture.lastTime = planar_elapsed_;capture.draws = planar_list_.mergedDrawCallCount();diff --git a/src/esengine/renderer/store/LightConstants.hpp b/src/esengine/renderer/store/LightConstants.hppindex 79af22863..6debe84d1 100644--- a/src/esengine/renderer/store/LightConstants.hpp+++ b/src/esengine/renderer/store/LightConstants.hpp@@ -13,6 +13,7 @@#pragma once#include "../../core/Types.hpp"+#include "./TiledLights.hpp"#include <glm/glm.hpp>@@ -194,13 +195,21 @@ struct LightConstants {/// rgb = what the BAKED indirect light (a lightmap, a probe volume) is multiplied by: a bake holds one/// moment's light, so a scene that passes through a day or a weather scales and tints it here (1 = as baked).glm::vec4 bakedTint{1.0f};+ /// The lights past the loop's sixteen (point and spot, no shadow map), read through the tile masks below; see TiledLights.hpp.+ GpuLight tiledLights[MAX_TILED_LIGHTS];+ /// Per screen tile, which of those lights can reach it: bit i of word i / 32.+ glm::uvec4 tileMask[TILE_COLUMNS * TILE_ROWS]{};+ /// x = how many tiled lights there are (0 = the loop does not run), y = tile columns, z = tile rows, w unused.+ glm::vec4 tileInfo{0.0f};};static_assert(sizeof(GpuLight) == 96, "GpuLight must be std140-tight (six vec4s)");+static_assert(sizeof(LightConstants) <= 16384, "the block has to fit the 16 KB every device guarantees a uniform block");static_assert(sizeof(LightConstants) == 16 + 96 * MAX_LIGHTS + 16+ 64 * MAX_SHADOW_TILES + 16 * MAX_SHADOW_TILES+ 16 + 16 * 9 + 16 + 16- + 16 + 32 * MAX_REFLECTION_PROBES + 16,+ + 16 + 32 * MAX_REFLECTION_PROBES + 16+ + 96 * MAX_TILED_LIGHTS + 16 * TILE_COLUMNS * TILE_ROWS + 16,"LightConstants must match the std140 GLSL block layout");} // namespace esenginediff --git a/src/esengine/renderer/store/LightStore.hpp b/src/esengine/renderer/store/LightStore.hppindex cfe3d9a89..33165a8dd 100644--- a/src/esengine/renderer/store/LightStore.hpp+++ b/src/esengine/renderer/store/LightStore.hpp@@ -40,6 +40,7 @@ public:void clear() {data_ = LightConstants{};count_ = 0;+ tiledCount_ = 0;hasEnvironment_ = false;dirty_ = true;}@@ -62,6 +63,29 @@ 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) {+ if (tiledCount_ >= MAX_TILED_LIGHTS) return false;+ data_.tiledLights[tiledCount_] = light;+ markLightTiles(viewProjection, position, radius, tiledCount_, reinterpret_cast<u32(*)[4]>(data_.tileMask));+ ++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;+ dirty_ = true;+ }++ u32 tiledCount() const { return tiledCount_; }+/// Hands over the shadow tiles a frame rendered: per tile a world -> clip matrix/// and the atlas rect it was drawn into (bias in w), plus the params whose x is/// the master switch. Zeroed when nothing cast, so no matrix outlives its map.@@ -172,6 +196,7 @@ public:private:LightConstants data_{};u32 count_ = 0;+ u32 tiledCount_ = 0;bool hasEnvironment_ = false;BufferHandle ubo_ = BufferHandle::Invalid;bool dirty_ = true;diff --git a/src/esengine/renderer/store/TiledLights.hpp b/src/esengine/renderer/store/TiledLights.hppnew file mode 100644index 000000000..94dbbd525--- /dev/null+++ b/src/esengine/renderer/store/TiledLights.hpp@@ -0,0 +1,77 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file TiledLights.hpp+ * @brief Which screen tiles a light can reach — the half of tiled forward lighting that is decided on the CPU.+ *+ * @details The lighting UBO holds sixteen lights a fragment loops over, which a street at night overruns on its own. The rest of+ * a frame's point and spot lights (up to MAX_TILED_LIGHTS) ride in the same block with a bitmask per screen tile: bit+ * i of tile t says light i can reach a pixel in that tile. A fragment finds its tile from where it lands on the+ * screen and shades only the lights whose bit is set, so the cost follows the lights near a pixel and not the lights+ * in the scene.+ *+ * The grid is in NORMALIZED DEVICE coordinates — x and y in [-1, 1], y up — which both backends and every camera share:+ * a fragment recovers them from the projection it was drawn through, so there is no viewport size, no framebuffer+ * origin and no sub-rect of a shared surface for the two sides to disagree about.+ */+#pragma once++#include "../../core/Types.hpp"++#include <glm/glm.hpp>++#include <algorithm>+#include <cmath>++namespace esengine {++/// Tiles across and down the picture. 16 x 12 is 192 tiles, each a mask of 128 bits (a vec4 of u32), which with the lights is what+/// fits a uniform block's 16 KB.+inline constexpr u32 TILE_COLUMNS = 16;+inline constexpr u32 TILE_ROWS = 12;++/// Lights a frame can carry through tiles, past the sixteen the loop reads directly. Three words of mask: the fourth is spare.+inline constexpr u32 MAX_TILED_LIGHTS = 96;++/// Sets bit @p index in every tile of @p masks that the sphere (@p center, @p radius), seen through @p viewProjection, can reach.+///+/// @details Conservative: the sphere is boxed, the box's eight corners projected, and the tiles the projected rectangle covers get the+/// bit. A corner at or behind the eye makes the projection meaningless, so a light that straddles the camera plane+/// marks every tile — wrongly lit tiles cost a loop iteration, wrongly unlit ones are a visible hole. A light wholly+/// off the screen marks none.+inline void markLightTiles(const glm::mat4& viewProjection, const glm::vec3& center, f32 radius, u32 index,+ u32 (*masks)[4]) {+ const u32 word = index >> 5;+ const u32 bit = 1u << (index & 31u);+ const auto markAll = [&]() {+ for (u32 t = 0; t < TILE_COLUMNS * TILE_ROWS; ++t) masks[t][word] |= bit;+ };+ f32 minX = 1e30f, minY = 1e30f, maxX = -1e30f, maxY = -1e30f;+ for (u32 corner = 0; corner < 8; ++corner) {+ const glm::vec3 p = center + glm::vec3((corner & 1u) ? radius : -radius, (corner & 2u) ? radius : -radius,+ (corner & 4u) ? radius : -radius);+ const glm::vec4 clip = viewProjection * glm::vec4(p, 1.0f);+ if (clip.w <= 1e-4f) {+ markAll();+ return;+ }+ const f32 x = clip.x / clip.w;+ const f32 y = clip.y / clip.w;+ minX = std::min(minX, x);+ maxX = std::max(maxX, x);+ minY = std::min(minY, y);+ maxY = std::max(maxY, y);+ }+ if (maxX < -1.0f || minX > 1.0f || maxY < -1.0f || minY > 1.0f) return;+ const auto tileOf = [](f32 ndc, u32 count) {+ const f32 t = std::floor((ndc * 0.5f + 0.5f) * static_cast<f32>(count));+ return static_cast<u32>(std::clamp(t, 0.0f, static_cast<f32>(count - 1)));+ };+ const u32 x0 = tileOf(minX, TILE_COLUMNS), x1 = tileOf(maxX, TILE_COLUMNS);+ const u32 y0 = tileOf(minY, TILE_ROWS), y1 = tileOf(maxY, TILE_ROWS);+ for (u32 y = y0; y <= y1; ++y) {+ for (u32 x = x0; x <= x1; ++x) masks[y * TILE_COLUMNS + x][word] |= bit;+ }+}++} // namespace esenginediff --git a/src/esengine/renderer/webgpu/WebGPUDevice.cpp b/src/esengine/renderer/webgpu/WebGPUDevice.cppindex e64880da9..99cce3119 100644--- a/src/esengine/renderer/webgpu/WebGPUDevice.cpp+++ b/src/esengine/renderer/webgpu/WebGPUDevice.cpp@@ -1940,10 +1940,10 @@ WGPUPipelineLayout WebGPUDevice::pipelineLayoutFor(u32 group0Mask, u32 group1Masvoid WebGPUDevice::ensureDummies() {if (!dummy_ubo_.buffer) {- // Sized past the largest engine block (LightConstants, 1184 bytes) so a+ // Sized past the largest engine block (LightConstants, just under 16 KB with the tiled lights) so a// declared-but-unbound block always satisfies draw-time size validation.- const std::vector<u8> zeros(2048, 0);- dummy_ubo_ = BufferRec{makeBuffer(GfxBufferUsage::Uniform, 2048, zeros.data()), 2048,+ const std::vector<u8> zeros(16384, 0);+ dummy_ubo_ = BufferRec{makeBuffer(GfxBufferUsage::Uniform, 16384, zeros.data()), 16384,GfxBufferUsage::Uniform};}if (!dummy_texture_.texture) {diff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cppindex 312f62652..7ebc4360d 100644--- a/src/esengine/resource/ShaderParser.cpp+++ b/src/esengine/resource/ShaderParser.cpp@@ -1138,6 +1138,9 @@ struct LightConstants {u_reflParams : vec4f,u_reflBox : array<vec4f, 30>,u_bakedTint : vec4f,+ tiledLights : array<Light, 96>,+ tileMask : array<vec4u, 192>,+ tileInfo : vec4f,};@group(0) @binding(2) var<uniform> lc : LightConstants;fn unpackDepth(c : vec3f) -> f32 {@@ -1200,6 +1203,9 @@ struct LightConstants {u_reflParams : vec4f,u_reflBox : array<vec4f, 30>,u_bakedTint : vec4f,+ tiledLights : array<Light, 96>,+ tileMask : array<vec4u, 192>,+ tileInfo : vec4f,};@group(0) @binding(2) var<uniform> lc : LightConstants;struct ProbeConstants { u_probeIrradiance : array<vec4f, 1000>, u_probeTail : vec4f };@@ -1629,10 +1635,47 @@ fn applyLightingPBR(albedo : vec3f, N : vec3f, worldPos : vec3f, V : vec3f, metavar lit = indirectIrradiance(N) * ao;var gloss = vec3f(0.0);for (var i = 0; i < 16; i++) {- let pd = lc.u_lights[i].posDir;- let col = lc.u_lights[i].color;- let sh = lc.u_lights[i].shadow;- let fo = lc.u_lights[i].falloff;+ let term = shadeLight(lc.u_lights[i].posDir, lc.u_lights[i].color, lc.u_lights[i].spot, lc.u_lights[i].shadow,+ lc.u_lights[i].shadowMap, lc.u_lights[i].falloff, N, V, worldPos, a, F0, NdotV, specular, roughness);+ lit += term.lit;+ gloss += term.gloss;+ }+ // The lights past the sixteen: this pixel's tile is found from where the fragment lands through the camera it was drawn by+ // (normalized device coordinates, the same on every backend), and only the lights whose bit is set in its mask are shaded.+ let tiledCount = i32(lc.tileInfo.x);+ if (tiledCount > 0) {+ let tileClip = frame.projection * vec4f(worldPos, 1.0);+ let tileNdc = tileClip.xy / max(tileClip.w, 1e-4);+ let tileCount = vec2i(i32(lc.tileInfo.y), i32(lc.tileInfo.z));+ let tile = clamp(vec2i(floor((tileNdc * 0.5 + 0.5) * vec2f(tileCount))), vec2i(0), tileCount - vec2i(1));+ let mask = lc.tileMask[tile.y * tileCount.x + tile.x];+ for (var w = 0; w < 3; w++) {+ var bits = mask.x;+ if (w == 1) { bits = mask.y; } else if (w == 2) { bits = mask.z; }+ if (bits == 0u) { continue; }+ for (var b = 0; b < 32; b++) {+ if ((bits & (1u << u32(b))) == 0u) { continue; }+ let k = w * 32 + b;+ if (k >= tiledCount) { break; }+ let term = shadeLight(lc.tiledLights[k].posDir, lc.tiledLights[k].color, lc.tiledLights[k].spot,+ lc.tiledLights[k].shadow, lc.tiledLights[k].shadowMap, lc.tiledLights[k].falloff,+ N, V, worldPos, a, F0, NdotV, specular, roughness);+ lit += term.lit;+ gloss += term.gloss;+ }+ }+ }+ let ab = envBRDFApprox(NdotV, roughness);+ gloss += envRadiance(reflect(-V, N), roughness, reflectionColumn(), worldPos) * (ao * specular)+ * (F0 * ab.x + vec3f(ab.y));+ return albedo * (1.0 - metallic) * lit + gloss;+}+struct LightTerm { lit : vec3f, gloss : vec3f };+fn shadeLight(pd : vec4f, col : vec4f, sp : vec4f, sh : vec4f, sm : vec4f, fo : vec4f, N : vec3f, V : vec3f,+ worldPos : vec3f, a : f32, F0 : vec3f, NdotV : f32, specular : f32, roughness : f32) -> LightTerm {+ var lit = vec3f(0.0);+ var gloss = vec3f(0.0);+ {var L : vec3f;var atten : f32;var aim = pd.xy;@@ -1650,7 +1693,6 @@ fn applyLightingPBR(albedo : vec3f, N : vec3f, worldPos : vec3f, V : vec3f, metacastShadow = sh.y > 0.0 && dot(toLight, toLight) > 0.5;aim = worldPos.xy + toLight * sh.y;} else {- let sp = lc.u_lights[i].spot;let toL = lightVector(pd, sh, worldPos);let dist = lightDistance(toL);atten = distanceFalloff(dist, max(pd.w, 0.0001), fo);@@ -1661,9 +1703,8 @@ fn applyLightingPBR(albedo : vec3f, N : vec3f, worldPos : vec3f, V : vec3f, metaatten *= shapeFactor2D(fo.w, worldPos.xy);}if (castShadow && col.a > 0.0 && atten > 0.0) {- atten *= mix(1.0, shadowFactor2D(lc.u_lights[i].shadowMap.w, worldPos.xy), fo.z);+ atten *= mix(1.0, shadowFactor2D(sm.w, worldPos.xy), fo.z);}- let sm = lc.u_lights[i].shadowMap;if (sm.y > 0.0 && atten > 0.0) {atten *= mix(1.0,shadowFactor3D(worldPos, N, L, vec2f(sh.x, sm.z), i32(sm.x), i32(sm.y)),@@ -1681,10 +1722,7 @@ fn applyLightingPBR(albedo : vec3f, N : vec3f, worldPos : vec3f, V : vec3f, meta* (brdf * 3.14159265 * specular);}}- let ab = envBRDFApprox(NdotV, roughness);- gloss += envRadiance(reflect(-V, N), roughness, reflectionColumn(), worldPos) * (ao * specular)- * (F0 * ab.x + vec3f(ab.y));- return albedo * (1.0 - metallic) * lit + gloss;+ return LightTerm(lit, gloss);}fn applyLighting2DAO(albedo : vec3f, N : vec3f, worldPos : vec2f, ao : f32) -> vec3f {let P = vec3f(worldPos, 0.0);@@ -2072,6 +2110,9 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p" highp vec4 u_reflParams;\n" // x = columns in the bound atlas (1 = sky only)" highp vec4 u_reflBox[30];\n" // [2i] = column i+1's world min, [2i+1] its max" highp vec4 u_bakedTint;\n" // what baked indirect light is multiplied by+ " Light u_tiledLights[96];\n"+ " highp uvec4 u_tileMask[192];\n"+ " highp vec4 u_tileInfo;\n""};\n"// One run of nine per INSTANCE, not one for the draw: a merged draw// holds objects standing in many places. The flag in w tells "no@@ -2538,6 +2579,11 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p" highp float ramp = clamp((reach - dist) / max(reach - fo.x, 1e-4), 0.0, 1.0);\n"" return pow(ramp, max(fo.y, 1e-3));\n""}\n"+ // The body of the per-light loop, a function so that the lights the tiles carry are shaded by the same code as the sixteen.+ "void shadeLight(in highp vec4 pd, in highp vec4 col, in highp vec4 sp, in highp vec4 sh, in highp vec4 sm,\n"+ " in highp vec4 fo, in highp vec3 N, in highp vec3 V, in highp vec3 worldPos,\n"+ " in highp float a, in highp vec3 F0, in highp float NdotV, in highp float specular,\n"+ " in highp float roughness, inout highp vec3 lit, inout highp vec3 gloss);\n"// The lighting model in its general form; a lit 2D surface is its zero// (metallic 0, roughness 1, specular 0 leaves albedo * NdotL, pixel for pixel// what this engine has always drawn), so there is one model and not two.@@ -2557,10 +2603,45 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p// A Light has no third coordinate, so distance stays in the plane and a// point light's height is its radius. Normal and view are the 3D part." for (int i = 0; i < 16; ++i) {\n"- " highp vec4 pd = u_lights[i].posDir;\n"- " highp vec4 col = u_lights[i].color;\n"- " highp vec4 sh = u_lights[i].shadow;\n" // x = penumbra softness, y = directional distance- " highp vec4 fo = u_lights[i].falloff;\n" // x = inner radius, y = exponent, z = shadow strength+ " shadeLight(u_lights[i].posDir, u_lights[i].color, u_lights[i].spot, u_lights[i].shadow,\n"+ " u_lights[i].shadowMap, u_lights[i].falloff, N, V, worldPos, a, F0, NdotV,\n"+ " specular, roughness, lit, gloss);\n"+ " }\n"+ // The lights past the sixteen: this pixel's tile is found from where the fragment lands through the camera it was drawn by+ // (normalized device coordinates, the same on every backend), and only the lights whose bit is set in its mask are shaded.+ " int tiledCount = int(u_tileInfo.x);\n"+ " if (tiledCount > 0) {\n"+ " highp vec4 tileClip = u_projection * vec4(worldPos, 1.0);\n"+ " highp vec2 tileNdc = tileClip.xy / max(tileClip.w, 1e-4);\n"+ " ivec2 tileCount = ivec2(int(u_tileInfo.y), int(u_tileInfo.z));\n"+ " ivec2 tile = clamp(ivec2(floor((tileNdc * 0.5 + 0.5) * vec2(tileCount))), ivec2(0), tileCount - ivec2(1));\n"+ " highp uvec4 mask = u_tileMask[tile.y * tileCount.x + tile.x];\n"+ " for (int w = 0; w < 3; ++w) {\n"+ " highp uint bits = w == 0 ? mask.x : (w == 1 ? mask.y : mask.z);\n"+ " if (bits == 0u) continue;\n"+ " for (int b = 0; b < 32; ++b) {\n"+ " if ((bits & (1u << uint(b))) == 0u) continue;\n"+ " int k = w * 32 + b;\n"+ " if (k >= tiledCount) break;\n"+ " shadeLight(u_tiledLights[k].posDir, u_tiledLights[k].color, u_tiledLights[k].spot,\n"+ " u_tiledLights[k].shadow, u_tiledLights[k].shadowMap, u_tiledLights[k].falloff,\n"+ " N, V, worldPos, a, F0, NdotV, specular, roughness, lit, gloss);\n"+ " }\n"+ " }\n"+ " }\n"+ // The environment, which for this engine is the ambient term: the same+ // radiance from every direction. A metal has no diffuse, so without a+ // reflection of it a metal is black wherever no light happens to point.+ " highp vec2 ab = envBRDFApprox(NdotV, roughness);\n"+ " gloss += envRadiance(reflect(-V, N), roughness, reflectionColumn(), worldPos)\n"+ " * (ao * specular)\n"+ " * (F0 * ab.x + ab.y);\n"+ " return albedo * (1.0 - metallic) * lit + gloss;\n"+ "}\n"+ "void shadeLight(in highp vec4 pd, in highp vec4 col, in highp vec4 sp, in highp vec4 sh, in highp vec4 sm,\n"+ " in highp vec4 fo, in highp vec3 N, in highp vec3 V, in highp vec3 worldPos,\n"+ " in highp float a, in highp vec3 F0, in highp float NdotV, in highp float specular,\n"+ " in highp float roughness, inout highp vec3 lit, inout highp vec3 gloss) {\n"" highp vec3 L;\n"" highp float atten;\n"" highp vec2 target = pd.xy;\n" // shadow-ray aim point (light position by default)@@ -2580,7 +2661,6 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p" castShadow = sh.y > 0.0 && dot(toLight, toLight) > 0.5;\n"" target = worldPos.xy + toLight * sh.y;\n"" } else {\n"- " highp vec4 sp = u_lights[i].spot;\n"" highp vec3 toL = lightVector(pd, sh, worldPos);\n"" highp float dist = lightDistance(toL);\n"" atten = distanceFalloff(dist, max(pd.w, 0.0001), fo);\n"@@ -2593,12 +2673,11 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p" atten *= shapeFactor2D(fo.w, worldPos.xy);\n"" }\n"" if (castShadow && col.a > 0.0 && atten > 0.0) {\n"- " atten *= mix(1.0, shadowFactor2D(u_lights[i].shadowMap.w, worldPos.xy), fo.z);\n"+ " atten *= mix(1.0, shadowFactor2D(sm.w, worldPos.xy), fo.z);\n"" }\n"// The tiles this light rendered into, which are its own: a fragment// tested against every map in the atlas would be darkened by geometry// seen from somewhere no light reaching it is standing.- " highp vec4 sm = u_lights[i].shadowMap;\n"" if (sm.y > 0.0 && atten > 0.0) {\n"" atten *= mix(1.0, shadowFactor3D(worldPos, N, L, vec2(sh.x, sm.z),\n"" int(sm.x), int(sm.y)), fo.z);\n"@@ -2617,15 +2696,6 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p" gloss += radiance * fresnelSchlick(max(dot(V, H), 0.0), F0)\n"" * (brdf * 3.14159265 * specular);\n"" }\n"- " }\n"- // The environment, which for this engine is the ambient term: the same- // radiance from every direction. A metal has no diffuse, so without a- // reflection of it a metal is black wherever no light happens to point.- " highp vec2 ab = envBRDFApprox(NdotV, roughness);\n"- " gloss += envRadiance(reflect(-V, N), roughness, reflectionColumn(), worldPos)\n"- " * (ao * specular)\n"- " * (F0 * ab.x + ab.y);\n"- " return albedo * (1.0 - metallic) * lit + gloss;\n""}\n""highp vec3 applyLighting2DAO(highp vec3 albedo, highp vec3 N, highp vec2 worldPos,\n"" highp float ao) {\n"@@ -2674,6 +2744,9 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p" highp vec4 u_reflParams;\n"" highp vec4 u_reflBox[30];\n"" highp vec4 u_bakedTint;\n"+ " Light u_tiledLights[96];\n"+ " highp uvec4 u_tileMask[192];\n"+ " highp vec4 u_tileInfo;\n""};\n""uniform highp sampler2D u_shadowMap;\n""highp float unpackDepth(in highp vec3 c) {\n"diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txtindex cbf1c5277..1e360dbb1 100644--- a/tests/CMakeLists.txt+++ b/tests/CMakeLists.txt@@ -373,6 +373,14 @@ target_include_directories(test_probe_store PRIVATE)add_test(NAME test_probe_store COMMAND test_probe_store)+# Which screen tiles a light's sphere can reach (tiled forward lighting's CPU half). Header-only, so it runs without a device.+add_executable(test_tiled_lights renderer/test_tiled_lights.cpp)+target_include_directories(test_tiled_lights PRIVATE+ ${CMAKE_SOURCE_DIR}/src+ ${CMAKE_SOURCE_DIR}/third_party/glm+)+add_test(NAME test_tiled_lights COMMAND test_tiled_lights)+# Which baked column a point reflects. Header-only, so it runs without a device —# the pixel gate says a surface came out the wrong colour, this says whether the# lookup took the wrong box or let two bakes into one frame.diff --git a/tests/renderer/test_tiled_lights.cpp b/tests/renderer/test_tiled_lights.cppnew file mode 100644index 000000000..376826bba--- /dev/null+++ b/tests/renderer/test_tiled_lights.cpp@@ -0,0 +1,152 @@+// Native CTest harness for the CPU half of tiled forward lighting: which screen tiles a light's sphere can reach.+//+// What a wrong answer costs is invisible in a passing frame and plain in a failing one — a light that misses a tile it reaches is a+// hard-edged hole in the lighting, and one that marks every tile is a frame that pays for lights nobody sees. So the numbers+// here are pinned: the tile a light sits in, how many a big one covers, that one behind the eye marks them all, that one off the+// screen marks none, and that the bit lands in the word it should.++#include "esengine/renderer/store/LightStore.hpp"+#include "esengine/renderer/store/TiledLights.hpp"++#include <glm/gtc/matrix_transform.hpp>++#include <cstdio>+#include <cstring>++using namespace esengine;++static int g_failures = 0;+#define CHECK(cond, msg) \+ do { \+ if (!(cond)) { std::printf("FAIL: %s\n", msg); ++g_failures; } \+ else { std::printf("ok: %s\n", msg); } \+ } while (0)++namespace {++constexpr u32 kTiles = TILE_COLUMNS * TILE_ROWS;++u32 tilesWithBit(u32 (*masks)[4], u32 index) {+ u32 n = 0;+ for (u32 t = 0; t < kTiles; ++t) {+ if (masks[t][index >> 5] & (1u << (index & 31u))) ++n;+ }+ return n;+}++bool hasBit(u32 (*masks)[4], u32 tile, u32 index) { return (masks[tile][index >> 5] & (1u << (index & 31u))) != 0; }++/// A camera at the origin looking down -Z, 60 degrees, square picture.+glm::mat4 camera() {+ return glm::perspective(glm::radians(60.0f), 1.0f, 0.1f, 1000.0f);+}++} // namespace++int main() {+ static u32 masks[kTiles][4];+ const glm::mat4 vp = camera();++ // --- a small light straight ahead lights the tile at the centre, and only the tiles around it+ {+ std::memset(masks, 0, sizeof(masks));+ markLightTiles(vp, glm::vec3(0.0f, 0.0f, -50.0f), 1.0f, 0, masks);+ const u32 centreX = TILE_COLUMNS / 2, centreY = TILE_ROWS / 2;+ CHECK(hasBit(masks, centreY * TILE_COLUMNS + centreX, 0) || hasBit(masks, (centreY - 1) * TILE_COLUMNS + centreX - 1, 0),+ "a light straight ahead marks a tile at the middle of the picture");+ CHECK(tilesWithBit(masks, 0) <= 4, "and, being small and far, no more than four tiles");+ CHECK(!hasBit(masks, 0, 0) && !hasBit(masks, kTiles - 1, 0), "none of the corners");+ }++ // --- a light's bit lands in its own word+ {+ std::memset(masks, 0, sizeof(masks));+ markLightTiles(vp, glm::vec3(0.0f, 0.0f, -50.0f), 1.0f, 70, masks);+ bool wordOk = true;+ for (u32 t = 0; t < kTiles; ++t) {+ if (masks[t][0] != 0 || masks[t][1] != 0 || masks[t][3] != 0) wordOk = false;+ }+ CHECK(wordOk && tilesWithBit(masks, 70) > 0, "light 70 sets bit 6 of word 2 and nothing in the other words");+ }++ // --- a big light covers a lot of the picture, and a bigger one all of it+ {+ std::memset(masks, 0, sizeof(masks));+ markLightTiles(vp, glm::vec3(0.0f, 0.0f, -30.0f), 9.0f, 0, masks);+ const u32 wide = tilesWithBit(masks, 0);+ CHECK(wide > kTiles / 4 && wide < kTiles, "a light that spans much of the picture marks much of it, not all");+ std::memset(masks, 0, sizeof(masks));+ markLightTiles(vp, glm::vec3(0.0f, 0.0f, -20.0f), 200.0f, 0, masks);+ CHECK(tilesWithBit(masks, 0) == kTiles, "a light that covers the whole picture marks every tile");+ }++ // --- off the screen: none; behind or around the eye: all+ {+ std::memset(masks, 0, sizeof(masks));+ markLightTiles(vp, glm::vec3(500.0f, 0.0f, -50.0f), 1.0f, 0, masks);+ CHECK(tilesWithBit(masks, 0) == 0, "a light far to the side of the view marks no tile");+ std::memset(masks, 0, sizeof(masks));+ markLightTiles(vp, glm::vec3(0.0f, 0.0f, 20.0f), 1.0f, 0, masks);+ CHECK(tilesWithBit(masks, 0) == kTiles, "a light behind the camera marks every tile, since where it lands is not known");+ std::memset(masks, 0, sizeof(masks));+ markLightTiles(vp, glm::vec3(0.0f, 0.0f, 0.0f), 5.0f, 0, masks);+ CHECK(tilesWithBit(masks, 0) == kTiles, "and so does one that straddles the camera plane");+ }++ // --- the grid is in normalized device coordinates: the bottom-left of the picture is tile 0, y up+ {+ std::memset(masks, 0, sizeof(masks));+ // Down and to the left of the centre.+ markLightTiles(vp, glm::vec3(-20.0f, -20.0f, -50.0f), 1.0f, 0, masks);+ bool lowLeft = false;+ for (u32 y = 0; y < TILE_ROWS / 2; ++y) {+ for (u32 x = 0; x < TILE_COLUMNS / 2; ++x) lowLeft |= hasBit(masks, y * TILE_COLUMNS + x, 0);+ }+ CHECK(lowLeft && tilesWithBit(masks, 0) > 0, "a light below and left of the centre marks a tile in the first rows and columns");+ bool upper = false;+ for (u32 y = TILE_ROWS / 2; y < TILE_ROWS; ++y) {+ for (u32 x = 0; x < TILE_COLUMNS; ++x) upper |= hasBit(masks, y * TILE_COLUMNS + x, 0);+ }+ CHECK(!upper, "and none in the upper half: rows count up from the bottom");+ }++ // --- an orthographic camera (every 2D game) maps the same way+ {+ std::memset(masks, 0, sizeof(masks));+ const glm::mat4 ortho = glm::ortho(-100.0f, 100.0f, -100.0f, 100.0f, -10.0f, 10.0f);+ markLightTiles(ortho, glm::vec3(0.0f, 0.0f, 0.0f), 5.0f, 3, masks);+ const u32 n = tilesWithBit(masks, 3);+ CHECK(n >= 1 && n <= 4, "an orthographic light at the centre marks the tiles at the centre");+ std::memset(masks, 0, sizeof(masks));+ markLightTiles(ortho, glm::vec3(0.0f, 0.0f, 0.0f), 500.0f, 3, masks);+ 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+ {+ LightStore store;+ store.clear();+ GpuLight light;+ light.posDir = glm::vec4(0.0f, 0.0f, 0.0f, 10.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; }+ }+ 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.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.clear();+ CHECK(store.tiledCount() == 0 && store.data().tileInfo.x == 0.0f, "a new frame starts with none");+ }++ CHECK(sizeof(LightConstants) <= 16384, "the whole block fits the 16 KB a uniform block is guaranteed");++ std::printf(g_failures == 0 ? "\nALL PASS\n" : "\n%d FAILURE(S)\n", g_failures);+ return g_failures == 0 ? 0 : 1;+}diff --git a/tools/check-shader-blocks.mjs b/tools/check-shader-blocks.mjsindex 7bb3b39a6..4869c57c6 100644--- a/tools/check-shader-blocks.mjs+++ b/tools/check-shader-blocks.mjs@@ -100,6 +100,7 @@ const ALIASES = {const SIGNATURE_GAPS = {sampleNormal: 'WGSL takes the texture and its sampler apart; GLSL has one combined type',sampleNormalGrad: 'WGSL takes the texture and its sampler apart; GLSL has one combined type',+ shadeLight: 'WGSL returns the light and gloss it adds (a struct); GLSL accumulates them in two inout arguments',};/** A field name as the comparison sees it: the `u_` a shader adds is not part of it. */@@ -146,7 +147,8 @@ function cppBlock(name, file) {/** `MAX_LIGHTS` and friends, so a C++ array length compares as a number. */function constants() {const out = new Map();- for (const file of new Set(Object.values(BLOCKS))) {+ // The tile grid's size is TiledLights.hpp's, which the lighting block's array bounds are written in.+ for (const file of new Set([...Object.values(BLOCKS), 'src/esengine/renderer/store/TiledLights.hpp'])) {const source = readFileSync(path.join(ROOT, file), 'utf8');for (const [, k, v] of source.matchAll(/constexpr\s+\w+\s+(\w+)\s*=\s*(\d+)/g)) {out.set(k, v);@@ -218,7 +220,7 @@ function helpers(pattern) {return out;}-const glslFns = helpers(/^\s*(?:highp\s+)?(?:vec[234]|float|mat[234])\s+(\w+)\s*\(([^)]*)\)\s*\{/gm);+const glslFns = helpers(/^\s*(?:highp\s+)?(?:void|vec[234]|float|mat[234])\s+(\w+)\s*\(([^)]*)\)\s*\{/gm);const wgslFns = helpers(/\bfn\s+(\w+)\s*\(([^)]*)\)\s*->/g);const shape = (counts) => counts.length === 1 ? `${counts[0]} argument(s)`diff --git a/tools/lib/runtimeDecisions.mjs b/tools/lib/runtimeDecisions.mjsindex 9338d079e..65ea8552d 100644--- a/tools/lib/runtimeDecisions.mjs+++ b/tools/lib/runtimeDecisions.mjs@@ -75,9 +75,9 @@ export const DECISIONS = [},{id: 'light.cap',- what: 'Which lights survive MAX_LIGHTS, and that the rest were dropped by brightness.',+ what: 'Which lights the loop reads (the sun, the shadow casters, then the brightest), which ride in the screen tiles, and which were turned away.',kind: 'contended-resource',- owner: { path: 'src/esengine/renderer/frame/RenderFrame.cpp', probe: /std::partial_sort\(collected\.begin/ },+ owner: { path: 'src/esengine/renderer/frame/RenderFrame.cpp', probe: /std::stable_sort\(collected\.begin/ },runtime: { has: true, cite: { path: 'src/esengine/renderer/store/LightPlan.hpp', probe: /struct LightCapReport/ } },editor: { has: true, cite: { path: 'desktop/src/panels/inspector/componentDecorators.tsx', probe: /EditorControlSurface\.lightStatus\(/ } },agent: { has: true, cite: { path: 'desktop/shared/toolCatalog.mjs', probe: /'get_light_status'/ } },diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex d67dd0bf2..4b0e6d8e0 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -2493,6 +2493,8 @@ export const NOTED = {{"note":"Skinned meshes are followed by their bones, from the palette they were last drawn with."},"feat(render): fog follows the scene's sun and can walk the air against its shadow map":{"note":"Height Fog and Light Shafts follow the scene's own sun, and Height Fog can carry the sun's shadows as volumetric light."},+ "feat(render): a frame carries 112 lights, the lights past the sixteenth lighting their pixels through screen tiles":+ {"note":"A frame now carries up to 112 lights: sixteen are read for every pixel and the rest are tiled, so a street of lamps lights what each one reaches."},"feat(editor): Play runs on the graphics backend the project asks for":{"note":"Play runs the game on the graphics backend the project asks for, so a WebGPU project is played on WebGPU and its compute effects and Voxel GI are seen in the editor."},"feat(render): Voxel GI lights from a world-space cache of what the camera has seen, run as compute passes":