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 probe volume can be filled at run time
yhhd9910de3549d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bbc68988e..1feab2275 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 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'`).- **Direct Lighting Only and Indirect Lighting Only view modes.** Beside Clay in the viewport's Show menu (and `Renderer.setViewShading(view, 'directLighting' | 'indirectLighting')`), as Unreal's lighting components: clay lit by the lights alone, or by everything that is not a light (ambient, sky, reflections, probes, bakes). The two add up to Clay, so a dark shadow says at once whether its fill is missing or merely weak.diff --git a/cmake/ESEngineSources.cmake b/cmake/ESEngineSources.cmakeindex 6509b0a82..80d829d16 100644--- a/cmake/ESEngineSources.cmake+++ b/cmake/ESEngineSources.cmake@@ -27,6 +27,7 @@ set(ESENGINE_SOURCES${ESENGINE_ROOT}/src/esengine/renderer/frame/RenderFrameMask.cpp${ESENGINE_ROOT}/src/esengine/renderer/frame/RenderFrameShadow2D.cpp${ESENGINE_ROOT}/src/esengine/renderer/frame/RenderFramePlanar.cpp+ ${ESENGINE_ROOT}/src/esengine/renderer/frame/RenderFrameProbeCapture.cpp${ESENGINE_ROOT}/src/esengine/renderer/frame/RenderFrameOverlay.cpp${ESENGINE_ROOT}/src/esengine/renderer/frame/RenderFrameSubmit.cpp${ESENGINE_ROOT}/src/esengine/renderer/frame/FrameCapture.cppdiff --git a/docs/astro/src/content/docs/graphics/lighting.mdx b/docs/astro/src/content/docs/graphics/lighting.mdxindex ff35f6815..16d87ce6e 100644--- a/docs/astro/src/content/docs/graphics/lighting.mdx+++ b/docs/astro/src/content/docs/graphics/lighting.mdx@@ -535,6 +535,23 @@ and fills in every `MeshLightmap`, and `node pipeline/bin/estella.mjs bake-scene(Blender's Cycles, a Substance bake, any renderer that writes a lightmap and its UVlayout) is still read exactly as well — the component is the contract, not the baker.+### A room lit by what it looks like now: runtime capture++A bake sees only what it can hold: a mesh without a lightmap UV set is black to it, so lamps that light the walls of a+shed put none of that light back into its probes. Set **`capture`** on a `LightProbeVolume` and it is filled at run time+instead: the scene is drawn from the box's centre all round — the walls as the lights light them now, the sky through+the openings — and that is the light everything inside reads, in place of a bake. It is Unreal's real-time Sky Light or+Reflection Capture, and the "interior environment" a hand-built renderer captures inside a building.++```ts+entity.insert(LightProbeVolume, { halfExtents: { x: 22, y: 7, z: 11 }, capture: true, captureInterval: 2 });+```++- One face is drawn a frame, small (32 pixels), so a capture costs six small extra scene draws spread over six frames.+- **`captureInterval`** recaptures every so many seconds (0 = once). Each capture sees the room lit by the last one, so a+ few 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 reflects indoorsA lightmap is the diffuse half. The other half is what a **mirror** shows, and withoutdiff --git a/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx b/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdxindex 3def89c02..87cd5e544 100644--- a/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx+++ b/docs/astro/src/content/docs/zh-cn/graphics/lighting.mdx@@ -464,6 +464,21 @@ quality: { profiles: { medium: { lighting: 'full' } } }Cycles、Substance 的烘焙、任何写出 lightmap 与其 UV 布局的渲染器)照样读得一样好——契约是组件,不是烘焙器。+### 用房间此刻的样子照亮它:运行时捕获++烘焙只看得见它能保存的东西:没有光照贴图 UV 的网格在它眼里是黑的,所以棚里的灯照亮了墙,这部分光却回不到探针里。+给 `LightProbeVolume` 打开 **`capture`**,它就改为在运行时填充:从盒子中心向四周把场景画一遍——墙被灯照亮的此刻的样子、+从开口看到的天空——盒子里的一切读这份光,代替烘焙。这对应虚幻的实时 Sky Light 或 Reflection Capture,也就是手写渲染器+在建筑里拍的那张"室内环境"。++```ts+entity.insert(LightProbeVolume, { halfExtents: { x: 22, y: 7, z: 11 }, capture: true, captureInterval: 2 });+```++- 每帧只画一个面,而且很小(32 像素),一次捕获相当于分摊到 6 帧里的 6 次小场景绘制。+- **`captureInterval`** 每隔多少秒重拍一次(0 = 只拍一次)。每次拍到的房间都包含上一次的补光,所以拍几次就是几次反弹。+- 一个盒子只有一个光照点:适合一个房间,不适合两头差别很大的长厅——那就用几个盒子。+### 室内的镜面反射的是什么lightmap 是漫反射那一半。另一半是**镜子**里看到的东西,而没有探针时那永远是天空——在室内,一颗diff --git a/docs/astro/src/data/components.generated.json b/docs/astro/src/data/components.generated.jsonindex 3e3258f9d..a1536eabf 100644--- a/docs/astro/src/data/components.generated.json+++ b/docs/astro/src/data/components.generated.json@@ -3750,6 +3750,19 @@"default": "none","doc": "Baked probe grid (.esprobes) filling this box."},+ {+ "key": "capture",+ "type": "boolean",+ "default": "false",+ "doc": "Fill this box at run time from a capture at its centre (the room as lit now), not from a bake."+ },+ {+ "key": "captureInterval",+ "type": "number",+ "default": "0",+ "doc": "Seconds between captures (0 = once). Each one adds a bounce.",+ "range": "≥ 0"+ },{"key": "halfExtents","type": "Vec3",diff --git a/fixtures/scenes/probe-capture.esscene b/fixtures/scenes/probe-capture.esscenenew file mode 100644index 000000000..17e3016ad--- /dev/null+++ b/fixtures/scenes/probe-capture.esscene@@ -0,0 +1,264 @@+{+ "version": 4,+ "name": "ProbeCapture",+ "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+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Red",+ "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": 0,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": false,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "Blue",+ "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": 0,+ "b": 1,+ "a": 1+ },+ "lit": false,+ "opaque": true,+ "cullBackfaces": false,+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "Green",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 300,+ "z": 0+ },+ "scale": {+ "x": 6,+ "y": 0.1,+ "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": 5,+ "name": "Capture",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "LightProbeVolume",+ "data": {+ "halfExtents": {+ "x": 250,+ "y": 250,+ "z": 250+ },+ "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": "vignette",+ "enabled": true,+ "uniforms": {+ "u_intensity": 0+ }+ }+ ]+ }+ }+ ]+ }+ ]+}diff --git a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts b/sdk/src/ecs/bridge/nativeEngineApi.generated.tsindex 89e8628a6..9fd9fb091 100644--- a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts+++ b/sdk/src/ecs/bridge/nativeEngineApi.generated.ts@@ -205,6 +205,7 @@ export interface NativeEngineApi {renderer_lodInspect?(view: number, entity: number, outPtr: number): number;renderer_pollFrameCapture?(handle: number): number;renderer_pollPreviewReadback?(): number;+ renderer_pollProbeCapture?(): number;renderer_pollSkeletalPreview?(preview: number): number;renderer_pollSnapshotReadback?(): number;renderer_programEpoch?(): number;@@ -213,6 +214,7 @@ export interface NativeEngineApi {renderer_renderMeshPreview?(meshId: number, w: number, h: number): void;renderer_renderSkeletalPreview?(preview: number, viewProjectionPtr: number): number;renderer_replayToDrawCall?(drawCallIndex: number): void;+ renderer_requestProbeCapture?(x: number, y: number, z: number, face: number): void;renderer_resize?(width: number, height: number): void;renderer_retainedTextBatch?(entity: number, verticesPtr: number, vertexCount: number, indicesPtr: number, indexCount: number, pageId: number, glyphMode: number): void;renderer_retainedTextBegin?(entity: number, sdf: number, screen: number, hasBox: number, layer: number, boxWidth: number, boxHeight: number, autoKind: number): void;@@ -232,6 +234,7 @@ export interface NativeEngineApi {renderer_setMeshEdgeBuffers?(enabled: boolean): void;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_setQualityBudgets?(atlasSize: number, cellSize: number, cascades: number, particleLimit: number): void;renderer_setShadow2DSoftSamples?(samples: number): void;renderer_setShadowDistance?(distance: number): void;@@ -256,6 +259,7 @@ export interface NativeEngineApi {renderer_submitSkeletalPreviewBatchEx?(preview: number, verticesPtr: number, vertexCount: number, indicesPtr: number, indexCount: number, textureId: number, blendMode: number, transformPtr: number, layer: number, depth: number, materialId: number, premultipliedColor: boolean): number;renderer_submitTextBatch?(verticesPtr: number, vertexCount: number, indicesPtr: number, indexCount: number, textureId: number, transformPtr: number, entity: number, layer: number, depth: number, glyphMode: number, cullBit: number): void;renderer_takeFrameCapture?(handle: number, dest: number, destSize: number): boolean;+ renderer_takeProbeCapture?(dst: number, bytes: number): boolean;renderer_takeTextureWants?(): string;renderer_updateTransforms?(registry: unknown): void;rm_acquireTextureByPath?(rm: unknown, path: string): number;@@ -554,6 +558,7 @@ export function createNativeEngineApi(bind('renderer_lodInspect', 'es_renderer_lodInspect', false);bind('renderer_pollFrameCapture', 'es_renderer_pollFrameCapture', false);bind('renderer_pollPreviewReadback', 'es_renderer_pollPreviewReadback', false);+ bind('renderer_pollProbeCapture', 'es_renderer_pollProbeCapture', false);bind('renderer_pollSkeletalPreview', 'es_renderer_pollSkeletalPreview', false);bind('renderer_pollSnapshotReadback', 'es_renderer_pollSnapshotReadback', false);bind('renderer_programEpoch', 'es_renderer_programEpoch', false);@@ -562,6 +567,7 @@ export function createNativeEngineApi(bind('renderer_renderMeshPreview', 'es_renderer_renderMeshPreview', false);bind('renderer_renderSkeletalPreview', 'es_renderer_renderSkeletalPreview', false);bind('renderer_replayToDrawCall', 'es_renderer_replayToDrawCall', false);+ bind('renderer_requestProbeCapture', 'es_renderer_requestProbeCapture', false);bind('renderer_resize', 'es_renderer_resize', false);bind('renderer_retainedTextBatch', 'es_renderer_retainedTextBatch', false);bind('renderer_retainedTextBegin', 'es_renderer_retainedTextBegin', false);@@ -581,6 +587,7 @@ export function createNativeEngineApi(bind('renderer_setMeshEdgeBuffers', 'es_renderer_setMeshEdgeBuffers', false);bind('renderer_setOrigin', 'es_renderer_setOrigin', false);bind('renderer_setPlanarReflectionQuality', 'es_renderer_setPlanarReflectionQuality', false);+ bind('renderer_setProbeVolumeOverride', 'es_renderer_setProbeVolumeOverride', false);bind('renderer_setQualityBudgets', 'es_renderer_setQualityBudgets', false);bind('renderer_setShadow2DSoftSamples', 'es_renderer_setShadow2DSoftSamples', false);bind('renderer_setShadowDistance', 'es_renderer_setShadowDistance', false);@@ -605,6 +612,7 @@ export function createNativeEngineApi(bind('renderer_submitSkeletalPreviewBatchEx', 'es_renderer_submitSkeletalPreviewBatchEx', false);bind('renderer_submitTextBatch', 'es_renderer_submitTextBatch', false);bind('renderer_takeFrameCapture', 'es_renderer_takeFrameCapture', false);+ bind('renderer_takeProbeCapture', 'es_renderer_takeProbeCapture', false);bind('renderer_takeTextureWants', 'es_renderer_takeTextureWants', false);bind('renderer_updateTransforms', 'es_renderer_updateTransforms', true);bind('rm_acquireTextureByPath', 'es_rm_acquireTextureByPath', true);diff --git a/sdk/src/ecs/bridge/ptrAccessors.generated.ts b/sdk/src/ecs/bridge/ptrAccessors.generated.tsindex 15baf0e5b..16f13e630 100644--- a/sdk/src/ecs/bridge/ptrAccessors.generated.ts+++ b/sdk/src/ecs/bridge/ptrAccessors.generated.ts@@ -1067,6 +1067,8 @@ export function createLightData(): LightPtrData {export interface LightProbeVolumePtrData {probes: number;+ capture: boolean;+ captureInterval: number;halfExtents: Vec3;spacing: number;enabled: boolean;@@ -1077,9 +1079,11 @@ export function fillLightProbeVolume(ptr: number, out: LightProbeVolumePtrData,): void {out.probes = u32[ptr >> 2];- const halfExtents_ = out.halfExtents; halfExtents_.x = f32[(ptr + 4) >> 2]; halfExtents_.y = f32[((ptr + 4) >> 2) + 1]; halfExtents_.z = f32[((ptr + 4) >> 2) + 2];- out.spacing = f32[(ptr + 16) >> 2];- out.enabled = u8[ptr + 20] !== 0;+ out.capture = u8[ptr + 4] !== 0;+ out.captureInterval = f32[(ptr + 8) >> 2];+ const halfExtents_ = out.halfExtents; halfExtents_.x = f32[(ptr + 12) >> 2]; halfExtents_.y = f32[((ptr + 12) >> 2) + 1]; halfExtents_.z = f32[((ptr + 12) >> 2) + 2];+ out.spacing = f32[(ptr + 24) >> 2];+ out.enabled = u8[ptr + 28] !== 0;}export function writeLightProbeVolume(@@ -1087,14 +1091,18 @@ export function writeLightProbeVolume(ptr: number, data: LightProbeVolumePtrData,): void {u32[ptr >> 2] = data.probes;- f32[(ptr + 4) >> 2] = data.halfExtents.x; f32[((ptr + 4) >> 2) + 1] = data.halfExtents.y; f32[((ptr + 4) >> 2) + 2] = data.halfExtents.z;- f32[(ptr + 16) >> 2] = data.spacing;- u8[ptr + 20] = data.enabled ? 1 : 0;+ u8[ptr + 4] = data.capture ? 1 : 0;+ f32[(ptr + 8) >> 2] = data.captureInterval;+ f32[(ptr + 12) >> 2] = data.halfExtents.x; f32[((ptr + 12) >> 2) + 1] = data.halfExtents.y; f32[((ptr + 12) >> 2) + 2] = data.halfExtents.z;+ f32[(ptr + 24) >> 2] = data.spacing;+ u8[ptr + 28] = data.enabled ? 1 : 0;}export function createLightProbeVolumeData(): LightProbeVolumePtrData {return {probes: 0,+ capture: false,+ captureInterval: 0,halfExtents: { x: 0, y: 0, z: 0 },spacing: 0,enabled: false,diff --git a/sdk/src/ecs/component.generated.ts b/sdk/src/ecs/component.generated.tsindex 7e80cad9c..62bb25b71 100644--- a/sdk/src/ecs/component.generated.ts+++ b/sdk/src/ecs/component.generated.ts@@ -15,7 +15,7 @@ import type { AlignContent, AlignItems, AlignSelf, BillboardMode, BodyType, Canv* getAbiLayoutHash(); BuiltinBridge.connect() compares them and refuses to* run on mismatch, because mismatched offsets read the wrong heap bytes.*/-export const ABI_LAYOUT_HASH = '04486d0b29ae33ae';+export const ABI_LAYOUT_HASH = '9b9790d2839bd020';/*** One asset-valued field of a component: which field, and what kind of@@ -590,6 +590,8 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {LightProbeVolume: {defaults: {probes: 0,+ capture: false,+ captureInterval: 0,halfExtents: { x: 100, y: 100, z: 100 },spacing: 100,enabled: true,@@ -600,6 +602,8 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {animatableFields: [],fields: {probes: { tooltip: "Baked probe grid (.esprobes) filling this box." },+ capture: { tooltip: "Fill this box at run time from a capture at its centre (the room as lit now), not from a bake." },+ captureInterval: { min: 0, tooltip: "Seconds between captures (0 = once). Each one adds a bounce.", shownWhen: { field: "capture", values: [1] } },halfExtents: { min: 0, tooltip: "Half the box this volume covers, from the entity's position." },spacing: { min: 1, tooltip: "World units between probes the next bake lays down." },},@@ -1758,6 +1762,8 @@ export interface LightData {export interface LightProbeVolumeData {probes: number;+ capture: boolean;+ captureInterval: number;halfExtents: Vec3;spacing: number;enabled: boolean;diff --git a/sdk/src/postprocess/PostProcessPlugin.ts b/sdk/src/postprocess/PostProcessPlugin.tsindex 0612e77cb..ddfdd4af0 100644--- a/sdk/src/postprocess/PostProcessPlugin.ts+++ b/sdk/src/postprocess/PostProcessPlugin.ts@@ -17,6 +17,7 @@ import { linearColorSpace } from '../ecs/env';import type { Entity } from '../types';import { resolvedLightingSky } from './volumeSystem';import { SkyEnvironment, skyParamsOf, skySunOf } from './skyEnvironment';+import { probeCaptureSystem } from './probeCapture';/** Toward the sun from the first directional light that shines: the way the sky's shader finds it (the light's aim reversed). */function sunFromLights(lights: Iterable<[Entity, LightData, TransformData]>): [number, number, number] | null {@@ -83,6 +84,8 @@ export class PostProcessPlugin implements Plugin {const sky = new SkyEnvironment();this.skies_.set(app, sky);app.addSystemToSchedule(Schedule.PostUpdate, skyEnvironmentSystem(app, sky));+ // After the sky: a volume filled at run time shows the sky that lights the scene where it sees it.+ app.addSystemToSchedule(Schedule.PostUpdate, probeCaptureSystem(() => app.wasmModule, () => sky.panorama));}cleanup(app?: App): void {diff --git a/sdk/src/postprocess/probeCapture.ts b/sdk/src/postprocess/probeCapture.tsnew file mode 100644index 000000000..10ac4c562--- /dev/null+++ b/sdk/src/postprocess/probeCapture.ts@@ -0,0 +1,158 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file probeCapture.ts+ * @brief A probe volume filled at run time: the room as a camera at its centre sees it now.+ *+ * @details The engine draws the scene from the volume's centre into six small faces, one a frame, packs them as RGBM and+ * reads them back (RenderFrameProbeCapture.cpp). Here they are turned into a panorama — a pixel nothing was drawn+ * on is the sky, taken from the sky the scene is lit with — projected to nine irradiance coefficients like any+ * environment, and handed to the engine as a one-point grid the volume reads in place of its bake. Unreal's+ * real-time Sky Light / Reflection Capture; the "interior environment" a hand-built renderer captures in a shed.+ */++import { defineSystem } from '../ecs/system';+import { Query } from '../ecs/query';+import { Transform, LightProbeVolume, type TransformData, type LightProbeVolumeData } from '../ecs/component';+import type { Entity } from '../types';+import type { ESEngineModule } from '../wasm';+import { withScratch } from '../wasm/wasmScratch';+import { projectIrradianceSH, type Panorama } from '../lightmap/environmentAtlas';+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. */+export const PROBE_CAPTURE_FACE = 32;+const RANGE = 8;+const WIDTH = 64;++// Toward each face and its up, as RenderFrameProbeCapture.cpp draws them: +X -X +Y -Y +Z -Z.+const FACE_DIR = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]] as const;+const FACE_UP = [[0, 1, 0], [0, 1, 0], [0, 0, -1], [0, 0, 1], [0, 1, 0], [0, 1, 0]] as const;++const cross = (a: readonly number[], b: readonly number[]): number[] =>+ [a[1]! * b[2]! - a[2]! * b[1]!, a[2]! * b[0]! - a[0]! * b[2]!, a[0]! * b[1]! - a[1]! * b[0]!];+const dot = (a: readonly number[], b: readonly number[]): number => a[0]! * b[0]! + a[1]! * b[1]! + a[2]! * b[2]!;+const unit = (a: number[]): number[] => { const l = Math.hypot(a[0]!, a[1]!, a[2]!) || 1; return [a[0]! / l, a[1]! / l, a[2]! / l]; };++// A lookAt camera's right and up for each face: what the direction's x and y are measured along.+const FACE_BASIS = FACE_DIR.map((f, i) => {+ const right = unit(cross(f, FACE_UP[i]!));+ return { forward: f, right, up: cross(right, f) };+});++/**+ * The six RGBM faces (side by side, rows bottom-up as a readback lands) as a panorama of radiance, Panorama's layout. A+ * pixel with alpha 0 had nothing drawn on it and takes the sky there: `sky`, or black without one.+ */+export function capturePanorama(rgba: Uint8Array, face: number, sky: Panorama | null): Panorama {+ const height = WIDTH >> 1;+ const rgb = new Float32Array(WIDTH * height * 3);+ const stride = face * 6;+ for (let y = 0; y < height; y++) {+ for (let x = 0; x < WIDTH; x++) {+ const d = panoramaDirection((x + 0.5) / WIDTH, (y + 0.5) / height);+ let f = 0, best = -Infinity;+ for (let i = 0; i < 6; i++) { const c = dot(d, FACE_DIR[i]!); if (c > best) { best = c; f = i; } }+ const b = FACE_BASIS[f]!;+ const z = dot(d, b.forward);+ const u = dot(d, b.right) / z * 0.5 + 0.5, v = dot(d, b.up) / z * 0.5 + 0.5;+ const px = Math.min(face - 1, Math.max(0, Math.floor(u * face)));+ const row = Math.min(face - 1, Math.max(0, Math.floor(v * face)));+ const i = (row * stride + f * face + px) * 4;+ const o = (y * WIDTH + x) * 3;+ if (rgba[i + 3]! === 0) {+ if (sky) {+ const [su, sv] = panoramaUV(d[0]!, d[1]!, d[2]!);+ const sx = Math.min(sky.width - 1, Math.floor(su * sky.width));+ const sy = Math.min(sky.height - 1, Math.floor(sv * sky.height));+ const s = (sy * sky.width + sx) * 3;+ rgb[o] = sky.rgb[s]!; rgb[o + 1] = sky.rgb[s + 1]!; rgb[o + 2] = sky.rgb[s + 2]!;+ }+ continue;+ }+ const m = (rgba[i + 3]! / 255) * RANGE;+ rgb[o] = (rgba[i]! / 255) * m; rgb[o + 1] = (rgba[i + 1]! / 255) * m; rgb[o + 2] = (rgba[i + 2]! / 255) * m;+ }+ }+ return { width: WIDTH, height, rgb };+}++interface CaptureCore {+ HEAPF32: Float32Array;+ HEAPU8: Uint8Array;+ renderer_requestProbeCapture?(x: number, y: number, z: number, face: number): void;+ renderer_pollProbeCapture?(): number;+ renderer_takeProbeCapture?(dst: number, bytes: number): boolean;+ renderer_setProbeVolumeOverride?(entity: number, volumeHandle: 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 }>;+ pending: Entity | null;+}++/**+ * The system that keeps capturing volumes filled: one capture at a time, the volume due longest first, again every+ * `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 };+ return defineSystem(+ [Query(LightProbeVolume, Transform)],+ (volumes: Iterable<[Entity, LightProbeVolumeData, TransformData]>) => {+ const core = module() as unknown as CaptureCore | null;+ if (!core?.renderer_requestProbeCapture || !core.renderer_pollProbeCapture || !core.renderer_takeProbeCapture+ || !core.renderer_setProbeVolumeOverride || !core.probe_volume_create) return;+ const now = performance.now() / 1000;+ const live = new Set<Entity>();+ let due: { entity: Entity; at: [number, number, number]; since: number } | null = null;+ for (const [entity, volume, transform] of volumes) {+ if (!volume.capture || !volume.enabled) continue;+ live.add(entity);+ const had = state.grids.get(entity);+ const interval = volume.captureInterval ?? 0;+ if (had && (interval <= 0 || now - had.at < interval)) continue;+ const since = had ? now - had.at : Infinity;+ 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.+ for (const [entity, grid] of state.grids) {+ if (live.has(entity)) continue;+ core.renderer_setProbeVolumeOverride(entity as unknown as number, 0);+ core.probe_volume_release?.(grid.handle);+ state.grids.delete(entity);+ }+ if (state.pending !== null) {+ const status = core.renderer_pollProbeCapture();+ if (status === 0) return;+ const entity = state.pending;+ state.pending = null;+ if (status !== 1 || !live.has(entity)) return;+ const bytes = PROBE_CAPTURE_FACE * 6 * PROBE_CAPTURE_FACE * 4;+ 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()));+ const shPtr = alloc(27 * 4);+ core.HEAPF32.set(sh, shPtr >> 2);+ return core.probe_volume_create!(1, 1, 1, shPtr);+ });+ if (!handle) 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 });+ return;+ }+ if (due) {+ core.renderer_requestProbeCapture(due.at[0], due.at[1], due.at[2], PROBE_CAPTURE_FACE);+ state.pending = due.entity;+ }+ },+ { name: 'ProbeCaptureSystem', runWhenPaused: true },+ );+}diff --git a/sdk/src/postprocess/skyEnvironment.ts b/sdk/src/postprocess/skyEnvironment.tsindex 9f6b48bf4..4c9f443d2 100644--- a/sdk/src/postprocess/skyEnvironment.ts+++ b/sdk/src/postprocess/skyEnvironment.ts@@ -425,9 +425,14 @@ export class SkyEnvironment {private lastBake_ = -Infinity;private warned_ = false;private capturing_ = false;+ private panorama_: Panorama | null = null;constructor(private readonly minInterval = 1) {}+ /** The panorama the sky's environment was last made from (radiance, Panorama's layout), or null: what a probe capture+ * shows where it sees the sky. */+ get panorama(): Panorama | null { return this.panorama_; }+/** The environment handle the frame is lighting with, 0 when none. */get environment(): number { return this.baked_?.environment ?? 0; }@@ -452,8 +457,10 @@ export class SkyEnvironment {if (key === this.key_) return;// A first sky is made at once; a sky that keeps changing waits its turn.if (this.baked_ && now - this.lastBake_ < this.minInterval) return;- const made = bakePanorama(module, core, skyPanorama(input));+ const panorama = skyPanorama(input);+ const made = bakePanorama(module, core, panorama);if (!made) return;+ this.panorama_ = panorama;this.adopt(core, made, key, now);}@@ -482,8 +489,9 @@ export class SkyEnvironment {return core.postprocess_takeSkyCapture!(ptr, bytes) ? core.HEAPU8.slice(ptr, ptr + bytes) : null;});if (!pixels) return;- const made = bakePanorama(module, core, decodeSkyCapture(pixels, CUSTOM_SKY_WIDTH, CUSTOM_SKY_HEIGHT));- if (made) this.adopt(core, made, `custom:${type}`, now);+ const panorama = decodeSkyCapture(pixels, CUSTOM_SKY_WIDTH, CUSTOM_SKY_HEIGHT);+ const made = bakePanorama(module, core, panorama);+ if (made) { this.panorama_ = panorama; this.adopt(core, made, `custom:${type}`, now); }return;}if (this.baked_ && this.key_ === `custom:${type}` && now - this.lastBake_ < this.minInterval) return;diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.tsindex 16c9b5cfc..f79a905f4 100644--- a/sdk/src/wasm.ts+++ b/sdk/src/wasm.ts@@ -560,6 +560,10 @@ export interface ESEngineModule {postprocess_setPassContinuesEffect(name: string): void;postprocess_requestSkyCapture?(passName: string, width: number, height: number): void;renderer_setWorldUnitsPerMeter?(units: number): void;+ renderer_requestProbeCapture?(x: number, y: number, z: number, face: number): void;+ renderer_pollProbeCapture?(): number;+ renderer_takeProbeCapture?(dst: number, bytes: number): boolean;+ renderer_setProbeVolumeOverride?(entity: number, volumeHandle: number): void;postprocess_pollSkyCapture?(): number;postprocess_takeSkyCapture?(dst: number, bytes: number): boolean;postprocess_setMsaaSamples(samples: number): void;diff --git a/sdk/src/wasm/ptrLayouts.generated.ts b/sdk/src/wasm/ptrLayouts.generated.tsindex 5dc860023..aac8fd5ab 100644--- a/sdk/src/wasm/ptrLayouts.generated.ts+++ b/sdk/src/wasm/ptrLayouts.generated.ts@@ -295,9 +295,11 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {ptrFn: 'getLightProbeVolumePtr',fields: [{ name: 'probes', type: 'u32', offset: 0 },- { name: 'halfExtents', type: 'vec3', offset: 4 },- { name: 'spacing', type: 'f32', offset: 16 },- { name: 'enabled', type: 'bool', offset: 20 },+ { name: 'capture', type: 'bool', offset: 4 },+ { name: 'captureInterval', type: 'f32', offset: 8 },+ { name: 'halfExtents', type: 'vec3', offset: 12 },+ { name: 'spacing', type: 'f32', offset: 24 },+ { name: 'enabled', type: 'bool', offset: 28 },],},MeshCollider3D: {diff --git a/sdk/src/wasm/wasm.generated.ts b/sdk/src/wasm/wasm.generated.tsindex 6fd643726..bd73e9f93 100644--- a/sdk/src/wasm/wasm.generated.ts+++ b/sdk/src/wasm/wasm.generated.ts@@ -716,6 +716,8 @@ export interface Light {export interface LightProbeVolume {probes: number;+ capture: boolean;+ captureInterval: number;halfExtents: Vec3;spacing: number;enabled: boolean;diff --git a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snapindex 377fcc03d..9d514277a 100644--- a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap+++ b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap@@ -579,6 +579,19 @@ exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapsho},},"LightProbeVolume": {+ "capture": {+ "tooltip": "Fill this box at run time from a capture at its centre (the room as lit now), not from a bake.",+ },+ "captureInterval": {+ "min": 0,+ "shownWhen": {+ "field": "capture",+ "values": [+ 1,+ ],+ },+ "tooltip": "Seconds between captures (0 = once). Each one adds a bounce.",+ },"halfExtents": {"min": 0,"tooltip": "Half the box this volume covers, from the entity's position.",diff --git a/sdk/tests/probe-capture.test.ts b/sdk/tests/probe-capture.test.tsnew file mode 100644index 000000000..6088cf871--- /dev/null+++ b/sdk/tests/probe-capture.test.ts@@ -0,0 +1,40 @@+import { describe, it, expect } from 'vitest';+import { capturePanorama } from '../src/postprocess/probeCapture';+import { projectIrradianceSH } from '../src/lightmap/environmentAtlas';+import { evalIrradianceSH } from '../src/lightmap/sh';++/** Six faces of `n` texels, +X -X +Y -Y +Z -Z side by side, each one RGBM colour (alpha 0 = nothing drawn). */+function faces(n: number, colours: Array<[number, number, number] | null>): Uint8Array {+ const out = new Uint8Array(n * 6 * n * 4);+ for (let row = 0; row < n; row++) {+ for (let f = 0; f < 6; f++) {+ const c = colours[f];+ for (let x = 0; x < n; x++) {+ const i = (row * n * 6 + f * n + x) * 4;+ if (!c) continue;+ // RGBM over 8 with m = 1/8: the colour itself, in range.+ out.set([c[0] * 255, c[1] * 255, c[2] * 255, 32], i);+ }+ }+ }+ return out;+}++describe('a probe capture read back', () => {+ it('puts each face where it looks: red at +X lights what faces +X red', () => {+ const pano = capturePanorama(faces(8, [[1, 0, 0], [0, 0, 1], [0, 1, 0], null, null, null]), 8, null);+ const sh = projectIrradianceSH(pano);+ const right = evalIrradianceSH(sh, 1, 0, 0), left = evalIrradianceSH(sh, -1, 0, 0), up = evalIrradianceSH(sh, 0, 1, 0);+ expect(right[0]).toBeGreaterThan(right[2]! * 3);+ expect(left[2]).toBeGreaterThan(left[0]! * 3);+ expect(up[1]).toBeGreaterThan(Math.max(up[0]!, up[2]!) * 2);+ });++ it('fills what nothing was drawn on from the sky', () => {+ const sky = { width: 4, height: 2, rgb: new Float32Array(4 * 2 * 3).fill(0.5) };+ const pano = capturePanorama(faces(8, [null, null, null, null, null, null]), 8, sky);+ expect(Math.min(...pano.rgb)).toBeCloseTo(0.5);+ const dark = capturePanorama(faces(8, [null, null, null, null, null, null]), 8, null);+ expect(Math.max(...dark.rgb)).toBe(0);+ });+});diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cppindex c3c6773fa..68941bdd1 100644--- a/src/esengine/bindings/EditorAPI.generated.cpp+++ b/src/esengine/bindings/EditorAPI.generated.cpp@@ -2,10 +2,10 @@* @file EditorAPI.generated.cpp* @brief Auto-generated editor API with string-dispatched component access* @details Generated by EHT - DO NOT EDIT- * @schema_hash 8ca490aabded77bf+ * @schema_hash 30b5f9a4fda7dda7*/-#define ES_EDITOR_API_SCHEMA_HASH "8ca490aabded77bf"+#define ES_EDITOR_API_SCHEMA_HASH "30b5f9a4fda7dda7"#include <emscripten/bind.h>#include <string>@@ -419,6 +419,8 @@ std::string editor_getComponentSchema(const std::string& name) {} else if (name == "LightProbeVolume") {return R"JSON([{"key":"probes","type":"asset","group":"LightProbeVolume"},+ {"key":"capture","type":"bool","group":"LightProbeVolume"},+ {"key":"captureInterval","type":"float","group":"LightProbeVolume"},{"key":"halfExtents.x","type":"float","group":"LightProbeVolume"},{"key":"halfExtents.y","type":"float","group":"LightProbeVolume"},{"key":"halfExtents.z","type":"float","group":"LightProbeVolume"},@@ -1596,7 +1598,8 @@ bool editor_setFloat(Registry& reg, u32 e, const std::string& comp, const std::s} else if (comp == "LightProbeVolume") {if (!reg.has<esengine::ecs::LightProbeVolume>(entity)) return false;auto& c = reg.get<esengine::ecs::LightProbeVolume>(entity);- if (field == "halfExtents.x") { c.halfExtents.x = value; }+ if (field == "captureInterval") { c.captureInterval = value; }+ else if (field == "halfExtents.x") { c.halfExtents.x = value; }else if (field == "halfExtents.y") { c.halfExtents.y = value; }else if (field == "halfExtents.z") { c.halfExtents.z = value; }else if (field == "spacing") { c.spacing = value; }@@ -2217,7 +2220,8 @@ f32 editor_getFloat(Registry& reg, u32 e, const std::string& comp, const std::st} else if (comp == "LightProbeVolume") {if (!reg.has<esengine::ecs::LightProbeVolume>(entity)) return 0.0f;const auto& c = reg.get<esengine::ecs::LightProbeVolume>(entity);- if (field == "halfExtents.x") { return c.halfExtents.x; }+ if (field == "captureInterval") { return c.captureInterval; }+ else if (field == "halfExtents.x") { return c.halfExtents.x; }else if (field == "halfExtents.y") { return c.halfExtents.y; }else if (field == "halfExtents.z") { return c.halfExtents.z; }else if (field == "spacing") { return c.spacing; }@@ -3286,7 +3290,8 @@ bool editor_setBool(Registry& reg, u32 e, const std::string& comp, const std::st} else if (comp == "LightProbeVolume") {if (!reg.has<esengine::ecs::LightProbeVolume>(entity)) return false;auto& c = reg.get<esengine::ecs::LightProbeVolume>(entity);- if (field == "enabled") { c.enabled = value; }+ if (field == "capture") { c.capture = value; }+ else if (field == "enabled") { c.enabled = value; }else { return false; }return true;} else if (comp == "MeshCollider3D") {@@ -3577,7 +3582,8 @@ bool editor_getBool(Registry& reg, u32 e, const std::string& comp, const std::st} else if (comp == "LightProbeVolume") {if (!reg.has<esengine::ecs::LightProbeVolume>(entity)) return false;const auto& c = reg.get<esengine::ecs::LightProbeVolume>(entity);- if (field == "enabled") { return c.enabled; }+ if (field == "capture") { return c.capture; }+ else if (field == "enabled") { return c.enabled; }} else if (comp == "MeshCollider3D") {if (!reg.has<esengine::ecs::MeshCollider3D>(entity)) return false;const auto& c = reg.get<esengine::ecs::MeshCollider3D>(entity);diff --git a/src/esengine/bindings/RendererBindings.cpp b/src/esengine/bindings/RendererBindings.cppindex 13e362f7c..0d9b2ee41 100644--- a/src/esengine/bindings/RendererBindings.cpp+++ b/src/esengine/bindings/RendererBindings.cpp@@ -1413,6 +1413,26 @@ void renderer_setLodPreview(u32 view, u32 entity, i32 level) {g_renderFrame->setLodPreview(view, Entity::fromRaw(entity), held);}+void renderer_requestProbeCapture(f32 x, f32 y, f32 z, u32 face) {+ if (g_renderFrame) g_renderFrame->requestProbeCapture({x, y, z}, face);+}++i32 renderer_pollProbeCapture() {+ return g_renderFrame ? g_renderFrame->pollProbeCapture() : 2;+}++bool renderer_takeProbeCapture(uintptr_t dst, u32 bytes) {+ if (!g_renderFrame || dst == 0) return false;+ const std::vector<u8>& px = g_renderFrame->probeCapturePixels();+ if (px.empty() || px.size() > bytes) return false;+ std::memcpy(reinterpret_cast<void*>(dst), px.data(), px.size());+ return true;+}++void renderer_setProbeVolumeOverride(u32 entity, u32 volumeHandle) {+ if (g_renderFrame) g_renderFrame->setProbeVolumeOverride(entity, resource::ProbeVolumeHandle(volumeHandle));+}+void renderer_setWorldUnitsPerMeter(f32 units) {if (g_renderFrame) g_renderFrame->setWorldUnitsPerMeter(units);}diff --git a/src/esengine/bindings/RendererBindings.hpp b/src/esengine/bindings/RendererBindings.hppindex 03dba42db..12cacc31a 100644--- a/src/esengine/bindings/RendererBindings.hpp+++ b/src/esengine/bindings/RendererBindings.hpp@@ -324,6 +324,15 @@ void renderer_setImpostorAtlas(u32 entity, u32 texture, u32 frames);*/std::string renderer_takeTextureWants();+/** Capture the scene around (x, y, z) into six face-pixel faces, one a frame (RenderFrame::requestProbeCapture). */+void renderer_requestProbeCapture(f32 x, f32 y, f32 z, u32 face);+/** 0 = not yet, 1 = ready to take, 2 = none asked for or it failed. Between frames only. */+i32 renderer_pollProbeCapture();+/** Copies the capture (six faces side by side, RGBM RGBA8, rows bottom-up) to @p dst; false when it does not fit or is not ready. */+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);+/** 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/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cppindex 50fcc4040..d0309fdf9 100644--- a/src/esengine/bindings/WebBindings.generated.cpp+++ b/src/esengine/bindings/WebBindings.generated.cpp@@ -762,6 +762,8 @@ LightJS lightToJS(const esengine::ecs::Light& c) {struct LightProbeVolumeJS {u32 probes;+ bool capture;+ f32 captureInterval;glm::vec3 halfExtents;f32 spacing;bool enabled;@@ -769,6 +771,8 @@ struct LightProbeVolumeJS {void lightprobevolumeApplyJS(esengine::ecs::LightProbeVolume& c, const LightProbeVolumeJS& js) {c.probes = resource::ProbeVolumeHandle(js.probes);+ c.capture = js.capture;+ c.captureInterval = js.captureInterval;c.halfExtents = js.halfExtents;c.spacing = js.spacing;c.enabled = js.enabled;@@ -783,6 +787,8 @@ esengine::ecs::LightProbeVolume lightprobevolumeFromJS(const LightProbeVolumeJS&LightProbeVolumeJS lightprobevolumeToJS(const esengine::ecs::LightProbeVolume& c) {LightProbeVolumeJS js;js.probes = c.probes.id();+ js.capture = c.capture;+ js.captureInterval = c.captureInterval;js.halfExtents = c.halfExtents;js.spacing = c.spacing;js.enabled = c.enabled;@@ -2078,6 +2084,8 @@ EMSCRIPTEN_BINDINGS(esengine_components) {value_object<LightProbeVolumeJS>("LightProbeVolume").field("probes", &LightProbeVolumeJS::probes)+ .field("capture", &LightProbeVolumeJS::capture)+ .field("captureInterval", &LightProbeVolumeJS::captureInterval).field("halfExtents", &LightProbeVolumeJS::halfExtents).field("spacing", &LightProbeVolumeJS::spacing).field("enabled", &LightProbeVolumeJS::enabled);@@ -4116,9 +4124,11 @@ static_assert(offsetof(esengine::ecs::Light, hemisphere) == 132, "ABI offset dristatic_assert(offsetof(esengine::ecs::Light, groundColor) == 136, "ABI offset drift: esengine::ecs::Light.groundColor (EHT expected 136)");static_assert(offsetof(esengine::ecs::Light, enabled) == 152, "ABI offset drift: esengine::ecs::Light.enabled (EHT expected 152)");static_assert(offsetof(esengine::ecs::LightProbeVolume, probes) == 0, "ABI offset drift: esengine::ecs::LightProbeVolume.probes (EHT expected 0)");-static_assert(offsetof(esengine::ecs::LightProbeVolume, halfExtents) == 4, "ABI offset drift: esengine::ecs::LightProbeVolume.halfExtents (EHT expected 4)");-static_assert(offsetof(esengine::ecs::LightProbeVolume, spacing) == 16, "ABI offset drift: esengine::ecs::LightProbeVolume.spacing (EHT expected 16)");-static_assert(offsetof(esengine::ecs::LightProbeVolume, enabled) == 20, "ABI offset drift: esengine::ecs::LightProbeVolume.enabled (EHT expected 20)");+static_assert(offsetof(esengine::ecs::LightProbeVolume, capture) == 4, "ABI offset drift: esengine::ecs::LightProbeVolume.capture (EHT expected 4)");+static_assert(offsetof(esengine::ecs::LightProbeVolume, captureInterval) == 8, "ABI offset drift: esengine::ecs::LightProbeVolume.captureInterval (EHT expected 8)");+static_assert(offsetof(esengine::ecs::LightProbeVolume, halfExtents) == 12, "ABI offset drift: esengine::ecs::LightProbeVolume.halfExtents (EHT expected 12)");+static_assert(offsetof(esengine::ecs::LightProbeVolume, spacing) == 24, "ABI offset drift: esengine::ecs::LightProbeVolume.spacing (EHT expected 24)");+static_assert(offsetof(esengine::ecs::LightProbeVolume, enabled) == 28, "ABI offset drift: esengine::ecs::LightProbeVolume.enabled (EHT expected 28)");static_assert(offsetof(esengine::ecs::MeshCollider3D, mesh) == 0, "ABI offset drift: esengine::ecs::MeshCollider3D.mesh (EHT expected 0)");static_assert(offsetof(esengine::ecs::MeshCollider3D, friction) == 4, "ABI offset drift: esengine::ecs::MeshCollider3D.friction (EHT expected 4)");static_assert(offsetof(esengine::ecs::MeshCollider3D, restitution) == 8, "ABI offset drift: esengine::ecs::MeshCollider3D.restitution (EHT expected 8)");@@ -4426,7 +4436,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif// ABI Hash -- runtime handshake against the SDK bundle// =============================================================================-static const char* kEsAbiLayoutHash = "04486d0b29ae33ae";+static const char* kEsAbiLayoutHash = "9b9790d2839bd020";std::string esengineGetAbiLayoutHash() {return std::string(kEsAbiLayoutHash);diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cppindex 1792e3fca..8378b04a2 100644--- a/src/esengine/bindings/WebSDKEntry.cpp+++ b/src/esengine/bindings/WebSDKEntry.cpp@@ -818,6 +818,10 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {emscripten::function("renderer_takeTextureWants", &esengine::renderer_takeTextureWants);emscripten::function("renderer_setViewShading", &esengine::renderer_setViewShading);emscripten::function("renderer_setWorldUnitsPerMeter", &esengine::renderer_setWorldUnitsPerMeter);+ emscripten::function("renderer_requestProbeCapture", &esengine::renderer_requestProbeCapture);+ emscripten::function("renderer_pollProbeCapture", &esengine::renderer_pollProbeCapture);+ emscripten::function("renderer_takeProbeCapture", &esengine::renderer_takeProbeCapture);+ emscripten::function("renderer_setProbeVolumeOverride", &esengine::renderer_setProbeVolumeOverride);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/data/shaders/blit.esshader b/src/esengine/data/shaders/blit.esshaderindex 4af7ca467..eb6feac48 100644--- a/src/esengine/data/shaders/blit.esshader+++ b/src/esengine/data/shaders/blit.esshader@@ -94,6 +94,16 @@ void main() {// back to when the frame took none is white, whose alpha is 1.fragColor = vec4(c.rgb, 0.5);return;+#endif+#ifdef ES_RGBM+ // A probe capture's face packed for an 8-bit readback: RGBM over 8. Alpha 0 is a pixel nothing was drawn on (the sky, which+ // post-processing paints), left for the reader to fill.+ if (c.a <= 0.001) { fragColor = vec4(0.0); return; }+ vec3 h = clamp(c.rgb, vec3(0.0), vec3(8.0));+ float m = clamp(max(max(h.r, h.g), max(h.b, 1e-6)) / 8.0, 1.0 / 255.0, 1.0);+ m = ceil(m * 255.0) / 255.0;+ fragColor = vec4(h / (m * 8.0), m);+ return;#endifc = vec4(c.rgb * exp2(u_time.z), c.a);#ifdef ES_TONEMAP@@ -186,6 +196,13 @@ fn displayLookup(c : vec3f) -> vec3f {#endif#ifdef ES_COPYreturn vec4f(c.rgb, 0.5);+#endif+#ifdef ES_RGBM+ if (c.a <= 0.001) { return vec4f(0.0); }+ let h = clamp(c.rgb, vec3f(0.0), vec3f(8.0));+ var m = clamp(max(max(h.r, h.g), max(h.b, 1e-6)) / 8.0, 1.0 / 255.0, 1.0);+ m = ceil(m * 255.0) / 255.0;+ return vec4f(h / (m * 8.0), m);#endifc = vec4f(c.rgb * exp2(tc.u_time.z), c.a);#ifdef ES_TONEMAPdiff --git a/src/esengine/ecs/components/Light.hpp b/src/esengine/ecs/components/Light.hppindex d6c503950..86b9f8e03 100644--- a/src/esengine/ecs/components/Light.hpp+++ b/src/esengine/ecs/components/Light.hpp@@ -283,6 +283,17 @@ struct LightProbeVolume {ES_PROPERTY(asset = probeVolume, tooltip="Baked probe grid (.esprobes) filling this box.")resource::ProbeVolumeHandle probes;+ /** @brief Fill the box at run time from what a camera at its centre sees, all round: the walls as the lights light+ * them now, the sky through the openings — Unreal's real-time Sky Light / Reflection Capture, and the interior+ * capture a hand-built renderer takes. One grid point for the whole box, read in place of @ref probes. */+ ES_PROPERTY(tooltip="Fill this box at run time from a capture at its centre (the room as lit now), not from a bake.")+ bool capture{false};++ /** @brief Seconds between captures; 0 captures once. Each lit view of the room includes the last capture's fill, so a+ * few captures are a few bounces. */+ ES_PROPERTY(min=0, shown_when=capture:true, tooltip="Seconds between captures (0 = once). Each one adds a bounce.")+ f32 captureInterval{0.0f};+/** @brief Half the box's size, in world units, from the entity's position. */ES_PROPERTY(min=0, tooltip="Half the box this volume covers, from the entity's position.")glm::vec3 halfExtents{100.0f, 100.0f, 100.0f};diff --git a/src/esengine/renderer/frame/PostProcessPipeline.cpp b/src/esengine/renderer/frame/PostProcessPipeline.cppindex 2a525a9a5..58af295d4 100644--- a/src/esengine/renderer/frame/PostProcessPipeline.cpp+++ b/src/esengine/renderer/frame/PostProcessPipeline.cpp@@ -253,6 +253,10 @@ void PostProcessPipeline::shutdown() {resourceManager_.releaseShader(exactCopyShader_);exactCopyShader_ = resource::ShaderHandle{};}+ if (rgbmShader_.isValid()) {+ resourceManager_.releaseShader(rgbmShader_);+ rgbmShader_ = resource::ShaderHandle{};+ }if (copyDepthShader_.isValid()) {resourceManager_.releaseShader(copyDepthShader_);copyDepthShader_ = resource::ShaderHandle{};@@ -632,6 +636,20 @@ PostProcessPipeline::TemporalState* PostProcessPipeline::prepareHistory(Temporalreturn &state;}+void PostProcessPipeline::encodeRgbm() {+ if (!rgbmShader_.isValid()) {+ rgbmShader_ = compileBlit({"ES_RGBM"});+ if (!rgbmShader_.isValid()) { ES_LOG_ERROR("PostProcessPipeline: the RGBM pack would not compile"); return; }+ }+ Shader* shader = resourceManager_.getShader(rgbmShader_);+ if (!shader) return;+ applyPassPipeline(*shader);+ if (shader->hasUniform("u_texture")) shader->setUniform("u_texture", 0);+ shader->commitParams();+ bindBlitInputs(rgbmShader_);+ drawScreenQuad();+}+void PostProcessPipeline::requestSkyCapture(const std::string& passName, u32 width, u32 height) {sky_capture_.pass = passName;sky_capture_.width = std::clamp(width, 4u, 512u);diff --git a/src/esengine/renderer/frame/PostProcessPipeline.hpp b/src/esengine/renderer/frame/PostProcessPipeline.hppindex 230e4a018..fa4993c54 100644--- a/src/esengine/renderer/frame/PostProcessPipeline.hpp+++ b/src/esengine/renderer/frame/PostProcessPipeline.hpp@@ -605,6 +605,9 @@ public:* frame is one write on WebGPU. A request while one is in flight replaces it.*/void requestSkyCapture(const std::string& passName, u32 width, u32 height);+ /** @brief Draws the texture on unit 0 into the bound target as RGBM over 8 (alpha 0 kept for nothing drawn): a probe+ * capture's face, packed for an 8-bit readback. Called inside a graph pass that reads that texture. */+ void encodeRgbm();/** @brief 0 = not yet, 1 = the pixels are ready (skyCapturePixels), 2 = none was asked for or it failed. Issues the* readback itself once the capture has been drawn, so call it between frames, never inside one. */i32 pollSkyCapture();@@ -759,6 +762,7 @@ private:std::vector<u8> pixels;};SkyCapture sky_capture_;+ resource::ShaderHandle rgbmShader_;bool cover_active_ = false;glm::mat4 cover_matrix_{1.0f};Unique<Framebuffer> velocity_fbo_;diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cppindex ce047f57e..0f8c770b2 100644--- a/src/esengine/renderer/frame/RenderFrame.cpp+++ b/src/esengine/renderer/frame/RenderFrame.cpp@@ -190,6 +190,7 @@ void RenderFrame::init(u32 width, u32 height) {velocity_pool_.init();cover_pool_.init();planar_pool_.init();+ probe_pool_.init();batch_shader_id_ = initBatchShader();RenderFrameContext initCtx{@@ -227,6 +228,11 @@ void RenderFrame::shutdown() {cover_frame_ubo_ = BufferHandle::Invalid;}planar_pool_.shutdown();+ probe_pool_.shutdown();+ if (probe_capture_.frameUbo != BufferHandle::Invalid) {+ device_.deleteBuffer(probe_capture_.frameUbo);+ probe_capture_.frameUbo = BufferHandle::Invalid;+ }releasePlanarCaptures();releaseShadowFrameUbos();releaseShadow2DResources();@@ -1529,7 +1535,10 @@ void RenderFrame::collectProbes(ecs::Registry& registry) {for (auto entity : view) {const auto& volume = view.get(entity);if (!volume.enabled) continue;- const ProbeVolume* grid = resource_manager_.getProbeVolume(volume.probes);+ // A volume filled at run time (a capture's grid) reads that instead of what it was baked with.+ const auto overridden = probe_overrides_.find(static_cast<u32>(entity));+ const ProbeVolume* grid = resource_manager_.getProbeVolume(+ overridden != probe_overrides_.end() ? overridden->second : volume.probes);if (!grid) continue;// The box is axis-aligned around the entity's world position: a grid was// solved on world axes, so a turned volume would be read along axes it@@ -2691,6 +2700,7 @@ void RenderFrame::collectAll(ecs::Registry& registry, bool sceneGBuffer) {{ ES_PROFILE_SCOPE("render.collect.shadow2dDeclare"); declareShadow2DPass(); }{ ES_PROFILE_SCOPE("render.collect.shape2dDeclare"); declareShape2DPass(); }{ ES_PROFILE_SCOPE("render.collect.planar"); declarePlanarReflection(registry); }+ { ES_PROFILE_SCOPE("render.collect.probeCapture"); declareProbeCapture(registry); }auto ctx = makeContext();#ifdef ES_ENABLE_POSTPROCESSdiff --git a/src/esengine/renderer/frame/RenderFrame.hpp b/src/esengine/renderer/frame/RenderFrame.hppindex 4b2d30da8..e2f3da407 100644--- a/src/esengine/renderer/frame/RenderFrame.hpp+++ b/src/esengine/renderer/frame/RenderFrame.hpp@@ -405,6 +405,18 @@ public:* window they are looking through.*/void setViewShading(u32 view, ShadingMode mode) { view_shading_.set(view, mode); }+ /**+ * @brief Capture the scene around @p position (world) into six @p face-pixel faces, one a frame, and read them back:+ * a probe volume filled at run time (RenderFrameProbeCapture.cpp). A request replaces one in flight.+ */+ void requestProbeCapture(const glm::vec3& position, u32 face);+ /** @brief 0 = not yet, 1 = ready (probeCapturePixels), 2 = none asked for or it failed. Between frames only. */+ i32 pollProbeCapture();+ /** @brief The six faces side by side, +X -X +Y -Y +Z -Z, RGBM over 8 in RGBA8 (alpha 0 = nothing drawn), rows bottom-up. */+ 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 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; }@@ -772,6 +784,24 @@ private:/** @brief Gathers the scene's reflection probes and binds the atlas they name. */void collectReflections(ecs::Registry& registry);void declarePlanarReflection(ecs::Registry& registry);+ void declareProbeCapture(ecs::Registry& registry);+ void executeProbeFace(ecs::Registry& registry);+ struct ProbeCapture {+ enum class State : u8 { Idle, Capturing, Drawn, Reading };+ State state = State::Idle;+ glm::vec3 position{0.0f};+ u32 face = 32;+ u32 next = 0;+ u64 frame = ~0ull;+ glm::mat4 viewProjection{1.0f};+ Unique<Framebuffer> faces[6];+ Unique<Framebuffer> atlas;+ BufferHandle frameUbo = BufferHandle::Invalid;+ ReadbackHandle readback = ReadbackHandle::Invalid;+ std::vector<u8> pixels;+ };+ ProbeCapture probe_capture_;+ std::unordered_map<u32, resource::ProbeVolumeHandle> probe_overrides_;void executePlanarReflection(ecs::Registry& registry, u32 view);struct PlanarCapture {Unique<Framebuffer> target;@@ -789,6 +819,8 @@ private:};std::unordered_map<u32, PlanarCapture> planar_captures_;TransientBufferPool planar_pool_{device_};+ TransientBufferPool probe_pool_{device_};+ DrawList probe_list_;f32 world_units_per_meter_ = 100.0f;/// The probe volumes' grids, packed for the per-pixel read (ProbeStore::layoutAtlas). Remade only when a grid/// or the set of grids changes, so a still scene uploads it once.diff --git a/src/esengine/renderer/frame/RenderFrameProbeCapture.cpp b/src/esengine/renderer/frame/RenderFrameProbeCapture.cppnew file mode 100644index 000000000..c9f5b3789--- /dev/null+++ b/src/esengine/renderer/frame/RenderFrameProbeCapture.cpp@@ -0,0 +1,167 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file RenderFrameProbeCapture.cpp+ * @brief The scene as seen from a point, all round, for a probe volume filled at run time.+ *+ * @details Six faces, one a frame: each is the scene collected and drawn from the point (as the planar reflection draws+ * it from a mirrored camera), lit as the frame lights it, with no post-processing, into a small target of its own;+ * then packed as RGBM into its slot of one 8-bit atlas the SDK reads back. One a frame because a frame writes its+ * transient vertices and its frame constants once: six faces in one frame would all draw what the last wrote.+ * A pixel nothing was drawn on (the sky, which post-processing paints) keeps alpha 0 for the reader to fill.+ */+#include "RenderFrame.hpp"+#ifdef ES_ENABLE_POSTPROCESS+#include "PostProcessPipeline.hpp"+#endif+#include "../../core/FrameProfiler.hpp"+#include "../../core/Log.hpp"++#include <glm/gtc/constants.hpp>+#include <glm/gtc/matrix_transform.hpp>++namespace esengine {++namespace {++// Toward each face, and its up: the SDK's probeCapture.ts builds the same bases to read the faces back.+constexpr glm::vec3 kFaceDir[6] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};+constexpr glm::vec3 kFaceUp[6] = {{0, 1, 0}, {0, 1, 0}, {0, 0, -1}, {0, 0, 1}, {0, 1, 0}, {0, 1, 0}};++} // namespace++void RenderFrame::requestProbeCapture(const glm::vec3& position, u32 face) {+ ProbeCapture& c = probe_capture_;+ c.position = position;+ c.face = std::clamp(face, 8u, 128u);+ c.next = 0;+ c.state = ProbeCapture::State::Capturing;+ c.readback = ReadbackHandle::Invalid;+}++i32 RenderFrame::pollProbeCapture() {+ ProbeCapture& c = probe_capture_;+ switch (c.state) {+ case ProbeCapture::State::Idle: return 2;+ case ProbeCapture::State::Capturing: return 0;+ case ProbeCapture::State::Drawn:+ c.readback = c.atlas ? device_.requestReadback(c.atlas->handle(), c.face * 6, c.face) : ReadbackHandle::Invalid;+ if (c.readback == ReadbackHandle::Invalid) { c.state = ProbeCapture::State::Idle; return 2; }+ c.state = ProbeCapture::State::Reading;+ [[fallthrough]];+ case ProbeCapture::State::Reading: {+ const GfxReadbackStatus status = device_.pollReadback(c.readback);+ if (status == GfxReadbackStatus::Pending) return 0;+ c.state = ProbeCapture::State::Idle;+ if (status != GfxReadbackStatus::Ready) return 2;+ c.pixels.resize(static_cast<usize>(c.face) * 6 * c.face * 4);+ return device_.takeReadback(c.readback, c.pixels.data(), c.pixels.size()) ? 1 : 2;+ }+ }+ return 2;+}++void RenderFrame::declareProbeCapture(ecs::Registry& registry) {+#ifdef ES_ENABLE_POSTPROCESS+ ProbeCapture& c = probe_capture_;+ // One face a frame, whichever camera's collect comes first.+ if (c.state != ProbeCapture::State::Capturing || c.frame == planar_frame_ || !post_process_) return;+ c.frame = planar_frame_;+ const u32 n = c.face;+ const GfxPixelFormat format = linear_color_ && device_.supportsFloatTargets() && !planar_float_refused_+ ? GfxPixelFormat::RGBA16F : GfxPixelFormat::RGBA8;+ const u32 f = c.next;+ auto& target = c.faces[f];+ if (!target || target->getWidth() != n || target->getSpecification().colorFormat != format) {+ FramebufferSpec spec;+ spec.width = n; spec.height = n; spec.linearFilter = false;+ spec.depthStencil = true; spec.colorFormat = format;+ target = Framebuffer::create(device_, spec);+ }+ if (!c.atlas || c.atlas->getWidth() != n * 6 || c.atlas->getHeight() != n) {+ FramebufferSpec spec;+ spec.width = n * 6; spec.height = n; spec.linearFilter = false;+ spec.depthStencil = false; spec.colorFormat = GfxPixelFormat::RGBA8;+ c.atlas = Framebuffer::create(device_, spec);+ }+ if (!target || !c.atlas) {+ ES_LOG_ERROR("Probe capture: could not make its {}x{} targets", n, n);+ c.state = ProbeCapture::State::Idle;+ return;+ }++ const f32 metre = world_units_per_meter_;+ const glm::vec3 at = rebased(c.position);+ c.viewProjection = glm::perspective(glm::half_pi<f32>(), 1.0f, 0.05f * metre, 4000.0f * metre)+ * glm::lookAt(at, at + kFaceDir[f], kFaceUp[f]);++ rg::PassDesc face;+ face.name = "probe-capture-face";+ face.write = graph_.importTarget(target->handle(), n, n, /*output=*/false, target->getColorAttachment());+ face.clear = face.clearDepth = true;+ for (u32 i = 0; i < 4; ++i) face.clearColor[i] = 0.0f;+ face.keep = true;+ if (shadow_resource_ != rg::kNoResource) face.dependencies.push_back(shadow_resource_);+ face.execute = [this, ®istry](const rg::PassContext&) { executeProbeFace(registry); };+ const rg::ResourceId faceResource = face.write;+ graph_.addPass(std::move(face));++ rg::PassDesc pack;+ pack.name = "probe-capture-pack";+ pack.reads = {faceResource};+ pack.write = graph_.importTarget(c.atlas->handle(), n * 6, n, /*output=*/false, c.atlas->getColorAttachment());+ pack.keep = true;+ pack.viewportX = f * n;+ pack.viewportY = 0;+ pack.viewportW = n;+ pack.viewportH = n;+ pack.execute = [this, f](const rg::PassContext&) {+ post_process_->encodeRgbm();+ if (f == 5) probe_capture_.state = ProbeCapture::State::Drawn;+ };+ graph_.addPass(std::move(pack));+ c.next = f + 1;+#else+ (void)registry;+#endif+}++void RenderFrame::executeProbeFace(ecs::Registry& registry) {+ ProbeCapture& c = probe_capture_;+ if (c.frameUbo == BufferHandle::Invalid) {+ c.frameUbo = device_.createBuffer({GfxBufferUsage::Uniform, RenderContext::frameConstantsSize(), true},+ GfxContent::transient(), nullptr);+ }+ if (c.frameUbo == BufferHandle::Invalid) return;+ probe_pool_.beginFrame();+ probe_list_.clear();+ probe_list_.setCullingMask(0xFFFFFFFFu);+ probe_list_.setDepthMask(draw_list_.depthMask());+ probe_list_.setYSortMask(draw_list_.ySortMask());+ auto ctx = makeContext();+ ctx.view_projection = c.viewProjection;+ Frustum frustum;+ frustum.extractFromMatrix(ctx.view_projection);+ RenderCollectContext collect{registry, frustum, clip_state_, probe_pool_, probe_list_, ctx,+ computeCameraView(ctx.view_projection)};+ collect.screen_ui = screen_domain_;+ collect.ui_tree_layers = ui_tree_layers_;+ collectSky(collect);+ // The scene as lit, and nothing after it: no post-processing, overlays or HUD.+ for (auto& plugin : plugins_) plugin->collect(collect);+ probe_list_.finalize(probe_pool_);+ probe_pool_.upload();+ context_.useFrameConstants(c.frameUbo, toClipDepthRange(c.viewProjection, device_.clipDepthRange()));+ // The lights as the frame packed them; a light past the sixteen direct slots keeps the main view's tiles.+ context_.lights().uploadAndBind();+ submitColorList(probe_list_, probe_pool_, nullptr, DrawList::Phase::All, "render.probe.draws");+ ES_PROFILE_COUNTER("render.probe.draws", probe_list_.mergedDrawCallCount());+ device_.invalidatePipelineCache();+}++void RenderFrame::setProbeVolumeOverride(u32 entity, resource::ProbeVolumeHandle grid) {+ if (grid.isValid()) probe_overrides_[entity] = grid;+ else probe_overrides_.erase(entity);+}++} // namespace esenginediff --git a/src/esengine/renderer/rhi/ShaderEmbeds.generated.hpp b/src/esengine/renderer/rhi/ShaderEmbeds.generated.hppindex 9f73e81c3..27bb40310 100644--- a/src/esengine/renderer/rhi/ShaderEmbeds.generated.hpp+++ b/src/esengine/renderer/rhi/ShaderEmbeds.generated.hpp@@ -363,6 +363,16 @@ void main() {fragColor = vec4(c.rgb, 0.5);return;+#endif+#ifdef ES_RGBM+++ if (c.a <= 0.001) { fragColor = vec4(0.0); return; }+ vec3 h = clamp(c.rgb, vec3(0.0), vec3(8.0));+ float m = clamp(max(max(h.r, h.g), max(h.b, 1e-6)) / 8.0, 1.0 / 255.0, 1.0);+ m = ceil(m * 255.0) / 255.0;+ fragColor = vec4(h / (m * 8.0), m);+ return;#endifc = vec4(c.rgb * exp2(u_time.z), c.a);#ifdef ES_TONEMAP@@ -455,6 +465,13 @@ fn displayLookup(c : vec3f) -> vec3f {#endif#ifdef ES_COPYreturn vec4f(c.rgb, 0.5);+#endif+#ifdef ES_RGBM+ if (c.a <= 0.001) { return vec4f(0.0); }+ let h = clamp(c.rgb, vec3f(0.0), vec3f(8.0));+ var m = clamp(max(max(h.r, h.g), max(h.b, 1e-6)) / 8.0, 1.0 / 255.0, 1.0);+ m = ceil(m * 255.0) / 255.0;+ return vec4f(h / (m * 8.0), m);#endifc = vec4f(c.rgb * exp2(tc.u_time.z), c.a);#ifdef ES_TONEMAPdiff --git a/tests/aot/generated/conformance/handshake.h b/tests/aot/generated/conformance/handshake.hindex 5edaee3c6..b632e788a 100644--- a/tests/aot/generated/conformance/handshake.h+++ b/tests/aot/generated/conformance/handshake.h@@ -1,5 +1,5 @@/* GENERATED by sdk/tests/aot-conformance.test.ts — do not edit. *//* The contract half of the handshake. The width half is the harness. */-#define ES_CONF_EXPECTED_CONTRACT_HASH 0xfbd6360662f44589ULL+#define ES_CONF_EXPECTED_CONTRACT_HASH 0xfc7cc108e24537d9ULL/* And which BUILD the artifact beside this one is. */#define ES_CONF_EXPECTED_MODULE_CONTRACT 0xc3d0e057d5701a2eULLdiff --git a/tests/aot/generated/conformance/systems_decl.c b/tests/aot/generated/conformance/systems_decl.cindex fd41e38af..b84807bae 100644--- a/tests/aot/generated/conformance/systems_decl.c+++ b/tests/aot/generated/conformance/systems_decl.c@@ -10,7 +10,7 @@answer, it is a read of a different field. The address width belongsto the MACHINE, so it mixes in here rather than in the compiler and a32-bit artifact cannot load into a 64-bit host. */-#define ES_ABI_ENGINE_DIGEST 0xfbd6360662f44589ULL+#define ES_ABI_ENGINE_DIGEST 0xfc7cc108e24537d9ULLES_EXPORT const uint64_t es_abi_hash =ES_ABI_ENGINE_DIGEST ^ (0x9e3779b97f4a7c15ULL * (uint64_t)sizeof(es_addr_t));diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjsindex e871ee96c..bd3a70e6e 100644--- a/tools/renderScenes.mjs+++ b/tools/renderScenes.mjs@@ -920,6 +920,10 @@ export const SCENES = [// An inverse-square lamp (0.5) 1 m over a white floor, seen from above: 0.5 under it, 0.5 x cos45 / 2 one metre out,// 0.5 x 0.45 / 5 two metres out (0.5, 0.177, 0.045 linear) — the pool a real lamp throws; the ramp falls off far more gently.{ id: "point-inverse-square", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/point-inverse-square.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-backface.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[187,187,187],\"tol\":8},{\"x\":0.667,\"y\":0.5,\"rgb\":[117,117,117],\"tol\":8},{\"x\":0.833,\"y\":0.5,\"rgb\":[58,58,58],\"tol\":8}]" } },+ // 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: "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