@photivra/engine 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +92 -1
- package/CITATION.cff +1 -1
- package/README.md +6 -6
- package/SECURITY.md +1 -1
- package/dist/core/version.d.ts +1 -1
- package/dist/core/version.js +1 -1
- package/dist/core/version.js.map +1 -1
- package/dist/facade/chart-radiance-batch.js +3 -2
- package/dist/facade/chart-radiance-batch.js.map +1 -1
- package/dist/facade/chart-scenes.d.ts +2 -0
- package/dist/facade/chart-scenes.js +4 -3
- package/dist/facade/chart-scenes.js.map +1 -1
- package/dist/facade/display-view.d.ts +5 -0
- package/dist/facade/display-view.js +134 -52
- package/dist/facade/display-view.js.map +1 -1
- package/dist/facade/scene-radiance.d.ts +38 -5
- package/dist/facade/scene-radiance.js +79 -23
- package/dist/facade/scene-radiance.js.map +1 -1
- package/dist/facade/simulate-capture.d.ts +14 -6
- package/dist/facade/simulate-capture.js +19 -7
- package/dist/facade/simulate-capture.js.map +1 -1
- package/dist/facade/simulate-display-view.d.ts +24 -0
- package/dist/facade/simulate-display-view.js +101 -55
- package/dist/facade/simulate-display-view.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/API_REFERENCE.md +7 -1
- package/docs/QUICK_START.md +48 -0
- package/docs/api/core-version.md +1 -1
- package/docs/api/exports.json +32 -2
- package/docs/api/facade-scene-radiance.md +34 -1
- package/docs/api/facade-simulate-capture.md +1 -1
- package/docs/api/facade-simulate-display-view.md +39 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,97 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 2.
|
|
3
|
+
## 2.7.0 — unreleased (prepared October 24, 2026)
|
|
4
|
+
|
|
5
|
+
A minor release that makes the display view much faster at device-pixel sizes and adds two APIs for it.
|
|
6
|
+
- **API for regions:** `prepareDisplayView` resolves a request once for many regions.
|
|
7
|
+
- **API for charts:** caller material scenes let a piecewise-constant scene, such as a chart with a printed label, take the chart path.
|
|
8
|
+
- **Faster, same output:** three speed-ups change no byte of any result: the scene illuminant evaluated once per wavelength, a sample's terms reused per real pixel, and site values kept across display pixels.
|
|
9
|
+
- **Compatibility:** every request that 2.6.0 accepted gives byte-identical results (the engine version recorded in results aside). Root exports grow from 1,721 to 1,727; none is removed.
|
|
10
|
+
- **Known limit:** the Quality noise limit of 2.6.0 remains, and its fix moves to 2.8.0.
|
|
11
|
+
|
|
12
|
+
Measured on the app's All-in-one chart with its maker label (24 MP frame, the 2028 × 1352 view's centre strip, one thread, Speed), using the material scene: 1.15 s instead of 15 s on 2.6.0. With the Quality options it takes 3.0 s instead of 180 s.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- **Prepared display view: many regions of one view from one setup (#387).**
|
|
17
|
+
- **The problem:** each `simulateDisplayView` call repeated the request's setup, so a caller rendering one view in many regions (progressive display on several workers, centre first) paid it once per region. The setup is request validation; the camera, lens, scene, chart and illuminant; the channel responses through the environment chain; the diffraction kernels, readout moments, demosaic tables and colour matrix.
|
|
18
|
+
- **The new API:** `prepareDisplayView(options)` resolves the request once and returns a handle. Its `render(view, { signal })` returns what `simulateDisplayView(options, view)` returns, byte for byte: samples, view, exposure, scene, diagnostics and assumptions. Only `diagnostics.timingsMs` differ, and they cover the render only.
|
|
19
|
+
- **Behaviour:** renders may run concurrently and share only read-only setup. Each render has its own expected-signal caches, lookup count and assumptions, and its own abort signal.
|
|
20
|
+
- **Measured** on the app's 24 MP request, one thread, 8 × 8 regions of the 2028 × 1352 view, four in a row:
|
|
21
|
+
|
|
22
|
+
| Request | Separate calls | Prepared |
|
|
23
|
+
| --- | --- | --- |
|
|
24
|
+
| Chart preset, defaults | 0.26–0.41 s each | 0.25 s once, then 6–7 ms per region |
|
|
25
|
+
| Caller scene, defaults | 0.24–0.43 s each | 0.21 s once, then 17–42 ms per region |
|
|
26
|
+
| Chart preset, with diffraction, four-spot filter and AHD | 0.73–0.79 s each | 0.69 s once, then 34–66 ms per region |
|
|
27
|
+
| Caller scene, with the same options | 1.27–1.52 s each | 0.73 s once, then 0.68–0.75 s per region (its own diffraction work) |
|
|
28
|
+
|
|
29
|
+
- **Exports:** `prepareDisplayView`, `PreparedDisplayView` and `PreparedDisplayViewRenderOptions`; root exports grow from 1,721 to 1,724. A test renders whole views and regions through a prepared view, concurrently too, for Speed, Quality and a caller scene, and compares them with separate calls. See the quick start, "Display view".
|
|
30
|
+
|
|
31
|
+
- **Caller material scenes (#386).**
|
|
32
|
+
- **The new scene form:** `{ kind: "material-function", sceneId, materials, materialAt }` is a third caller scene form. It is for piecewise-constant scenes such as a chart with a printed label. `materials` lists reflectances as chart patches take them: neutral numbers or reflectance spectra covering 380–780 nm, at most `CALLER_MATERIAL_SCENE_MAX_MATERIALS` (65,536). `materialAt` receives the plane point without a wavelength (`SceneMaterialPoint`: `xM`, `yM`, `u`, `v`, and `chartU`, `chartV` on a fixed-size chart) and returns a material index. An index outside the list is an `InvalidConfigurationError`.
|
|
33
|
+
- **Captures and ideal references:** the radiance at a point is the material's, in the chart's expression order, so they are byte-identical to the same scene as a reflectance function. Tested in Speed and with diffraction and AHD.
|
|
34
|
+
- **Display view:** it takes the chart presets' material path, with each material tabulated once per spectral node and one lookup per lattice point. A material scene that reproduces a preset gives the preset's bytes, expected values and lookup count. Against the reflectance-function form, the same quantities are summed in another order:
|
|
35
|
+
- expected values agree within 1e-12 relative (tested);
|
|
36
|
+
- on whole views of the app's chart with its maker label (24 MP frame, Speed), 0 of 523,776 samples differ at 512 × 341 and 0 of 2,281,248 at 1068 × 712, with the largest |Δ| in the expected linear values 3.7 × 10⁻¹⁵.
|
|
37
|
+
- **Scene digest:** the materials enter `scene.sourceSha256`. The `materialAt` body does not, as for the other caller functions.
|
|
38
|
+
- **Measured** on the 2028 × 1352 view's centre strip, one thread:
|
|
39
|
+
|
|
40
|
+
| App's chart with its maker label | Reflectance function | Material scene | Chart preset (no label) |
|
|
41
|
+
| --- | --- | --- | --- |
|
|
42
|
+
| Defaults | 3.2 s | 1.15 s | 1.1 s |
|
|
43
|
+
| Diffraction, four-spot filter, AHD | 111 s | 3.0 s | 2.6 s |
|
|
44
|
+
|
|
45
|
+
- **Exports:** `CallerMaterialScene`, `SceneMaterialPoint` and `CALLER_MATERIAL_SCENE_MAX_MATERIALS`; root exports grow from 1,724 to 1,727. See the quick start, "Piecewise-constant scenes (2.7)".
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
|
|
49
|
+
- **Display view without diffraction: site values are kept across neighbouring display pixels (#392).**
|
|
50
|
+
- **What changed:** each display pixel opens a cache window of its footprint plus the demosaic reach. Neighbouring windows overlap, so the same native sites were evaluated about 3.7 times (measured at 2028 wide on a 24 MP frame). Without diffraction the view now keeps site values in a ring of native rows, a power of two at least twice the window's height, as the filled chart path already did with diffraction.
|
|
51
|
+
- **Exactness:** a site's value does not depend on the window, and a ring hit adds to `sceneLookups` the lookups the site's evaluation would have made. So samples, expected values, noise and every diagnostic are unchanged. The hash locks and the same 120 views as above hash identically.
|
|
52
|
+
- **Measured** on the same strip, Speed (one thread):
|
|
53
|
+
|
|
54
|
+
| Request | Before (after the memo above) | After |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| Caller `reflectance-function` scene | 12.5 / 13.4 s | 3.0 / 3.0 s (4.3×) |
|
|
57
|
+
| Chart preset | 1.2 / 1.3 s | 1.0 / 1.0 s |
|
|
58
|
+
|
|
59
|
+
With the illuminant table, the memo and this change together, the caller-scene strip takes 3.1–3.6 s instead of 14.0–15.2 s on 2.6.0, and the chart preset 1.0 s instead of 2.1–2.5 s.
|
|
60
|
+
|
|
61
|
+
- **Display view: a sample's terms are reused for later samples of the same real pixel (#392).**
|
|
62
|
+
- **What changed:** at device-pixel view sizes a display pixel covers a few real pixels, and its 256 samples land on each of them many times. A sample's recorded terms depend only on its real pixel, not on the display pixel or the sample: the site variances, candidate slopes, residuals, expected values, the AHD choice terms and the correction. The view now keeps them per real pixel of the display pixel's footprint and replays them for later samples, as the one-material memo already did.
|
|
63
|
+
- **Exactness:** the replay adds the same values to the same sums in the same order. It is used only where every site of the sample lies in the window's site cache, where reading the sites again cost no work and no scene lookup. So samples, expected values, noise and diagnostics, `sceneLookups` and `siteEvaluations` included, are unchanged:
|
|
64
|
+
- the six hash locks, and two new locks for views barely smaller than the frame, recorded on 2.6.0 before the change;
|
|
65
|
+
- 120 further views hashed identically before and after (6, 3.76 and 1.4 µm; five charts and a caller scene; Speed and Quality; 20–90 % of the frame width; ISO 100 and 3200).
|
|
66
|
+
- **Measured** on the same strip as above (one thread, before and after on the same build otherwise):
|
|
67
|
+
|
|
68
|
+
| Request | Before | After |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| Chart preset, defaults | 2.1 / 2.2 s | 1.2 / 1.3 s (1.8×) |
|
|
71
|
+
| Chart preset, with diffraction, four-spot filter and AHD | 7.7 / 7.6 s | 3.0 / 2.9 s (2.6×) |
|
|
72
|
+
| Caller `reflectance-function` scene, defaults | 14.0 / 14.6 s | 12.5 / 13.4 s (1.1×) |
|
|
73
|
+
| Same, with diffraction, four-spot filter and AHD | 185 s | 174 s (1.06×) |
|
|
74
|
+
|
|
75
|
+
Caller scenes gain little because their time goes on evaluating each site the first time; reusing site values across neighbouring display pixels is the next step of #392.
|
|
76
|
+
|
|
77
|
+
- **Scene illuminant evaluated once per wavelength (#385).**
|
|
78
|
+
- **What changed:** the planar scene provider (chart and caller scenes, in captures and display views) and the batched chart radiance used to evaluate the illuminant's spectrum on every scene lookup. That is Planck's law, CIE A or the daylight locus: two transcendental evaluations per call. They now keep it in a table per distinct wavelength, filled with the same call.
|
|
79
|
+
- **Results are unchanged:** a prepared spectrum is a pure function of the wavelength, so the table returns the same double and the product keeps its order, `value × irradianceScale × shape / π`. Display views, captures, hash locks and fingerprints are byte-identical. The table lives in each provider (one per call), up to 4,096 wavelengths.
|
|
80
|
+
- **Measured** on a 24 MP full frame (6000 × 4000 at 6 µm), f/8, a composite chart with a 2 × 2 box, on the 2028 × 1352 view's 8-row centre strip. One thread, 4-vCPU Linux container, Node 24.21.0, two runs each, same sample hashes before and after:
|
|
81
|
+
|
|
82
|
+
| Request | Before | After |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| Caller `reflectance-function` scene, defaults | 15.0 / 15.2 s | 8.8 / 8.5 s (1.75×) |
|
|
85
|
+
| Same, with diffraction, four-spot filter and AHD | 185 / 174 s | 113 / 116 s (1.56×) |
|
|
86
|
+
| Chart preset, defaults | 2.2 / 2.5 s | 2.2 / 2.0 s |
|
|
87
|
+
| Chart preset, with diffraction, four-spot filter and AHD | 7.9 / 8.9 s | 7.4 / 7.6 s |
|
|
88
|
+
| 128 × 128 capture region, caller scene / chart | 4.9 / 3.2 s | 4.7 / 3.0 s |
|
|
89
|
+
|
|
90
|
+
### Known limit
|
|
91
|
+
|
|
92
|
+
- **Display view, Quality (AHD): too much colour in the noise where a display pixel covers few sensor pixels (#379).** This is unchanged from 2.6.0 (see its entry below). By the owner's decision of October 24, 2026 ("Ship speed now, #379 in 2.8.0"), the redesign of the Quality noise model moves to 2.8.0. Speed (bilinear) is exact.
|
|
93
|
+
|
|
94
|
+
## 2.6.0 — published October 20, 2026
|
|
4
95
|
|
|
5
96
|
A minor release that adds the display view and the close-up light factor and makes Quality renders faster. `simulateDisplayView` gives the image the real full-resolution capture would give after resizing to a display size, without rendering it at full resolution; region renders with diffraction convolve only the region, identical diffraction kernels are reused and built faster, the engine's own chart scenes skip re-parsing their fixed records, and the framing results report how much light the lens loses up close. Applications that only capture do not bundle the display view. Every capture and ideal-reference request that 2.5.0 accepted gives byte-identical results (the engine version recorded in captures aside), except that region renders with diffraction state the narrower convolution in their `output.region` assumption; their samples, RAW codes and files are unchanged. `calculateChartFraming` and `calculateSubjectDistanceForFraming` results gain two fields. Root exports grow from 1,717 to 1,721 symbols; none is removed. The display view with the Quality options has one known limit, listed below.
|
|
6
97
|
|
package/CITATION.cff
CHANGED
|
@@ -9,7 +9,7 @@ abstract: "An open TypeScript engine for the science and mathematics of photogra
|
|
|
9
9
|
repository-code: "https://github.com/photivra/photivra"
|
|
10
10
|
url: "https://photivra.com"
|
|
11
11
|
license: "Apache-2.0"
|
|
12
|
-
version: "2.
|
|
12
|
+
version: "2.7.0"
|
|
13
13
|
keywords:
|
|
14
14
|
- photography
|
|
15
15
|
- camera optics
|
package/README.md
CHANGED
|
@@ -32,10 +32,10 @@ The source is licensed under Apache-2.0.
|
|
|
32
32
|
|
|
33
33
|
## Quick start
|
|
34
34
|
|
|
35
|
-
Install the published ESM package below. The [2.
|
|
35
|
+
Install the published ESM package below. The [2.7.0 release record](https://github.com/Photivra/photivra/blob/main/docs/RELEASE_2_7_0.md) and [changelog](https://github.com/Photivra/photivra/blob/main/CHANGELOG.md) describe the current release:
|
|
36
36
|
|
|
37
37
|
```sh
|
|
38
|
-
npm install @photivra/engine@2.
|
|
38
|
+
npm install @photivra/engine@2.7.0
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
Simulate a photograph of a test chart with a generic camera, then read the developed sRGB pixels:
|
|
@@ -75,7 +75,7 @@ console.log(horizontal.provenance);
|
|
|
75
75
|
|
|
76
76
|
Start with the [Developer Guide](https://github.com/Photivra/photivra/blob/main/docs/DEVELOPERS.md). Then use the [Usage Guide](https://github.com/Photivra/photivra/blob/main/docs/USAGE.md) and the [API reference](https://github.com/Photivra/photivra/blob/main/docs/API_REFERENCE.md), which is generated from the package exports.
|
|
77
77
|
|
|
78
|
-
Repository `main` may describe newer, unreleased work. For the stable contract, use the docs bundled in the published package, or the exact `v2.
|
|
78
|
+
Repository `main` may describe newer, unreleased work. For the stable contract, use the docs bundled in the published package, or the exact `v2.7.0` tag.
|
|
79
79
|
|
|
80
80
|
## Documentation
|
|
81
81
|
|
|
@@ -363,13 +363,13 @@ The application can then use those results, while the photography calculations t
|
|
|
363
363
|
|
|
364
364
|
## Status
|
|
365
365
|
|
|
366
|
-
- Repository package version: `2.
|
|
367
|
-
- Engine API contract: `2.
|
|
366
|
+
- Repository package version: `2.7.0` (release candidate prepared October 24, 2026; publication is separate)
|
|
367
|
+
- Engine API contract: `2.7.0`
|
|
368
368
|
- Versioned generic tier reference assets: [GENERIC_TIER_PRESETS.md](https://github.com/Photivra/photivra/blob/main/docs/GENERIC_TIER_PRESETS.md).
|
|
369
369
|
- Composed POC simulation API contract: `1.0.0`
|
|
370
370
|
- Stability: 1.0 root-package compatibility policy; bounded scientific models and independent POC contract
|
|
371
371
|
|
|
372
|
-
From 1.0.1, the package version and `ENGINE_API_VERSION` are equal. New captures/plans record 2.
|
|
372
|
+
From 1.0.1, the package version and `ENGINE_API_VERSION` are equal. New captures/plans record 2.7.0; existing archives keep their original creator identities. Schema, model and POC contract versions stay independent.
|
|
373
373
|
|
|
374
374
|
A breaking change to the root contracts now needs a new package major version. Additive and corrective changes follow [compatibility and migration](https://github.com/Photivra/photivra/blob/main/docs/RELEASE_1_3_0.md). A 1.0 package is not a claim of calibrated physical accuracy.
|
|
375
375
|
|
package/SECURITY.md
CHANGED
|
@@ -4,7 +4,7 @@ Please do not open a public issue that contains vulnerability details.
|
|
|
4
4
|
|
|
5
5
|
## Supported versions
|
|
6
6
|
|
|
7
|
-
The published 1.0.0 release started the 1.x root-package compatibility line, and 2.0.0 started the 2.x line. The current release is **2.
|
|
7
|
+
The published 1.0.0 release started the 1.x root-package compatibility line, and 2.0.0 started the 2.x line. The current release is **2.6.0**, published on October 20, 2026 (see [CHANGELOG.md](CHANGELOG.md)).
|
|
8
8
|
|
|
9
9
|
Security fixes target the current maintained development and release line. Do not assume that older 1.x releases, snapshots or pre-1.0 releases will receive fixes.
|
|
10
10
|
|
package/dist/core/version.d.ts
CHANGED
package/dist/core/version.js
CHANGED
package/dist/core/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/core/version.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAgB,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Version of the engine release. Since 1.0.1 it equals the npm package version.\n *\n * New captures and plans record this version as their creator. Archived records keep the\n * version they were made with. Proof-of-concept (POC), schema and model contracts have their\n * own versions. Release checks confirm it matches package.json and the packed package.\n * @see docs/RELEASE_1_0_1.md\n */\nexport const ENGINE_API_VERSION = \"2.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/core/version.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAgB,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Version of the engine release. Since 1.0.1 it equals the npm package version.\n *\n * New captures and plans record this version as their creator. Archived records keep the\n * version they were made with. Proof-of-concept (POC), schema and model contracts have their\n * own versions. Release checks confirm it matches package.json and the packed package.\n * @see docs/RELEASE_1_0_1.md\n */\nexport const ENGINE_API_VERSION = \"2.7.0\" as const;\n"]}
|
|
@@ -19,7 +19,7 @@ import { InvalidConfigurationError } from "../core/configuration-error.js";
|
|
|
19
19
|
import { requireAllowlistedRecord } from "../core/record-validation.js";
|
|
20
20
|
import { FULL_RESOLUTION_CEILING_PIXELS, resolveRaisedLimit } from "../core/pixel-limits.js";
|
|
21
21
|
import { resolveChartScene } from "./chart-scenes.js";
|
|
22
|
-
import { buildPlanarSceneRadianceProvider, calculateIlluminantIrradianceScale, resolveCaptureIlluminant } from "./scene-radiance.js";
|
|
22
|
+
import { buildPlanarSceneRadianceProvider, calculateIlluminantIrradianceScale, resolveCaptureIlluminant, tabulatedSpectrum } from "./scene-radiance.js";
|
|
23
23
|
export const CHART_RADIANCE_BATCH_SCHEMA_VERSION = "0.1.0";
|
|
24
24
|
/** `maximumQueries` is the default batch limit; a request may raise it with its own `maximumQueries`, up to `ceilingQueries`. */
|
|
25
25
|
export const CHART_RADIANCE_BATCH_LIMITS = Object.freeze({ maximumQueries: 24_000_000, ceilingQueries: FULL_RESOLUTION_CEILING_PIXELS, maximumWavelengths: 256,
|
|
@@ -67,12 +67,13 @@ export function calculateChartRadianceBatchPlan(input) {
|
|
|
67
67
|
irradianceScale, geometry: { distanceM: 1, metresPerFrameUnit: 1 }, evidence: [], limitations: [] });
|
|
68
68
|
const channelWeights = weights === undefined ? null : weights.map(row => Object.freeze([...row]));
|
|
69
69
|
const nm = Object.freeze([...wavelengths]);
|
|
70
|
+
const shapeAt = tabulatedSpectrum(illuminant.shape);
|
|
70
71
|
const materialRadiance = (material, wavelength) => {
|
|
71
72
|
const m = chart.materials[material];
|
|
72
73
|
const reflectance = m.kind === "neutral" ? m.reflectance : m.spectrum.evaluate(wavelength);
|
|
73
74
|
if (m.kind === "spectrum" && !(reflectance >= 0 && reflectance <= 1))
|
|
74
75
|
throw new InvalidConfigurationError("Chart reflectance spectrum left [0, 1].");
|
|
75
|
-
return reflectance * irradianceScale *
|
|
76
|
+
return reflectance * irradianceScale * shapeAt(wavelength) / Math.PI;
|
|
76
77
|
};
|
|
77
78
|
return Object.freeze({ chart, illuminant, irradianceScale, queryCount, columns: channelWeights === null ? 1 : channelWeights.length,
|
|
78
79
|
mode: channelWeights === null ? "radiance" : "spectral-integral", wavelengthsNanometers: nm, channelWeights, materialRadiance,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-radiance-batch.js","sourceRoot":"","sources":["../../src/facade/chart-radiance-batch.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAA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,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAE,CAAC;QAC1B,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAAE,MAAM,IAAI,yBAAyB,CAAC,2DAA2D,CAAC,CAAC;QAChH,MAAM,CAAC,GAAG,QAAQ,GAAG,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAE,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;QACjE,sGAAsG;QACtG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;YAAE,MAAM,IAAI,yBAAyB,CAAC,wFAAwF,CAAC,CAAC;QAC9K,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QAClB,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Batched radiance queries for the engine's procedural chart scenes (#277): many frame points in one\n * call, each answered with spectral radiance at a declared wavelength, or with the spectral integral of\n * that radiance against declared channel weights. This is the float64 CPU reference for the\n * `webgpu-f32` chart-radiance stage (`ImageKernelAccelerator.evaluateChartRadiance`).\n *\n * Every value comes from the chart provider's own `radianceAt` (createPlanarSceneRadianceProvider): a\n * Lambertian reflectance ρ(λ) under the scaled illuminant, L = ρ·k·S(λ)/π. The spectral integral of a\n * query is Σ_j w_cj·L(u, v, λ_j), summed in wavelength order. Charts are uniform-illuminant Lambertian\n * patterns, so a query's integral depends only on its material: the GPU stage uses exactly that.\n *\n * The query shape mirrors a batched provider (one call, queries in, results in the same order). Points\n * are frame units (u right, v up; see chart-scenes.ts); `mapEnvironmentDirectionsToChartPoints` converts\n * environment-direction queries exactly as `evaluateRadiance` does.\n * @see docs/WEBGPU.md, \"Scene radiance on the GPU\".\n */\n\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { requireAllowlistedRecord } from \"../core/record-validation.js\";\nimport { FULL_RESOLUTION_CEILING_PIXELS, resolveRaisedLimit } from \"../core/pixel-limits.js\";\nimport { resolveChartScene, type ChartScene, type ResolvedChartScene } from \"./chart-scenes.js\";\nimport { buildPlanarSceneRadianceProvider, calculateIlluminantIrradianceScale, resolveCaptureIlluminant, type CaptureIlluminant,\n type ResolvedCaptureIlluminant } from \"./scene-radiance.js\";\n\nexport const CHART_RADIANCE_BATCH_SCHEMA_VERSION = \"0.1.0\" as const;\n/** `maximumQueries` is the default batch limit; a request may raise it with its own `maximumQueries`, up to `ceilingQueries`. */\nexport const CHART_RADIANCE_BATCH_LIMITS = Object.freeze({ maximumQueries: 24_000_000, ceilingQueries: FULL_RESOLUTION_CEILING_PIXELS, maximumWavelengths: 256,\n maximumChannels: 4 });\n\nexport interface ChartRadianceBatchInput {\n schemaVersion: typeof CHART_RADIANCE_BATCH_SCHEMA_VERSION;\n /** An engine chart preset (caller scene functions are not supported here). */\n scene: ChartScene;\n illuminant: CaptureIlluminant;\n illuminanceLux: number;\n /** Frame height / width. */\n aspect: number;\n /** Frame points, interleaved [u0, v0, u1, v1, …]. Finite. */\n points: Float32Array | Float64Array;\n /** The wavelengths the queries use, in nanometres (1–256). */\n wavelengthsNanometers: readonly number[];\n /** Radiance queries: one wavelength index per point. Exactly one of this and `channelWeights`. */\n wavelengthIndices?: Uint8Array | Uint16Array;\n /** Spectral integration: per channel (1–4), one finite weight per wavelength. */\n channelWeights?: readonly (readonly number[])[];\n /**\n * Optional opt-in batch limit: an integer from 1 to `CHART_RADIANCE_BATCH_LIMITS.ceilingQueries`. Default\n * `CHART_RADIANCE_BATCH_LIMITS.maximumQueries` (24 000 000). It does not change the values.\n */\n maximumQueries?: number;\n}\n\n/** Validated plan with the resolved chart, illuminant and irradiance scale. Arrays are borrowed. */\nexport interface ChartRadianceBatchPlan {\n chart: ResolvedChartScene;\n illuminant: ResolvedCaptureIlluminant;\n irradianceScale: number;\n queryCount: number;\n /** Output values per query: 1 for radiance queries, the channel count for spectral integration. */\n columns: number;\n mode: \"radiance\" | \"spectral-integral\";\n wavelengthsNanometers: readonly number[];\n channelWeights: readonly (readonly number[])[] | null;\n /** Spectral radiance of one material at a wavelength: the provider's own radianceAt for that material. */\n materialRadiance(material: number, wavelengthNanometers: number): number;\n /** The reference value of one query and output column (radianceAt, and its wavelength-ordered sum). */\n queryValue(points: Float32Array | Float64Array, wavelengthIndices: Uint8Array | Uint16Array | undefined, query: number, column: number): number;\n}\n\nexport function calculateChartRadianceBatchPlan(input: ChartRadianceBatchInput): ChartRadianceBatchPlan {\n const r = requireAllowlistedRecord(input, [\"schemaVersion\", \"scene\", \"illuminant\", \"illuminanceLux\", \"aspect\", \"points\", \"wavelengthsNanometers\",\n \"wavelengthIndices\", \"channelWeights\", \"maximumQueries\"], \"Invalid chart radiance batch input.\");\n if (r.schemaVersion !== CHART_RADIANCE_BATCH_SCHEMA_VERSION) throw new InvalidConfigurationError(\"Unsupported chart radiance batch schema.\");\n if (typeof r.aspect !== \"number\" || !(r.aspect > 0 && r.aspect <= Number.MAX_VALUE)) throw new InvalidConfigurationError(\"aspect must be positive.\");\n const chart = resolveChartScene({ scene: r.scene as ChartScene, aspect: r.aspect });\n const illuminant = resolveCaptureIlluminant(r.illuminant as CaptureIlluminant);\n const irradianceScale = calculateIlluminantIrradianceScale(illuminant.shape, r.illuminanceLux as number);\n const L = CHART_RADIANCE_BATCH_LIMITS, points = r.points;\n const maximumQueries = resolveRaisedLimit(r.maximumQueries, L.maximumQueries, L.ceilingQueries,\n \"Chart radiance batch maximumQueries must be an integer from 1 to \" + L.ceilingQueries + \".\");\n if (!(points instanceof Float32Array || points instanceof Float64Array) || points.length % 2 !== 0 || points.length / 2 > maximumQueries) {\n throw new InvalidConfigurationError(\"points must be an interleaved Float32Array or Float64Array of (u, v) pairs.\");\n }\n for (let i = 0; i < points.length; i++) if (!Number.isFinite(points[i]!)) throw new InvalidConfigurationError(\"Chart points must be finite.\");\n const queryCount = points.length / 2, wavelengths = r.wavelengthsNanometers;\n if (!Array.isArray(wavelengths) || wavelengths.length < 1 || wavelengths.length > L.maximumWavelengths ||\n wavelengths.some(nm => typeof nm !== \"number\" || !Number.isFinite(nm) || nm <= 0)) {\n throw new InvalidConfigurationError(\"wavelengthsNanometers must list 1 to 256 positive wavelengths.\");\n }\n const indices = r.wavelengthIndices, weights = r.channelWeights;\n if ((indices === undefined) === (weights === undefined)) throw new InvalidConfigurationError(\"Give exactly one of wavelengthIndices and channelWeights.\");\n if (indices !== undefined) {\n if (!(indices instanceof Uint8Array || indices instanceof Uint16Array) || indices.length !== queryCount) {\n throw new InvalidConfigurationError(\"wavelengthIndices must hold one index per point.\");\n }\n for (let i = 0; i < queryCount; i++) if (indices[i]! >= wavelengths.length) throw new InvalidConfigurationError(\"A wavelength index is out of range.\");\n } else if (!Array.isArray(weights) || weights.length < 1 || weights.length > L.maximumChannels ||\n weights.some(row => !Array.isArray(row) || row.length !== wavelengths.length || row.some(w => typeof w !== \"number\" || !Number.isFinite(w)))) {\n throw new InvalidConfigurationError(\"channelWeights must hold 1 to 4 rows of one finite weight per wavelength.\");\n }\n // The provider's own radiance function: chart reflectance × scaled illuminant / π, in its float64 order.\n const provider = buildPlanarSceneRadianceProvider({ scene: chart, sceneId: \"chart-radiance-batch\", providerProfileId: \"chart-radiance-batch\", illuminant,\n irradianceScale, geometry: { distanceM: 1, metresPerFrameUnit: 1 }, evidence: [], limitations: [] });\n const channelWeights = weights === undefined ? null : (weights as number[][]).map(row => Object.freeze([...row]));\n const nm = Object.freeze([...(wavelengths as number[])]);\n const materialRadiance = (material: number, wavelength: number): number => {\n const m = chart.materials[material]!;\n const reflectance = m.kind === \"neutral\" ? m.reflectance : m.spectrum.evaluate(wavelength);\n if (m.kind === \"spectrum\" && !(reflectance >= 0 && reflectance <= 1)) throw new InvalidConfigurationError(\"Chart reflectance spectrum left [0, 1].\");\n return reflectance * irradianceScale * illuminant.shape.evaluate(wavelength) / Math.PI;\n };\n return Object.freeze({ chart, illuminant, irradianceScale, queryCount, columns: channelWeights === null ? 1 : channelWeights.length,\n mode: channelWeights === null ? \"radiance\" as const : \"spectral-integral\" as const, wavelengthsNanometers: nm, channelWeights, materialRadiance,\n queryValue(p: Float32Array | Float64Array, w: Uint8Array | Uint16Array | undefined, query: number, column: number): number {\n const u = p[2 * query]!, v = p[2 * query + 1]!;\n if (channelWeights === null) return provider.radianceAt(u, v, nm[w![query]!]!);\n let sum = 0;\n const row = channelWeights[column]!;\n for (let j = 0; j < nm.length; j++) sum += row[j]! * provider.radianceAt(u, v, nm[j]!);\n return sum;\n } });\n}\n\n/** Float64 CPU reference: every query's value(s), row-major (query, column). */\nexport function calculateChartRadianceBatch(input: ChartRadianceBatchInput): { plan: ChartRadianceBatchPlan; values: Float64Array } {\n const plan = calculateChartRadianceBatchPlan(input), values = new Float64Array(plan.queryCount * plan.columns);\n for (let q = 0; q < plan.queryCount; q++) for (let c = 0; c < plan.columns; c++) values[q * plan.columns + c] = plan.queryValue(input.points, input.wavelengthIndices, q, c);\n return { plan, values };\n}\n\n/**\n * Frame points of environment-direction queries on the chart plane, exactly as the planar provider's\n * `evaluateRadiance` computes them: look direction l = −o, plane point l·distance/l.z, in frame units.\n * @param directions - Outgoing unit vectors (scene toward camera), interleaved [x, y, z, …].\n */\nexport function mapEnvironmentDirectionsToChartPoints(input: { directions: Float32Array | Float64Array; distanceM: number; metresPerFrameUnit: number }): Float64Array {\n const r = requireAllowlistedRecord(input, [\"directions\", \"distanceM\", \"metresPerFrameUnit\"], \"Invalid planar direction input.\");\n const d = r.directions, distance = r.distanceM, scale = r.metresPerFrameUnit;\n if (!(d instanceof Float32Array || d instanceof Float64Array) || d.length % 3 !== 0 || typeof distance !== \"number\" || !(distance > 0 && distance <= Number.MAX_VALUE) ||\n typeof scale !== \"number\" || !(scale > 0 && scale <= Number.MAX_VALUE)) {\n throw new InvalidConfigurationError(\"Planar directions need interleaved unit vectors, a positive distance and a positive frame scale.\");\n }\n const points = new Float64Array(d.length / 3 * 2);\n for (let i = 0; i < d.length / 3; i++) {\n const lz = -d[3 * i + 2]!;\n if (!(lz > 0)) throw new InvalidConfigurationError(\"Planar scene query does not point toward the scene plane.\");\n const t = distance / lz;\n const x = -d[3 * i]! * t / scale, y = -d[3 * i + 1]! * t / scale;\n // A grazing direction (lz near 0, e.g. 1e-320) or a non-finite component would give ±Infinity or NaN.\n if (!Number.isFinite(x) || !Number.isFinite(y)) throw new InvalidConfigurationError(\"Planar scene query maps to a non-finite chart point (grazing or non-finite direction).\");\n points[2 * i] = x;\n points[2 * i + 1] = y;\n }\n return points;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chart-radiance-batch.js","sourceRoot":"","sources":["../../src/facade/chart-radiance-batch.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7F,OAAO,EAAE,iBAAiB,EAA4C,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAE,gCAAgC,EAAE,kCAAkC,EAAE,wBAAwB,EAAE,iBAAiB,EACxF,MAAM,qBAAqB,CAAC;AAE9D,MAAM,CAAC,MAAM,mCAAmC,GAAG,OAAgB,CAAC;AACpE,iIAAiI;AACjI,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,8BAA8B,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CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;QACjE,sGAAsG;QACtG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;YAAE,MAAM,IAAI,yBAAyB,CAAC,wFAAwF,CAAC,CAAC;QAC9K,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QAClB,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Batched radiance queries for the engine's procedural chart scenes (#277): many frame points in one\n * call, each answered with spectral radiance at a declared wavelength, or with the spectral integral of\n * that radiance against declared channel weights. This is the float64 CPU reference for the\n * `webgpu-f32` chart-radiance stage (`ImageKernelAccelerator.evaluateChartRadiance`).\n *\n * Every value comes from the chart provider's own `radianceAt` (createPlanarSceneRadianceProvider): a\n * Lambertian reflectance ρ(λ) under the scaled illuminant, L = ρ·k·S(λ)/π. The spectral integral of a\n * query is Σ_j w_cj·L(u, v, λ_j), summed in wavelength order. Charts are uniform-illuminant Lambertian\n * patterns, so a query's integral depends only on its material: the GPU stage uses exactly that.\n *\n * The query shape mirrors a batched provider (one call, queries in, results in the same order). Points\n * are frame units (u right, v up; see chart-scenes.ts); `mapEnvironmentDirectionsToChartPoints` converts\n * environment-direction queries exactly as `evaluateRadiance` does.\n * @see docs/WEBGPU.md, \"Scene radiance on the GPU\".\n */\n\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { requireAllowlistedRecord } from \"../core/record-validation.js\";\nimport { FULL_RESOLUTION_CEILING_PIXELS, resolveRaisedLimit } from \"../core/pixel-limits.js\";\nimport { resolveChartScene, type ChartScene, type ResolvedChartScene } from \"./chart-scenes.js\";\nimport { buildPlanarSceneRadianceProvider, calculateIlluminantIrradianceScale, resolveCaptureIlluminant, tabulatedSpectrum, type CaptureIlluminant,\n type ResolvedCaptureIlluminant } from \"./scene-radiance.js\";\n\nexport const CHART_RADIANCE_BATCH_SCHEMA_VERSION = \"0.1.0\" as const;\n/** `maximumQueries` is the default batch limit; a request may raise it with its own `maximumQueries`, up to `ceilingQueries`. */\nexport const CHART_RADIANCE_BATCH_LIMITS = Object.freeze({ maximumQueries: 24_000_000, ceilingQueries: FULL_RESOLUTION_CEILING_PIXELS, maximumWavelengths: 256,\n maximumChannels: 4 });\n\nexport interface ChartRadianceBatchInput {\n schemaVersion: typeof CHART_RADIANCE_BATCH_SCHEMA_VERSION;\n /** An engine chart preset (caller scene functions are not supported here). */\n scene: ChartScene;\n illuminant: CaptureIlluminant;\n illuminanceLux: number;\n /** Frame height / width. */\n aspect: number;\n /** Frame points, interleaved [u0, v0, u1, v1, …]. Finite. */\n points: Float32Array | Float64Array;\n /** The wavelengths the queries use, in nanometres (1–256). */\n wavelengthsNanometers: readonly number[];\n /** Radiance queries: one wavelength index per point. Exactly one of this and `channelWeights`. */\n wavelengthIndices?: Uint8Array | Uint16Array;\n /** Spectral integration: per channel (1–4), one finite weight per wavelength. */\n channelWeights?: readonly (readonly number[])[];\n /**\n * Optional opt-in batch limit: an integer from 1 to `CHART_RADIANCE_BATCH_LIMITS.ceilingQueries`. Default\n * `CHART_RADIANCE_BATCH_LIMITS.maximumQueries` (24 000 000). It does not change the values.\n */\n maximumQueries?: number;\n}\n\n/** Validated plan with the resolved chart, illuminant and irradiance scale. Arrays are borrowed. */\nexport interface ChartRadianceBatchPlan {\n chart: ResolvedChartScene;\n illuminant: ResolvedCaptureIlluminant;\n irradianceScale: number;\n queryCount: number;\n /** Output values per query: 1 for radiance queries, the channel count for spectral integration. */\n columns: number;\n mode: \"radiance\" | \"spectral-integral\";\n wavelengthsNanometers: readonly number[];\n channelWeights: readonly (readonly number[])[] | null;\n /** Spectral radiance of one material at a wavelength: the provider's own radianceAt for that material. */\n materialRadiance(material: number, wavelengthNanometers: number): number;\n /** The reference value of one query and output column (radianceAt, and its wavelength-ordered sum). */\n queryValue(points: Float32Array | Float64Array, wavelengthIndices: Uint8Array | Uint16Array | undefined, query: number, column: number): number;\n}\n\nexport function calculateChartRadianceBatchPlan(input: ChartRadianceBatchInput): ChartRadianceBatchPlan {\n const r = requireAllowlistedRecord(input, [\"schemaVersion\", \"scene\", \"illuminant\", \"illuminanceLux\", \"aspect\", \"points\", \"wavelengthsNanometers\",\n \"wavelengthIndices\", \"channelWeights\", \"maximumQueries\"], \"Invalid chart radiance batch input.\");\n if (r.schemaVersion !== CHART_RADIANCE_BATCH_SCHEMA_VERSION) throw new InvalidConfigurationError(\"Unsupported chart radiance batch schema.\");\n if (typeof r.aspect !== \"number\" || !(r.aspect > 0 && r.aspect <= Number.MAX_VALUE)) throw new InvalidConfigurationError(\"aspect must be positive.\");\n const chart = resolveChartScene({ scene: r.scene as ChartScene, aspect: r.aspect });\n const illuminant = resolveCaptureIlluminant(r.illuminant as CaptureIlluminant);\n const irradianceScale = calculateIlluminantIrradianceScale(illuminant.shape, r.illuminanceLux as number);\n const L = CHART_RADIANCE_BATCH_LIMITS, points = r.points;\n const maximumQueries = resolveRaisedLimit(r.maximumQueries, L.maximumQueries, L.ceilingQueries,\n \"Chart radiance batch maximumQueries must be an integer from 1 to \" + L.ceilingQueries + \".\");\n if (!(points instanceof Float32Array || points instanceof Float64Array) || points.length % 2 !== 0 || points.length / 2 > maximumQueries) {\n throw new InvalidConfigurationError(\"points must be an interleaved Float32Array or Float64Array of (u, v) pairs.\");\n }\n for (let i = 0; i < points.length; i++) if (!Number.isFinite(points[i]!)) throw new InvalidConfigurationError(\"Chart points must be finite.\");\n const queryCount = points.length / 2, wavelengths = r.wavelengthsNanometers;\n if (!Array.isArray(wavelengths) || wavelengths.length < 1 || wavelengths.length > L.maximumWavelengths ||\n wavelengths.some(nm => typeof nm !== \"number\" || !Number.isFinite(nm) || nm <= 0)) {\n throw new InvalidConfigurationError(\"wavelengthsNanometers must list 1 to 256 positive wavelengths.\");\n }\n const indices = r.wavelengthIndices, weights = r.channelWeights;\n if ((indices === undefined) === (weights === undefined)) throw new InvalidConfigurationError(\"Give exactly one of wavelengthIndices and channelWeights.\");\n if (indices !== undefined) {\n if (!(indices instanceof Uint8Array || indices instanceof Uint16Array) || indices.length !== queryCount) {\n throw new InvalidConfigurationError(\"wavelengthIndices must hold one index per point.\");\n }\n for (let i = 0; i < queryCount; i++) if (indices[i]! >= wavelengths.length) throw new InvalidConfigurationError(\"A wavelength index is out of range.\");\n } else if (!Array.isArray(weights) || weights.length < 1 || weights.length > L.maximumChannels ||\n weights.some(row => !Array.isArray(row) || row.length !== wavelengths.length || row.some(w => typeof w !== \"number\" || !Number.isFinite(w)))) {\n throw new InvalidConfigurationError(\"channelWeights must hold 1 to 4 rows of one finite weight per wavelength.\");\n }\n // The provider's own radiance function: chart reflectance × scaled illuminant / π, in its float64 order.\n const provider = buildPlanarSceneRadianceProvider({ scene: chart, sceneId: \"chart-radiance-batch\", providerProfileId: \"chart-radiance-batch\", illuminant,\n irradianceScale, geometry: { distanceM: 1, metresPerFrameUnit: 1 }, evidence: [], limitations: [] });\n const channelWeights = weights === undefined ? null : (weights as number[][]).map(row => Object.freeze([...row]));\n const nm = Object.freeze([...(wavelengths as number[])]);\n const shapeAt = tabulatedSpectrum(illuminant.shape);\n const materialRadiance = (material: number, wavelength: number): number => {\n const m = chart.materials[material]!;\n const reflectance = m.kind === \"neutral\" ? m.reflectance : m.spectrum.evaluate(wavelength);\n if (m.kind === \"spectrum\" && !(reflectance >= 0 && reflectance <= 1)) throw new InvalidConfigurationError(\"Chart reflectance spectrum left [0, 1].\");\n return reflectance * irradianceScale * shapeAt(wavelength) / Math.PI;\n };\n return Object.freeze({ chart, illuminant, irradianceScale, queryCount, columns: channelWeights === null ? 1 : channelWeights.length,\n mode: channelWeights === null ? \"radiance\" as const : \"spectral-integral\" as const, wavelengthsNanometers: nm, channelWeights, materialRadiance,\n queryValue(p: Float32Array | Float64Array, w: Uint8Array | Uint16Array | undefined, query: number, column: number): number {\n const u = p[2 * query]!, v = p[2 * query + 1]!;\n if (channelWeights === null) return provider.radianceAt(u, v, nm[w![query]!]!);\n let sum = 0;\n const row = channelWeights[column]!;\n for (let j = 0; j < nm.length; j++) sum += row[j]! * provider.radianceAt(u, v, nm[j]!);\n return sum;\n } });\n}\n\n/** Float64 CPU reference: every query's value(s), row-major (query, column). */\nexport function calculateChartRadianceBatch(input: ChartRadianceBatchInput): { plan: ChartRadianceBatchPlan; values: Float64Array } {\n const plan = calculateChartRadianceBatchPlan(input), values = new Float64Array(plan.queryCount * plan.columns);\n for (let q = 0; q < plan.queryCount; q++) for (let c = 0; c < plan.columns; c++) values[q * plan.columns + c] = plan.queryValue(input.points, input.wavelengthIndices, q, c);\n return { plan, values };\n}\n\n/**\n * Frame points of environment-direction queries on the chart plane, exactly as the planar provider's\n * `evaluateRadiance` computes them: look direction l = −o, plane point l·distance/l.z, in frame units.\n * @param directions - Outgoing unit vectors (scene toward camera), interleaved [x, y, z, …].\n */\nexport function mapEnvironmentDirectionsToChartPoints(input: { directions: Float32Array | Float64Array; distanceM: number; metresPerFrameUnit: number }): Float64Array {\n const r = requireAllowlistedRecord(input, [\"directions\", \"distanceM\", \"metresPerFrameUnit\"], \"Invalid planar direction input.\");\n const d = r.directions, distance = r.distanceM, scale = r.metresPerFrameUnit;\n if (!(d instanceof Float32Array || d instanceof Float64Array) || d.length % 3 !== 0 || typeof distance !== \"number\" || !(distance > 0 && distance <= Number.MAX_VALUE) ||\n typeof scale !== \"number\" || !(scale > 0 && scale <= Number.MAX_VALUE)) {\n throw new InvalidConfigurationError(\"Planar directions need interleaved unit vectors, a positive distance and a positive frame scale.\");\n }\n const points = new Float64Array(d.length / 3 * 2);\n for (let i = 0; i < d.length / 3; i++) {\n const lz = -d[3 * i + 2]!;\n if (!(lz > 0)) throw new InvalidConfigurationError(\"Planar scene query does not point toward the scene plane.\");\n const t = distance / lz;\n const x = -d[3 * i]! * t / scale, y = -d[3 * i + 1]! * t / scale;\n // A grazing direction (lz near 0, e.g. 1e-320) or a non-finite component would give ±Infinity or NaN.\n if (!Number.isFinite(x) || !Number.isFinite(y)) throw new InvalidConfigurationError(\"Planar scene query maps to a non-finite chart point (grazing or non-finite direction).\");\n points[2 * i] = x;\n points[2 * i + 1] = y;\n }\n return points;\n}\n"]}
|
|
@@ -348,6 +348,8 @@ export declare const CHART_SPECTRAL_RANGE_NANOMETERS: Readonly<{
|
|
|
348
348
|
minimum: 380;
|
|
349
349
|
maximum: 780;
|
|
350
350
|
}>;
|
|
351
|
+
/** Internal: validates a chart reflectance input (a neutral number or a reflectance spectrum covering 380–780 nm) as a material. */
|
|
352
|
+
export declare function resolveChartMaterial(value: unknown, name: string): ResolvedChartScene["materials"][number];
|
|
351
353
|
/**
|
|
352
354
|
* Internal (not exported from the package): the caller input behind each material of a resolved chart, in
|
|
353
355
|
* material order (`undefined` for an engine neutral). The facade hashes caller spectra from these inputs.
|
|
@@ -70,7 +70,8 @@ function finiteIn(value, name, minimum, maximum, open = false) {
|
|
|
70
70
|
}
|
|
71
71
|
/** Wavelength range every chart spectrum must cover (the facade's sensor quadrature range). */
|
|
72
72
|
export const CHART_SPECTRAL_RANGE_NANOMETERS = Object.freeze({ minimum: 380, maximum: 780 });
|
|
73
|
-
|
|
73
|
+
/** Internal: validates a chart reflectance input (a neutral number or a reflectance spectrum covering 380–780 nm) as a material. */
|
|
74
|
+
export function resolveChartMaterial(value, name) {
|
|
74
75
|
if (typeof value === "number")
|
|
75
76
|
return { kind: "neutral", reflectance: reflectance(value, name) };
|
|
76
77
|
let spectrum;
|
|
@@ -173,7 +174,7 @@ function resolveScene(scene, aspect, context) {
|
|
|
173
174
|
};
|
|
174
175
|
switch (preset) {
|
|
175
176
|
case "uniform": {
|
|
176
|
-
const raw = get("reflectance"), m =
|
|
177
|
+
const raw = get("reflectance"), m = resolveChartMaterial(raw, "reflectance");
|
|
177
178
|
return done({ reflectance: typeof raw === "number" ? raw : "caller-spectrum" }, [m], () => 0, [typeof raw === "number" ? undefined : raw]);
|
|
178
179
|
}
|
|
179
180
|
case "slanted-edge": {
|
|
@@ -260,7 +261,7 @@ function resolveScene(scene, aspect, context) {
|
|
|
260
261
|
if (typeof p.patchId !== "string" || p.patchId.trim() === "" || ids.has(p.patchId))
|
|
261
262
|
throw new InvalidConfigurationError("Each patch needs a unique non-empty patchId.");
|
|
262
263
|
ids.add(p.patchId);
|
|
263
|
-
materials.push(
|
|
264
|
+
materials.push(resolveChartMaterial(p.reflectance, "patches[" + index + "].reflectance"));
|
|
264
265
|
inputs.push(typeof p.reflectance === "number" ? undefined : p.reflectance);
|
|
265
266
|
}
|
|
266
267
|
const columnsRaw = record.columns === undefined ? Math.ceil(Math.sqrt(list.length)) : record.columns;
|