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(probes): a captured probe volume drives reflections too
yhh585bde98bfe1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1feab2275..1aa82b449 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -25,6 +25,7 @@ published separately; it ships inside the editor.- **The sky lights the scene.** Sky Atmosphere's **Light the Scene** makes the sky the scene's environment: every Ambient light that names no environment of its own lights with it, its diffuse light from the dome and the clouds and its reflection on metal and wet ground, scaled by the light's colour and intensity as an imported one is. The sky is worked out again as it changes (the sun moving, a weather coming in, clouds drifting), at most once a second; with clouds that takes about 20 ms on a desktop. The sun's disc is left out, since the directional light the sky follows is its direct light. Below the horizon it is the ground, lit by the sky's sun and dome and giving back **Ground Albedo** of it (0.2 by default, between asphalt and grass; Unreal's atmosphere uses 0.4), so a wall in shadow takes the sunlit ground's bounce as well as the sky's: under a high clear sun that doubles its fill, under a low hazy one it adds little. Off by default, so a scene already lit by hand looks as it did.- **Rooms stay dark under a sky that changes (sky occlusion).** With **Sky occlusion** on in the Lighting settings (`BakedLighting.skyOcclusion`), a probe bake keeps how much of the sky each probe sees instead of the sky itself: the probes hold the lights and their bounces, and the sky the frame has now (a live Sky Atmosphere, a weather, an environment) is added through what each probe sees of it, to the diffuse light and to the sky's reflection. A ball inside a roofed room measured 119 where the baked sky gave it 150, and a ball outside kept its light. A `.esprobes` baked this way carries `skyVisibility`; one without it lights as before. Probes are read per object, as Unity's light probes are: one large mesh spanning indoors and out takes one value.+- **A captured probe volume drives reflections too.** What a shiny surface inside a capturing `LightProbeVolume` reflects is the capture, box-projected, rather than the outdoor sky: the SDK prefilters each capture into a column of one reflection atlas beside the sky and the frame uses it wherever no baked `ReflectionProbe` is. A mesh now picks its reflection box by its world bounds (its centre, else the smallest box it overlaps), as probes do, so an imported level's walls whose origin sits outside the room still reflect it. A capture face now counts as done only once it is drawn. probe-capture-reflection checks a chrome ball shows the green wall on its right and the magenta one on its left, on both backends.- **A probe volume can be filled at run time.** `LightProbeVolume.capture` draws the scene from the box's centre all round (one small face a frame, no post-processing), reads it back and lights everything inside with it in place of a bake — the walls as the lamps light them now and the sky through the openings, which a bake cannot see on meshes without lightmap UVs. `captureInterval` recaptures (each pass a bounce). Unreal's real-time Sky Light / Reflection Capture; probe-capture checks a white ball between a red wall, a blue wall and a green ceiling takes each colour on the side that faces it, on both backends.- **Lamps can fall off as real ones do.** A Point or Spot light's **Inverse Square** falls it off as 1/distance² in metres (the project's units per metre), with `intensity` the light one metre away and `radius` only where it is let go, eased out by glTF's and three.js's window — Unreal's Use Inverse Squared Falloff. A lamp pools under itself instead of washing a room evenly; point-inverse-square checks 0.5, 0.177 and 0.045 under, 1 m and 2 m from a lamp. glTF punctual lights import this way (candela over π, range scaled with the model).- **A sky of your own lights the scene.** `defineSkyEffect({ type, label, glsl, wgsl, ... })` turns one function, the sky's radiance along a direction, into an effect a PostProcessVolume carries: drawn behind the scene and, with **Light the Scene** on, read back from the GPU as a small panorama about once a second and made the scene's environment, diffuse light and reflections, as Sky Atmosphere's is. A stylised sky lights the world with the light it shows, as an Unreal sky material does under a real-time Sky Light; the custom-sky gate checks that a ball under a blue-above, red-below sky is blue on top and red underneath on both backends. Effect textures can tile (`wrap: 'repeat'`).diff --git a/docs/astro/src/content/docs/graphics/lighting.mdx b/docs/astro/src/content/docs/graphics/lighting.mdxindex 16d87ce6e..fb7baf47d 100644--- a/docs/astro/src/content/docs/graphics/lighting.mdx+++ b/docs/astro/src/content/docs/graphics/lighting.mdx@@ -551,6 +551,11 @@ entity.insert(LightProbeVolume, { halfExtents: { x: 22, y: 7, z: 11 }, capture:- **`captureInterval`** recaptures every so many seconds (0 = once). Each capture sees the room lit by the last one, so afew are a few bounces.- The box is one point of light: it is right for a room, not for a long hall whose ends differ — use several boxes.+- What a shiny surface inside the box **reflects** is the capture too, projected onto the box's walls: a chrome tap in+ the shed shows the shed, not the sky outside. A scene with baked `ReflectionProbe`s keeps those; the frame binds one+ reflection atlas.+- Keep the box's centre clear: the capture is taken from there, and an object around that point (a mirror ball at the+ centre) is all it sees.### What a shiny surface reflects indoorsdiff --git a/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx b/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdxindex 87cd5e544..85e8fba47 100644--- a/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx+++ b/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx@@ -478,6 +478,9 @@ entity.insert(LightProbeVolume, { halfExtents: { x: 22, y: 7, z: 11 }, capture:- 每帧只画一个面,而且很小(32 像素),一次捕获相当于分摊到 6 帧里的 6 次小场景绘制。- **`captureInterval`** 每隔多少秒重拍一次(0 = 只拍一次)。每次拍到的房间都包含上一次的补光,所以拍几次就是几次反弹。- 一个盒子只有一个光照点:适合一个房间,不适合两头差别很大的长厅——那就用几个盒子。+- 盒子里光滑表面**反射**的也是这次捕获,并投影到盒子的墙上:棚里的铬水龙头映出的是棚子,而不是外面的天空。+ 场景里有烘焙的 `ReflectionProbe` 时仍用烘焙的那些;一帧只绑定一张反射图集。+- 盒子中心要空着:捕获从那里拍,包住这一点的物体(比如放在中心的镜面球)就是它能看到的全部。### 室内的镜面反射的是什么diff --git a/fixtures/scenes/chrome_m0.esmaterial b/fixtures/scenes/chrome_m0.esmaterialnew file mode 100644index 000000000..7d9185b86--- /dev/null+++ b/fixtures/scenes/chrome_m0.esmaterial@@ -0,0 +1,13 @@+{+ "version": "1.0",+ "type": "material",+ "shader": "builtin:model",+ "blendMode": 0,+ "depthTest": true,+ "depthWrite": true,+ "cull": 0,+ "properties": {+ "u_metallic": 1,+ "u_roughness": 0.05+ }+}diff --git a/fixtures/scenes/probe-capture-reflection.esscene b/fixtures/scenes/probe-capture-reflection.esscenenew file mode 100644index 000000000..7431c907e--- /dev/null+++ b/fixtures/scenes/probe-capture-reflection.esscene@@ -0,0 +1,257 @@+{+ "version": 4,+ "name": "ProbeCaptureReflection",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 330+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "fov": 50,+ "nearPlane": 1,+ "farPlane": 5000,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Ball",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 1.5,+ "y": 1.5,+ "z": 1.5+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:sphere",+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "enabled": true,+ "material": "/scenes/chrome_m0.esmaterial"+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "GreenRight",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 300,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 0.1,+ "y": 6,+ "z": 6+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 0,+ "g": 1,+ "b": 0,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": false,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "MagentaLeft",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -300,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 0.1,+ "y": 6,+ "z": 6+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "color": {+ "r": 1,+ "g": 0,+ "b": 1,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": false,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 5,+ "name": "Capture",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 160+ }+ }+ },+ {+ "type": "LightProbeVolume",+ "data": {+ "halfExtents": {+ "x": 300,+ "y": 300,+ "z": 300+ },+ "capture": true,+ "captureInterval": 0,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 6,+ "name": "Post",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "verifySky",+ "enabled": true,+ "uniforms": {+ "u_lightScene": 1+ }+ }+ ]+ }+ }+ ]+ },+ {+ "id": 8,+ "name": "Ambient",+ "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+ }+ }+ ]+ }+ ]+}diff --git a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts b/sdk/src/ecs/bridge/nativeEngineApi.generated.tsindex 9fd9fb091..3dbdf5f00 100644--- a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts+++ b/sdk/src/ecs/bridge/nativeEngineApi.generated.ts@@ -235,6 +235,7 @@ export interface NativeEngineApi {renderer_setOrigin?(x: number, y: number, z: number): void;renderer_setPlanarReflectionQuality?(scale: number, maxSize: number, updatesPerSecond: number): void;renderer_setProbeVolumeOverride?(entity: number, volumeHandle: number): void;+ renderer_setProbeVolumeReflection?(entity: number, environmentHandle: number, slot: number): void;renderer_setQualityBudgets?(atlasSize: number, cellSize: number, cascades: number, particleLimit: number): void;renderer_setShadow2DSoftSamples?(samples: number): void;renderer_setShadowDistance?(distance: number): void;@@ -588,6 +589,7 @@ export function createNativeEngineApi(bind('renderer_setOrigin', 'es_renderer_setOrigin', false);bind('renderer_setPlanarReflectionQuality', 'es_renderer_setPlanarReflectionQuality', false);bind('renderer_setProbeVolumeOverride', 'es_renderer_setProbeVolumeOverride', false);+ bind('renderer_setProbeVolumeReflection', 'es_renderer_setProbeVolumeReflection', false);bind('renderer_setQualityBudgets', 'es_renderer_setQualityBudgets', false);bind('renderer_setShadow2DSoftSamples', 'es_renderer_setShadow2DSoftSamples', false);bind('renderer_setShadowDistance', 'es_renderer_setShadowDistance', false);diff --git a/sdk/src/postprocess/probeCapture.ts b/sdk/src/postprocess/probeCapture.tsindex 10ac4c562..6c68c5a23 100644--- a/sdk/src/postprocess/probeCapture.ts+++ b/sdk/src/postprocess/probeCapture.ts@@ -17,7 +17,10 @@ import { Transform, LightProbeVolume, type TransformData, type LightProbeVolumeDimport type { Entity } from '../types';import type { ESEngineModule } from '../wasm';import { withScratch } from '../wasm/wasmScratch';-import { projectIrradianceSH, type Panorama } from '../lightmap/environmentAtlas';+import { projectIrradianceSH, prefilterOctahedral, type Panorama } from '../lightmap/environmentAtlas';+import { createTextureFromPixels } from '../runtime/runtimeAssets';+import { getResourceManager } from '../wasm/resourceManager';+import { TextureContent } from '../wasm';import { panoramaDirection, panoramaUV } from '../lightmap/panorama';/** Pixels a face is across: the light a room sends is smooth, and six of these are drawn one a frame. */@@ -84,14 +87,75 @@ interface CaptureCore {renderer_pollProbeCapture?(): number;renderer_takeProbeCapture?(dst: number, bytes: number): boolean;renderer_setProbeVolumeOverride?(entity: number, volumeHandle: number): void;+ renderer_setProbeVolumeReflection?(entity: number, environmentHandle: number, slot: number): void;+ environment_create?(shPtr: number, specularHandle: number, faceSize: number, mipCount: number, maxRange: number, columns: number): number;+ environment_release?(environmentHandle: number): void;probe_volume_create?(resX: number, resY: number, resZ: number, shPtr: number): number;probe_volume_release?(handle: number): void;}/** Each capturing volume's grid and when it was last filled, and the one capture in flight. */interface CaptureState {- grids: Map<Entity, { handle: number; at: number }>;+ grids: Map<Entity, { handle: number; at: number; panorama: Panorama }>;pending: Entity | null;+ /** The reflection atlas the captures make, and the environment the frame reads it through. */+ reflection: { environment: number; texture: number } | null;+ /** The sky panorama that atlas's column 0 was made from: a new sky (the one first made after the captures, a changing+ * weather) remakes it. */+ sky: Panorama | null;+}++/** The reflections' atlas: the same size as the sky's, so a surface leaving a room sees no change of sharpness. */+const REFLECTION_FACE = 32;+const REFLECTION_MIPS = 3;+const REFLECTION_RANGE = 8;++/**+ * One atlas, column 0 the sky and a column for each capture in order, prefiltered as an environment's reflection is: what+ * a surface inside a captured box reflects is the room around it rather than the sky outside.+ */+export function reflectionAtlas(sky: Panorama, captures: readonly Panorama[]): { width: number; height: number; rgba: Uint8Array; columns: number } {+ const columns = 1 + captures.length;+ const pyramids = [sky, ...captures].map((p) => prefilterOctahedral(p, REFLECTION_FACE, REFLECTION_MIPS, REFLECTION_RANGE));+ const colWidth = pyramids[0]!.width, height = pyramids[0]!.height;+ const rgba = new Uint8Array(colWidth * columns * height * 4);+ pyramids.forEach((pyramid, column) => {+ for (let y = 0; y < height; y++) {+ rgba.set(pyramid.rgba.subarray(y * colWidth * 4, (y + 1) * colWidth * 4), (y * colWidth * columns + column * colWidth) * 4);+ }+ });+ return { width: colWidth * columns, height, rgba, columns };+}++/** Rebuilds the reflection atlas from every capture held, and points each volume at its column; lets the last one go. */+function rebuildReflections(core: CaptureCore, module: ESEngineModule | null, state: CaptureState, sky: Panorama | null): void {+ const entities = [...state.grids.keys()];+ state.sky = sky;+ const drop = state.reflection;+ state.reflection = null;+ if (sky && entities.length && core.environment_create && core.renderer_setProbeVolumeReflection) {+ const atlas = reflectionAtlas(sky, entities.map((e) => state.grids.get(e)!.panorama));+ const texture = createTextureFromPixels(module, { width: atlas.width, height: atlas.height, pixels: atlas.rgba },+ TextureContent.Retained, false, { filterMode: 'linear', wrapMode: 'clamp', srgb: false });+ if (texture) {+ const environment = withScratch(core as never, (alloc: (n: number) => number) => {+ const shPtr = alloc(27 * 4);+ core.HEAPF32.set(projectIrradianceSH(sky), shPtr >> 2);+ return core.environment_create!(shPtr, texture, REFLECTION_FACE, REFLECTION_MIPS, REFLECTION_RANGE, atlas.columns);+ });+ if (environment) {+ state.reflection = { environment, texture };+ entities.forEach((e, i) => core.renderer_setProbeVolumeReflection!(e as unknown as number, environment, i + 1));+ } else {+ getResourceManager()?.releaseTexture(texture);+ }+ }+ }+ if (!state.reflection) for (const e of entities) core.renderer_setProbeVolumeReflection?.(e as unknown as number, 0, 0);+ if (drop) {+ core.environment_release?.(drop.environment);+ getResourceManager()?.releaseTexture(drop.texture);+ }}/**@@ -99,7 +163,7 @@ interface CaptureState {* `captureInterval` seconds (or once). `sky` answers the panorama the scene's sky was last made from, for what shows of it.*/export function probeCaptureSystem(module: () => ESEngineModule | null, sky: () => Panorama | null) {- const state: CaptureState = { grids: new Map(), pending: null };+ const state: CaptureState = { grids: new Map(), pending: null, reflection: null, sky: null };return defineSystem([Query(LightProbeVolume, Transform)],(volumes: Iterable<[Entity, LightProbeVolumeData, TransformData]>) => {@@ -119,13 +183,17 @@ export function probeCaptureSystem(module: () => ESEngineModule | null, sky: ()const p = transform.worldPosition ?? transform.position;if (!due || since > due.since) due = { entity, at: [p.x, p.y, p.z], since };}- // A volume that stopped capturing goes back to its bake.+ // A volume that stopped capturing goes back to its bake, and leaves the reflections.+ let dropped = false;for (const [entity, grid] of state.grids) {if (live.has(entity)) continue;core.renderer_setProbeVolumeOverride(entity as unknown as number, 0);+ core.renderer_setProbeVolumeReflection?.(entity as unknown as number, 0, 0);core.probe_volume_release?.(grid.handle);state.grids.delete(entity);+ dropped = true;}+ if (dropped || (state.grids.size && sky() !== state.sky)) rebuildReflections(core, module(), state, sky());if (state.pending !== null) {const status = core.renderer_pollProbeCapture();if (status === 0) return;@@ -133,19 +201,22 @@ export function probeCaptureSystem(module: () => ESEngineModule | null, sky: ()state.pending = null;if (status !== 1 || !live.has(entity)) return;const bytes = PROBE_CAPTURE_FACE * 6 * PROBE_CAPTURE_FACE * 4;+ let panorama: Panorama | null = null;const handle = withScratch(core as never, (alloc: (n: number) => number) => {const px = alloc(bytes);if (!core.renderer_takeProbeCapture!(px, bytes)) return 0;- const sh = projectIrradianceSH(capturePanorama(core.HEAPU8.slice(px, px + bytes), PROBE_CAPTURE_FACE, sky()));+ panorama = capturePanorama(core.HEAPU8.slice(px, px + bytes), PROBE_CAPTURE_FACE, sky());const shPtr = alloc(27 * 4);- core.HEAPF32.set(sh, shPtr >> 2);+ core.HEAPF32.set(projectIrradianceSH(panorama), shPtr >> 2);return core.probe_volume_create!(1, 1, 1, shPtr);});- if (!handle) return;+ if (!handle || !panorama) return;core.renderer_setProbeVolumeOverride(entity as unknown as number, handle);const old = state.grids.get(entity);if (old) core.probe_volume_release?.(old.handle);- state.grids.set(entity, { handle, at: now });+ state.grids.set(entity, { handle, at: now, panorama });+ // What a shiny surface in the box reflects follows what lights it.+ rebuildReflections(core, module(), state, sky());return;}if (due) {diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.tsindex f79a905f4..901aab6cb 100644--- a/sdk/src/wasm.ts+++ b/sdk/src/wasm.ts@@ -564,6 +564,7 @@ export interface ESEngineModule {renderer_pollProbeCapture?(): number;renderer_takeProbeCapture?(dst: number, bytes: number): boolean;renderer_setProbeVolumeOverride?(entity: number, volumeHandle: number): void;+ renderer_setProbeVolumeReflection?(entity: number, environmentHandle: number, slot: number): void;postprocess_pollSkyCapture?(): number;postprocess_takeSkyCapture?(dst: number, bytes: number): boolean;postprocess_setMsaaSamples(samples: number): void;diff --git a/src/esengine/bindings/RendererBindings.cpp b/src/esengine/bindings/RendererBindings.cppindex 0d9b2ee41..d811b3e2f 100644--- a/src/esengine/bindings/RendererBindings.cpp+++ b/src/esengine/bindings/RendererBindings.cpp@@ -1429,6 +1429,10 @@ bool renderer_takeProbeCapture(uintptr_t dst, u32 bytes) {return true;}+void renderer_setProbeVolumeReflection(u32 entity, u32 environmentHandle, u32 slot) {+ if (g_renderFrame) g_renderFrame->setProbeVolumeReflection(entity, environmentHandle, slot);+}+void renderer_setProbeVolumeOverride(u32 entity, u32 volumeHandle) {if (g_renderFrame) g_renderFrame->setProbeVolumeOverride(entity, resource::ProbeVolumeHandle(volumeHandle));}diff --git a/src/esengine/bindings/RendererBindings.hpp b/src/esengine/bindings/RendererBindings.hppindex 12cacc31a..98931a702 100644--- a/src/esengine/bindings/RendererBindings.hpp+++ b/src/esengine/bindings/RendererBindings.hpp@@ -332,6 +332,8 @@ i32 renderer_pollProbeCapture();bool renderer_takeProbeCapture(uintptr_t dst, u32 bytes);/** The grid the volume on @p entity reads instead of its own (a capture's); 0 stops. */void renderer_setProbeVolumeOverride(u32 entity, u32 volumeHandle);+/** The volume on @p entity reflects column @p slot of @p environmentHandle (an atlas of captures, column 0 the sky); 0 stops. */+void renderer_setProbeVolumeReflection(u32 entity, u32 environmentHandle, u32 slot);/** How many world units make a metre: what an inverse-square light measures distance in. */void renderer_setWorldUnitsPerMeter(f32 units);diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cppindex 8378b04a2..1fefed055 100644--- a/src/esengine/bindings/WebSDKEntry.cpp+++ b/src/esengine/bindings/WebSDKEntry.cpp@@ -822,6 +822,7 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {emscripten::function("renderer_pollProbeCapture", &esengine::renderer_pollProbeCapture);emscripten::function("renderer_takeProbeCapture", &esengine::renderer_takeProbeCapture);emscripten::function("renderer_setProbeVolumeOverride", &esengine::renderer_setProbeVolumeOverride);+ emscripten::function("renderer_setProbeVolumeReflection", &esengine::renderer_setProbeVolumeReflection);emscripten::function("renderer_setMeshEdgeBuffers", &esengine::renderer_setMeshEdgeBuffers);emscripten::function("renderer_setViewSkinWeights", &esengine::renderer_setViewSkinWeights);emscripten::function("renderer_lightStatus", &esengine::renderer_lightStatus);diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cppindex 0f8c770b2..a9011d0b8 100644--- a/src/esengine/renderer/frame/RenderFrame.cpp+++ b/src/esengine/renderer/frame/RenderFrame.cpp@@ -1606,6 +1606,20 @@ void RenderFrame::collectReflections(ecs::Registry& registry) {const glm::vec3 half = glm::abs(probe.halfExtents);store.add(centre - half, centre + half, probe.slot, probe.reflection.id());}+ // Probe volumes filled at run time reflect their capture too, a column each of the atlas the SDK built from them;+ // the frame binds one atlas, so a scene with baked reflection probes keeps those.+ if (store.empty() && !probe_reflections_.empty()) {+ auto volumes = registry.activeView<ecs::LightProbeVolume>();+ for (auto entity : volumes) {+ const auto found = probe_reflections_.find(static_cast<u32>(entity));+ if (found == probe_reflections_.end() || !volumes.get(entity).enabled) continue;+ const auto* transform = registry.tryGet<ecs::Transform>(entity);+ if (!transform) continue;+ const glm::vec3 centre = rebased(transform->worldPosition);+ const glm::vec3 half = glm::abs(volumes.get(entity).halfExtents);+ store.add(centre - half, centre + half, found->second.slot, found->second.environment);+ }+ }if (store.empty()) return;const Environment* baked =diff --git a/src/esengine/renderer/frame/RenderFrame.hpp b/src/esengine/renderer/frame/RenderFrame.hppindex e2f3da407..a340cb8be 100644--- a/src/esengine/renderer/frame/RenderFrame.hpp+++ b/src/esengine/renderer/frame/RenderFrame.hpp@@ -416,6 +416,12 @@ public:const std::vector<u8>& probeCapturePixels() const { return probe_capture_.pixels; }/** @brief The grid a volume reads instead of its own `probes` (a capture's), or an invalid handle to stop. */void setProbeVolumeOverride(u32 entity, resource::ProbeVolumeHandle grid);+ /** @brief The volume on @p entity reflects column @p slot of @p environment (an atlas built from captures, column 0 the+ * sky); an invalid environment stops. Used only where no baked ReflectionProbe is. */+ void setProbeVolumeReflection(u32 entity, u32 environment, u32 slot) {+ if (environment != 0 && slot != 0) probe_reflections_[entity] = {environment, slot};+ else probe_reflections_.erase(entity);+ }/** @brief How many world units make a metre (the project's setting): what an inverse-square light measures in. */void setWorldUnitsPerMeter(f32 units) { world_units_per_meter_ = units > 0.0f ? units : 100.0f; }@@ -802,6 +808,8 @@ private:};ProbeCapture probe_capture_;std::unordered_map<u32, resource::ProbeVolumeHandle> probe_overrides_;+ struct CapturedReflection { u32 environment = 0; u32 slot = 0; };+ std::unordered_map<u32, CapturedReflection> probe_reflections_;void executePlanarReflection(ecs::Registry& registry, u32 view);struct PlanarCapture {Unique<Framebuffer> target;diff --git a/src/esengine/renderer/frame/RenderFrameProbeCapture.cpp b/src/esengine/renderer/frame/RenderFrameProbeCapture.cppindex c9f5b3789..53f0447da 100644--- a/src/esengine/renderer/frame/RenderFrameProbeCapture.cpp+++ b/src/esengine/renderer/frame/RenderFrameProbeCapture.cpp@@ -70,7 +70,7 @@ void RenderFrame::declareProbeCapture(ecs::Registry& registry) {const u32 n = c.face;const GfxPixelFormat format = linear_color_ && device_.supportsFloatTargets() && !planar_float_refused_? GfxPixelFormat::RGBA16F : GfxPixelFormat::RGBA8;- const u32 f = c.next;+ const u32 f = std::min(c.next, 5u);auto& target = c.faces[f];if (!target || target->getWidth() != n || target->getSpecification().colorFormat != format) {FramebufferSpec spec;@@ -115,12 +115,16 @@ void RenderFrame::declareProbeCapture(ecs::Registry& registry) {pack.viewportY = 0;pack.viewportW = n;pack.viewportH = n;+ // The face counts as done when it is DRAWN, not when it is declared: a frame whose graph is built and not run would+ // otherwise skip it for good, and the last one would leave the capture waiting for ever.pack.execute = [this, f](const rg::PassContext&) {post_process_->encodeRgbm();- if (f == 5) probe_capture_.state = ProbeCapture::State::Drawn;+ ProbeCapture& done = probe_capture_;+ if (done.state != ProbeCapture::State::Capturing || done.next != f) return;+ done.next = f + 1;+ if (f == 5) done.state = ProbeCapture::State::Drawn;};graph_.addPass(std::move(pack));- c.next = f + 1;#else(void)registry;#endifdiff --git a/src/esengine/renderer/plugins/MeshPlugin.cpp b/src/esengine/renderer/plugins/MeshPlugin.cppindex 228c81e5e..5093b0181 100644--- a/src/esengine/renderer/plugins/MeshPlugin.cpp+++ b/src/esengine/renderer/plugins/MeshPlugin.cpp@@ -1115,7 +1115,7 @@ void MeshPlugin::collect(RenderCollectContext& collect_ctx) {const bool volume = key.lightmapTextureId == 0&& store.sampleBox(aabbCenter, halfExtents, probe, !resident->hasLightmapUV);if (volume && probe.irradiance[0].w > 1.5f) key.probeGridTextureId = store.atlasTexture();- const u32 slot = ctx.render_context.reflections().slotAt(position);+ const u32 slot = ctx.render_context.reflections().slotForBox(aabbCenter, halfExtents);probe.reflection.x = static_cast<f32>(slot);if (volume || slot != 0) key.probeIndex = draw_list.addProbe(probe);}diff --git a/src/esengine/renderer/store/ReflectionStore.hpp b/src/esengine/renderer/store/ReflectionStore.hppindex 6bf345a8a..95f92aac1 100644--- a/src/esengine/renderer/store/ReflectionStore.hpp+++ b/src/esengine/renderer/store/ReflectionStore.hpp@@ -83,6 +83,26 @@ public:return best ? best->slot : 0u;}+ /**+ * @brief The column a whole object reflects, by its world box rather than its origin (ProbeStore::sampleBox's rule):+ * its centre's, else the smallest probe the box overlaps. An imported level's walls keep their origin at the+ * world's centre, outside the room they stand in.+ */+ u32 slotForBox(const glm::vec3& centre, const glm::vec3& half) const {+ if (const u32 at = slotAt(centre); at != 0) return at;+ const Probe* best = nullptr;+ f32 bestSize = 0.0f;+ for (const Probe& v : probes_) {+ const glm::vec3 vc = (v.min + v.max) * 0.5f;+ const glm::vec3 vh = (v.max - v.min) * 0.5f;+ const glm::vec3 gap = glm::abs(centre - vc) - (half + vh);+ if (gap.x > 0.0f || gap.y > 0.0f || gap.z > 0.0f) continue;+ const f32 size = vh.x * vh.y * vh.z;+ if (!best || size < bestSize) { best = &v; bestSize = size; }+ }+ return best ? best->slot : 0u;+ }+/** @brief The probes themselves, for the frame block that carries their boxes. */const std::vector<Probe>& probes() const { return probes_; }diff --git a/tools/render-host/run.mjs b/tools/render-host/run.mjsindex ab9cfaf97..10f409089 100644--- a/tools/render-host/run.mjs+++ b/tools/render-host/run.mjs@@ -376,11 +376,14 @@ app.whenReady().then(async () => {// — video (HTMLVideoElement) decodes frames in real time and its system// uploads the newest frame each tick. Interleave engine steps with real// delays so frames actually arrive before the capture. Requires play mode.+ // ESTELLA_VERIFY_SETTLE_STEPS: at least this many steps as well. Content that takes frames rather than time — a+ // probe capture draws a face a frame — would otherwise lose the race on a loaded machine, whose steps run slow.const ms = Number(process.env.ESTELLA_VERIFY_SETTLE_MS) || 1500;+ const minSteps = Number(process.env.ESTELLA_VERIFY_SETTLE_STEPS) || 0;await exec(`(async () => {const api = window.__estellaHeadless.api;const end = performance.now() + ${ms};- while (performance.now() < end) {+ for (let n = 0; performance.now() < end || n < ${minSteps}; n++) {await api.step(1, 1 / 60);await new Promise((r) => setTimeout(r, 16));}diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjsindex bd3a70e6e..86212995e 100644--- a/tools/renderScenes.mjs+++ b/tools/renderScenes.mjs@@ -923,7 +923,11 @@ export const SCENES = [// A probe volume filled at run time: a white ball lit only by what a capture at its centre sees, a red wall to its right, blue// to its left, green above. The ball takes each wall's colour on the side that faces it; a capture read the wrong way round// swaps them, and none leaves the ball black.- { id: "probe-capture", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SETTLE_MS: "3000", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/probe-capture.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-backface.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.645,\"y\":0.5,\"rgb\":[144,93,32],\"tol\":20},{\"x\":0.355,\"y\":0.5,\"rgb\":[34,93,142],\"tol\":20},{\"x\":0.5,\"y\":0.36,\"rgb\":[92,142,91],\"tol\":20},{\"x\":0.5,\"y\":0.645,\"rgb\":[92,34,91],\"tol\":20}]" } },+ { id: "probe-capture", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SETTLE_MS: "3000", ESTELLA_VERIFY_SETTLE_STEPS: "60", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/probe-capture.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-backface.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.645,\"y\":0.5,\"rgb\":[144,93,32],\"tol\":20},{\"x\":0.355,\"y\":0.5,\"rgb\":[34,93,142],\"tol\":20},{\"x\":0.5,\"y\":0.36,\"rgb\":[92,142,91],\"tol\":20},{\"x\":0.5,\"y\":0.645,\"rgb\":[92,34,91],\"tol\":20}]" } },+ // The same capture, mirrored: a chrome ball under a blue-above, red-below sky, a green wall to its right and a magenta one+ // to its left. Inside the box it reflects the room the capture saw — green on its right, magenta on its left — and not+ // the sky's blue and red, which is what it reflected before captures fed reflections.+ { id: "probe-capture-reflection", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SETTLE_MS: "3000", ESTELLA_VERIFY_SETTLE_STEPS: "60", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/probe-capture-reflection.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-backface.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.352,\"y\":0.5,\"rgb\":[253,18,253],\"tol\":30},{\"x\":0.648,\"y\":0.5,\"rgb\":[33,252,33],\"tol\":30}]" } },{ id: "custom-sky", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_SETTLE_MS: "1500", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/custom-sky.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-backface.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.08,\"y\":0.08,\"rgb\":[89,124,243],\"tol\":10},{\"x\":0.08,\"y\":0.92,\"rgb\":[231,108,63],\"tol\":10},{\"x\":0.5,\"y\":0.32,\"rgb\":[127,121,226],\"tol\":20},{\"x\":0.5,\"y\":0.68,\"rgb\":[217,111,118],\"tol\":20}]" } },{ id: "sky-fog", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/sky-fog.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/depth-outline.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\": 0.2, \"y\": 0.1, \"rgb\": [144, 175, 187], \"tol\": 12}, {\"x\": 0.5, \"y\": 0.1, \"rgb\": [141, 174, 183], \"tol\": 12}, {\"x\": 0.8, \"y\": 0.2, \"rgb\": [143, 174, 186], \"tol\": 12}, {\"x\": 0.5, \"y\": 0.4, \"rgb\": [139, 171, 180], \"tol\": 12}, {\"x\": 0.2, \"y\": 0.8, \"rgb\": [62, 70, 70], \"tol\": 12}, {\"x\": 0.8, \"y\": 0.8, \"rgb\": [57, 64, 67], \"tol\": 12}]" } },// SSAO: one unlit grey floor read at seven places. Contact, corner and