@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.
@@ -3,7 +3,7 @@ import { type CieDaylightBasis } from "../color/illuminants.js";
3
3
  import type { SceneRadianceEvaluationRequest, SceneRadianceEvaluationResult } from "../schema/scene-radiance.js";
4
4
  import type { EvidenceProvenance } from "../core/evidence-provenance.js";
5
5
  import type { SensorApertureRay } from "../optics/sensor-aperture-rays.js";
6
- import { type ChartScene, type ResolvedChartScene } from "./chart-scenes.js";
6
+ import { type ChartReflectance, type ChartScene, type ResolvedChartScene } from "./chart-scenes.js";
7
7
  /** CIE maximum luminous efficacy for photopic vision, lm/W. */
8
8
  export declare const PHOTOPIC_MAXIMUM_LUMINOUS_EFFICACY_LM_PER_W = 683;
9
9
  /** Wavelength range of every facade spectrum and of the facade sensor quadrature, nm. */
@@ -80,6 +80,33 @@ export interface CallerRadianceScene {
80
80
  sceneId: string;
81
81
  evaluate(point: Readonly<ScenePlanePoint>): number;
82
82
  }
83
+ /** 2.7: a scene-plane point without a wavelength, passed to a material scene's `materialAt`. */
84
+ export type SceneMaterialPoint = Omit<ScenePlanePoint, "wavelengthNanometers">;
85
+ /**
86
+ * 2.7 (#386): a piecewise-constant caller scene, lit by the facade illuminant like a reflectance function. `materials` are
87
+ * reflectances as a chart's patches take them (a neutral number in [0, 1] or a reflectance spectrum covering 380–780 nm, at
88
+ * most {@link CALLER_MATERIAL_SCENE_MAX_MATERIALS}); `materialAt` returns the index of the material at a plane point (an
89
+ * integer from 0 to materials.length − 1). The radiance at a point is that material's, exactly as for a reflectance function
90
+ * returning its reflectance, but renderers can tabulate each material once: the display view then takes the chart path.
91
+ */
92
+ export interface CallerMaterialScene {
93
+ kind: "material-function";
94
+ sceneId: string;
95
+ materials: readonly ChartReflectance[];
96
+ materialAt(point: Readonly<SceneMaterialPoint>): number;
97
+ }
98
+ /** Most materials a {@link CallerMaterialScene} may list. */
99
+ export declare const CALLER_MATERIAL_SCENE_MAX_MATERIALS = 65536;
100
+ /** Internal: a validated material scene with its materials prepared (and the caller inputs, for the scene digest). */
101
+ export interface ResolvedCallerMaterialScene {
102
+ kind: "material-function";
103
+ sceneId: string;
104
+ materials: ResolvedChartScene["materials"];
105
+ materialInputs: readonly unknown[];
106
+ materialAt(point: Readonly<SceneMaterialPoint>): number;
107
+ }
108
+ /** Internal: a validated caller scene. */
109
+ export type ResolvedCallerScene = CallerReflectanceScene | CallerRadianceScene | ResolvedCallerMaterialScene;
83
110
  export interface PlanarSceneGeometry {
84
111
  distanceM: number;
85
112
  /** Metres per frame unit on the plane (half the framed width). */
@@ -110,12 +137,18 @@ export interface PlanarSceneRadianceProvider {
110
137
  chartMaterialAt?(u: number, v: number): number;
111
138
  materialRadiance?(material: number, wavelengthNanometers: number): number;
112
139
  }
140
+ /**
141
+ * Internal (#385): `spectrum.evaluate` remembered per distinct wavelength. A prepared spectrum is a pure function of the
142
+ * wavelength, so the table returns the same double the call would; renderers ask for the same few spectral nodes millions
143
+ * of times, and the illuminant's formula (two transcendental evaluations) was about 30 % of a caller-scene display view.
144
+ */
145
+ export declare function tabulatedSpectrum(spectrum: Readonly<PreparedColorimetricSpectrum>): (wavelengthNanometers: number) => number;
113
146
  /**
114
147
  * Wraps a chart or caller scene as a provider for the native environment RAW task. `irradianceScale` is
115
148
  * from {@link calculateIlluminantIrradianceScale}; caller radiance scenes ignore the illuminant.
116
149
  */
117
150
  export declare function buildPlanarSceneRadianceProvider(input: {
118
- scene: ResolvedChartScene | CallerReflectanceScene | CallerRadianceScene;
151
+ scene: ResolvedChartScene | ResolvedCallerScene;
119
152
  sceneId: string;
120
153
  providerProfileId: string;
121
154
  illuminant: ResolvedCaptureIlluminant;
@@ -150,7 +183,7 @@ export declare function resolveChartSizeOption(value: unknown, frameAspect: numb
150
183
  * provider `providerProfileId`.
151
184
  */
152
185
  export declare function createPlanarSceneRadianceProvider(input: {
153
- scene: ChartScene | CallerReflectanceScene | CallerRadianceScene;
186
+ scene: ChartScene | CallerReflectanceScene | CallerRadianceScene | CallerMaterialScene;
154
187
  illuminant: CaptureIlluminant;
155
188
  illuminanceLux: number;
156
189
  distanceM: number;
@@ -167,5 +200,5 @@ export declare function createPlanarSceneRadianceProvider(input: {
167
200
  }): PlanarSceneRadianceProvider & {
168
201
  chart: ResolvedChartScene | null;
169
202
  };
170
- /** Validates a caller scene function record. */
171
- export declare function requireCallerScene(value: unknown): CallerReflectanceScene | CallerRadianceScene;
203
+ /** Validates a caller scene record (a function scene as given; a material scene with its materials prepared). */
204
+ export declare function requireCallerScene(value: unknown): ResolvedCallerScene;
@@ -21,7 +21,7 @@ import { InvalidConfigurationError } from "../core/configuration-error.js";
21
21
  import { requireInputObject } from "../core/record-validation.js";
22
22
  import { estimateCie1931ColorMatchingFunctions, prepareColorimetricSpectrum } from "../color/color-matching-functions.js";
23
23
  import { createCieIlluminantASpectrum, createCieDaylightSpectrum, createPlanckianSpectrum, createPortableCieDaylightSpectrum, createPortableCieIlluminantASpectrum, createPortablePlanckianSpectrum } from "../color/illuminants.js";
24
- import { resolveChartScene } from "./chart-scenes.js";
24
+ import { resolveChartMaterial, resolveChartScene } from "./chart-scenes.js";
25
25
  /** CIE maximum luminous efficacy for photopic vision, lm/W. */
26
26
  export const PHOTOPIC_MAXIMUM_LUMINOUS_EFFICACY_LM_PER_W = 683;
27
27
  /** Wavelength range of every facade spectrum and of the facade sensor quadrature, nm. */
@@ -121,7 +121,28 @@ export function calculateIlluminantIrradianceScale(shape, illuminanceLux) {
121
121
  throw new InvalidConfigurationError("The illuminant has no luminous power.");
122
122
  return illuminanceLux / (PHOTOPIC_MAXIMUM_LUMINOUS_EFFICACY_LM_PER_W * sum);
123
123
  }
124
+ /** Most materials a {@link CallerMaterialScene} may list. */
125
+ export const CALLER_MATERIAL_SCENE_MAX_MATERIALS = 65_536;
124
126
  const UNCERTAINTY = Object.freeze({ kind: "not-quantified", limitation: "Analytic planar Lambertian scene; no measured scene, BRDF or illumination." });
127
+ /** Most distinct wavelengths {@link tabulatedSpectrum} keeps; later ones are evaluated on every call. */
128
+ const TABULATED_SPECTRUM_MAX_ENTRIES = 4096;
129
+ /**
130
+ * Internal (#385): `spectrum.evaluate` remembered per distinct wavelength. A prepared spectrum is a pure function of the
131
+ * wavelength, so the table returns the same double the call would; renderers ask for the same few spectral nodes millions
132
+ * of times, and the illuminant's formula (two transcendental evaluations) was about 30 % of a caller-scene display view.
133
+ */
134
+ export function tabulatedSpectrum(spectrum) {
135
+ const table = new Map();
136
+ return (nm) => {
137
+ let value = table.get(nm);
138
+ if (value === undefined) {
139
+ value = spectrum.evaluate(nm);
140
+ if (table.size < TABULATED_SPECTRUM_MAX_ENTRIES)
141
+ table.set(nm, value);
142
+ }
143
+ return value;
144
+ };
145
+ }
125
146
  /**
126
147
  * Wraps a chart or caller scene as a provider for the native environment RAW task. `irradianceScale` is
127
148
  * from {@link calculateIlluminantIrradianceScale}; caller radiance scenes ignore the illuminant.
@@ -131,19 +152,40 @@ export function buildPlanarSceneRadianceProvider(input) {
131
152
  const scale = geometry.metresPerFrameUnit, distance = geometry.distanceM, sceneId = input.sceneId, providerProfileId = input.providerProfileId;
132
153
  const evidence = input.evidence, limitations = input.limitations;
133
154
  const caller = "kind" in scene ? scene : undefined, chart = caller ? undefined : scene;
155
+ const materialScene = caller?.kind === "material-function" ? caller : undefined, materials = chart ? chart.materials : materialScene?.materials;
134
156
  const placed = geometry.chart, half = placed ? placed.widthM / 2 : 0, chartAspect = placed ? placed.heightM / placed.widthM : 0;
157
+ const shapeAt = tabulatedSpectrum(illuminant.shape);
158
+ /** A material scene's material at a frame point: the caller's index, or `materials.length` for a fixed-size chart's surround. */
159
+ function callerMaterialAt(u, v) {
160
+ const xM = u * scale, yM = v * scale;
161
+ let point;
162
+ if (placed) {
163
+ const cu = xM / half, cv = yM / half;
164
+ if (!(Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect))
165
+ return materialScene.materials.length;
166
+ point = Object.freeze({ xM, yM, u, v, chartU: cu, chartV: cv });
167
+ }
168
+ else
169
+ point = Object.freeze({ xM, yM, u, v });
170
+ const index = materialScene.materialAt(point);
171
+ if (!Number.isInteger(index) || index < 0 || index >= materialScene.materials.length)
172
+ throw new InvalidConfigurationError("Scene materialAt must return an index into its materials.");
173
+ return index;
174
+ }
135
175
  function radianceAt(u, v, nm) {
176
+ if (materialScene)
177
+ return materialRadianceOf(callerMaterialAt(u, v), nm);
136
178
  if (placed) {
137
179
  // Fixed-size chart (2.3): chart-local frame units from the plane point in metres.
138
180
  const xM = u * scale, yM = v * scale, cu = xM / half, cv = yM / half;
139
181
  if (!(Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect))
140
- return placed.surroundReflectance * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;
182
+ return placed.surroundReflectance * irradianceScale * shapeAt(nm) / Math.PI;
141
183
  if (chart)
142
- return chart.reflectanceAt(cu, cv, nm) * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;
184
+ return chart.reflectanceAt(cu, cv, nm) * irradianceScale * shapeAt(nm) / Math.PI;
143
185
  return callerValue(Object.freeze({ xM, yM, u, v, wavelengthNanometers: nm, chartU: cu, chartV: cv }), nm);
144
186
  }
145
187
  if (chart)
146
- return chart.reflectanceAt(u, v, nm) * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;
188
+ return chart.reflectanceAt(u, v, nm) * irradianceScale * shapeAt(nm) / Math.PI;
147
189
  return callerValue(Object.freeze({ xM: u * scale, yM: v * scale, u, v, wavelengthNanometers: nm }), nm);
148
190
  }
149
191
  function callerValue(point, nm) {
@@ -151,7 +193,7 @@ export function buildPlanarSceneRadianceProvider(input) {
151
193
  if (caller.kind === "reflectance-function") {
152
194
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1)
153
195
  throw new InvalidConfigurationError("Scene reflectance function must return a value in [0, 1].");
154
- return value * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;
196
+ return value * irradianceScale * shapeAt(nm) / Math.PI;
155
197
  }
156
198
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
157
199
  throw new InvalidConfigurationError("Scene radiance function must return a finite non-negative radiance.");
@@ -162,6 +204,23 @@ export function buildPlanarSceneRadianceProvider(input) {
162
204
  wavelengthBasis: request.wavelengthBasis, quantity: "outgoing-spectral-radiance", unit: "W/m^2/sr/nm",
163
205
  spectralRadianceWattsPerSquareMeterSteradianNanometer: radiance, scientificStatus: "approximation", uncertainty: UNCERTAINTY, evidence, limitations };
164
206
  }
207
+ /** Spectral radiance of material `material` (`materials.length`: a fixed-size chart's surround), in the chart's expression order. */
208
+ function materialRadianceOf(material, nm) {
209
+ const m = materials[material];
210
+ let value;
211
+ if (m === undefined)
212
+ value = placed ? placed.surroundReflectance : NaN;
213
+ else if (m.kind === "neutral")
214
+ value = m.reflectance;
215
+ else {
216
+ value = m.spectrum.evaluate(nm);
217
+ if (!(value >= 0 && value <= 1))
218
+ throw new InvalidConfigurationError("Chart reflectance spectrum left [0, 1].");
219
+ }
220
+ if (!(value >= 0))
221
+ throw new InvalidConfigurationError("Unknown chart material.");
222
+ return value * irradianceScale * shapeAt(nm) / Math.PI;
223
+ }
165
224
  const chartAccess = chart ? {
166
225
  chartMaterialAt(u, v) {
167
226
  if (!placed)
@@ -169,23 +228,8 @@ export function buildPlanarSceneRadianceProvider(input) {
169
228
  const cu = u * scale / half, cv = v * scale / half;
170
229
  return Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect ? chart.materialAt(cu, cv) : chart.materials.length;
171
230
  },
172
- materialRadiance(material, nm) {
173
- const m = chart.materials[material];
174
- let value;
175
- if (m === undefined)
176
- value = placed ? placed.surroundReflectance : NaN;
177
- else if (m.kind === "neutral")
178
- value = m.reflectance;
179
- else {
180
- value = m.spectrum.evaluate(nm);
181
- if (!(value >= 0 && value <= 1))
182
- throw new InvalidConfigurationError("Chart reflectance spectrum left [0, 1].");
183
- }
184
- if (!(value >= 0))
185
- throw new InvalidConfigurationError("Unknown chart material.");
186
- return value * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;
187
- }
188
- } : {};
231
+ materialRadiance: materialRadianceOf
232
+ } : materialScene ? { chartMaterialAt: callerMaterialAt, materialRadiance: materialRadianceOf } : {};
189
233
  return {
190
234
  sceneId, providerProfileId, radianceAt, ...chartAccess,
191
235
  evaluateRadiance(request) {
@@ -263,10 +307,22 @@ export function createPlanarSceneRadianceProvider(input) {
263
307
  limitations: ["Planar Lambertian scene under uniform illumination; no shadows, inter-reflection, gloss or fluorescence."] });
264
308
  return { ...provider, chart };
265
309
  }
266
- /** Validates a caller scene function record. */
310
+ /** Validates a caller scene record (a function scene as given; a material scene with its materials prepared). */
267
311
  export function requireCallerScene(value) {
268
312
  requireInputObject(value, "scene");
269
313
  const record = value;
314
+ if (record.kind === "material-function") {
315
+ for (const key of Object.keys(record))
316
+ if (key !== "kind" && key !== "sceneId" && key !== "materials" && key !== "materialAt")
317
+ throw new InvalidConfigurationError("Unknown scene field: " + key + ".");
318
+ if (typeof record.materialAt !== "function" || typeof record.sceneId !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/.test(record.sceneId) ||
319
+ !Array.isArray(record.materials) || record.materials.length < 1 || record.materials.length > CALLER_MATERIAL_SCENE_MAX_MATERIALS)
320
+ throw new InvalidConfigurationError("A material scene needs a public sceneId, 1 to " + CALLER_MATERIAL_SCENE_MAX_MATERIALS + " materials and a materialAt function.");
321
+ const inputs = [...record.materials];
322
+ return Object.freeze({ kind: "material-function", sceneId: record.sceneId, materialAt: record.materialAt,
323
+ materials: Object.freeze(inputs.map((m, index) => resolveChartMaterial(m, "scene.materials[" + index + "]"))),
324
+ materialInputs: Object.freeze(inputs.map((m) => (typeof m === "number" ? undefined : m))) });
325
+ }
270
326
  for (const key of Object.keys(record))
271
327
  if (key !== "kind" && key !== "sceneId" && key !== "evaluate")
272
328
  throw new InvalidConfigurationError("Unknown scene field: " + key + ".");
@@ -1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,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,UAAU;YAAE,MAAM,IAAI,yBAAyB,CAAC,uBAAuB,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;IAC/K,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,sBAAsB,IAAI,MAAM,CAAC,IAAI,KAAK,mBAAmB,CAAC,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU;QAC1H,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,oCAAoC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,yBAAyB,CAAC,uEAAuE,CAAC,CAAC;IACjN,OAAO,MAAiE,CAAC;AAC3E,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Turns a facade scene and an illuminant into a scene radiance provider for the existing native\n * environment RAW contract (`NativeEnvironmentRawProvider.evaluateRadiance` and, for pupil sampling,\n * `evaluateApertureRadiance`). The scene is an engine chart, a caller reflectance function or a caller\n * radiance function.\n *\n * Geometry: one plane perpendicular to the optical axis at `distanceM` in front of the camera. A query's\n * outgoing direction o (scene toward camera, see docs/SENSOR_ENVIRONMENT_QUERY.md) gives the look\n * direction l = -o; the plane point is l·distanceM/l.z. With a pupil ray, the plane point is the ray from\n * its lens origin to z = distanceM.\n *\n * Radiometry: a Lambertian reflector of reflectance ρ(λ) under irradiance E(λ) has radiance\n * L(λ) = ρ(λ)·E(λ)/π (W·m⁻²·sr⁻¹·nm⁻¹). The illuminant spectral shape S(λ) is scaled so that the\n * plane illuminance is E_v = K_m ∫ E(λ) V(λ) dλ with K_m = 683 lm/W (CIE photometric definition) and\n * V(λ) = ȳ(λ) from the engine's analytic CIE 1931 fit. The light is uniform\n * over the plane, with no shadows. Inter-reflection, gloss and fluorescence are not modelled.\n * @see docs/QUICK_START.md\n */\n\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { requireInputObject } from \"../core/record-validation.js\";\nimport { estimateCie1931ColorMatchingFunctions, prepareColorimetricSpectrum, type ColorimetricSpectrum,\n type PreparedColorimetricSpectrum } from \"../color/color-matching-functions.js\";\nimport { createCieIlluminantASpectrum, createCieDaylightSpectrum, createPlanckianSpectrum, createPortableCieDaylightSpectrum, createPortableCieIlluminantASpectrum,\n createPortablePlanckianSpectrum, type CieDaylightBasis } from \"../color/illuminants.js\";\nimport type { SceneRadianceEvaluationRequest, SceneRadianceEvaluationResult } from \"../schema/scene-radiance.js\";\nimport type { EvidenceProvenance } from \"../core/evidence-provenance.js\";\nimport type { SensorApertureRay } from \"../optics/sensor-aperture-rays.js\";\nimport { resolveChartScene, type ChartScene, type ResolvedChartScene } from \"./chart-scenes.js\";\n\n/** CIE maximum luminous efficacy for photopic vision, lm/W. */\nexport const PHOTOPIC_MAXIMUM_LUMINOUS_EFFICACY_LM_PER_W = 683;\n/** Wavelength range of every facade spectrum and of the facade sensor quadrature, nm. */\nexport const FACADE_SPECTRAL_RANGE_NANOMETERS = Object.freeze({ minimum: 380, maximum: 780 });\n\n/**\n * Illuminant choices. CIE D65 is not bundled: its S0/S1/S2 basis tables must come from the caller\n * (`daylight`). `planckian` is Planck's law; `cie-a` is CIE illuminant A from its defining formula.\n */\nexport type CaptureIlluminant =\n | \"cie-a\"\n | { kind: \"planckian\"; temperatureKelvin: number }\n | { kind: \"cie-a\" }\n | { kind: \"daylight\"; correlatedColorTemperatureKelvin: number; basis: CieDaylightBasis }\n | { kind: \"spectrum\"; spectrum: ColorimetricSpectrum; label?: string };\n\nexport interface ResolvedCaptureIlluminant {\n /** Short public description, for example \"planckian-6500K\". */\n id: string;\n description: string;\n /** Relative spectral shape (arbitrary scale) over at least 380-780 nm. */\n shape: PreparedColorimetricSpectrum;\n /** Original spectrum, for colorimetric white-balance calculations. */\n spectrum: ColorimetricSpectrum;\n}\n\nexport function resolveCaptureIlluminant(value: CaptureIlluminant): ResolvedCaptureIlluminant {\n return resolveIlluminant(value, CAPTURE_SPECTRA);\n}\n/**\n * The spectrum constructors of the engine's own illuminant formulas: the capture's, or the portable ones (the display view).\n * They are passed in rather than chosen inside {@link resolveIlluminant}, so a bundle that only captures does not contain the\n * portable ones.\n */\ninterface IlluminantSpectra { planckian: typeof createPlanckianSpectrum; cieA: typeof createCieIlluminantASpectrum; daylight: typeof createCieDaylightSpectrum }\nconst CAPTURE_SPECTRA: IlluminantSpectra = { planckian: createPlanckianSpectrum, cieA: createCieIlluminantASpectrum, daylight: createCieDaylightSpectrum };\n/**\n * Internal (not exported from the package): {@link resolveCaptureIlluminant} with the engine's own formulas (Planckian,\n * CIE A, daylight locus) evaluated with the portable power and e^x − 1 (`portablePow`, `portableExpm1`), so the spectrum\n * has the same bits in every JavaScript engine. The display view uses it; captures keep {@link resolveCaptureIlluminant}.\n * A caller spectrum is the caller's own.\n */\nexport function resolvePortableCaptureIlluminant(value: CaptureIlluminant): ResolvedCaptureIlluminant {\n return resolveIlluminant(value, { planckian: createPortablePlanckianSpectrum, cieA: createPortableCieIlluminantASpectrum, daylight: createPortableCieDaylightSpectrum });\n}\nfunction resolveIlluminant(value: CaptureIlluminant, spectra: IlluminantSpectra): ResolvedCaptureIlluminant {\n if (value === \"cie-a\") return resolveIlluminant({ kind: \"cie-a\" }, spectra);\n requireInputObject(value, \"illuminant\");\n const record = value as unknown as Record<string, unknown>;\n const allowed: Record<string, readonly string[]> = { planckian: [\"kind\", \"temperatureKelvin\"], \"cie-a\": [\"kind\"],\n daylight: [\"kind\", \"correlatedColorTemperatureKelvin\", \"basis\"], spectrum: [\"kind\", \"spectrum\", \"label\"] };\n const keys = typeof record.kind === \"string\" ? allowed[record.kind] : undefined;\n if (!keys) throw new InvalidConfigurationError(\"Unknown illuminant kind.\");\n for (const key of Object.keys(record)) if (!keys.includes(key)) throw new InvalidConfigurationError(\"Unknown illuminant field: \" + key + \".\");\n let spectrum: ColorimetricSpectrum, id: string, description: string;\n try {\n switch (value.kind) {\n case \"planckian\": {\n const t = value.temperatureKelvin;\n if (typeof t !== \"number\" || !Number.isFinite(t) || t < 1000 || t > 25000) throw new InvalidConfigurationError(\"Planckian temperature must be 1000-25000 K.\");\n spectrum = spectra.planckian({ temperatureKelvin: t, wavelengthRangeNanometers: { ...FACADE_SPECTRAL_RANGE_NANOMETERS } });\n id = \"planckian-\" + t + \"K\"; description = \"Planck blackbody spectrum at \" + t + \" K (Planck's law).\";\n break;\n }\n case \"cie-a\":\n spectrum = spectra.cieA(); id = \"cie-a\"; description = \"CIE standard illuminant A from its defining formula: Planck's law with c2 = 1.435e-2 m·K and T = 2848 K, 100 at 560 nm.\";\n break;\n case \"daylight\":\n spectrum = spectra.daylight({ correlatedColorTemperatureKelvin: value.correlatedColorTemperatureKelvin, coefficientRounding: \"cie-three-decimals\", basis: value.basis });\n id = \"cie-daylight-\" + value.correlatedColorTemperatureKelvin + \"K\"; description = \"CIE daylight from the caller's S0/S1/S2 basis (\" + value.basis.datasetId + \").\";\n break;\n case \"spectrum\":\n spectrum = value.spectrum; id = \"caller-spectrum\";\n description = \"Caller illuminant spectrum\" + (typeof value.label === \"string\" ? \" (\" + value.label + \")\" : \"\") + \".\";\n break;\n }\n } catch (error) {\n if (error instanceof InvalidConfigurationError) throw error;\n throw new InvalidConfigurationError(\"Invalid illuminant: \" + (error instanceof Error ? error.message : \"invalid\"));\n }\n let shape: PreparedColorimetricSpectrum;\n try { shape = prepareColorimetricSpectrum(spectrum, \"illuminant\"); } catch (error) {\n throw new InvalidConfigurationError(\"Invalid illuminant spectrum: \" + (error instanceof Error ? error.message : \"invalid\"));\n }\n const range = shape.wavelengthRangeNanometers;\n if (range.minimum > FACADE_SPECTRAL_RANGE_NANOMETERS.minimum || range.maximum < FACADE_SPECTRAL_RANGE_NANOMETERS.maximum)\n throw new InvalidConfigurationError(\"The illuminant spectrum must cover 380-780 nm.\");\n for (let nm = FACADE_SPECTRAL_RANGE_NANOMETERS.minimum; nm <= FACADE_SPECTRAL_RANGE_NANOMETERS.maximum; nm += 1) {\n const s = shape.evaluate(nm);\n if (!(s >= 0)) throw new InvalidConfigurationError(\"The illuminant spectrum must be non-negative over 380-780 nm.\");\n }\n return Object.freeze({ id, description, shape, spectrum });\n}\n\n/**\n * Factor k such that k·S(λ) (W·m⁻²·nm⁻¹) gives `illuminanceLux` on the plane: E_v = 683 ∫ k S ȳ dλ,\n * integrated with the 1 nm trapezoid rule over 380-780 nm (ȳ outside this range is below 4e-5 of its peak).\n */\nexport function calculateIlluminantIrradianceScale(shape: PreparedColorimetricSpectrum, illuminanceLux: number): number {\n if (typeof shape !== \"object\" || shape === null || typeof shape.evaluate !== \"function\") throw new InvalidConfigurationError(\"A prepared illuminant spectrum is required.\");\n if (typeof illuminanceLux !== \"number\" || !Number.isFinite(illuminanceLux) || illuminanceLux <= 0 || illuminanceLux > 1e7)\n throw new InvalidConfigurationError(\"Illuminance must be a positive number of lux up to 1e7.\");\n let sum = 0;\n for (let nm = FACADE_SPECTRAL_RANGE_NANOMETERS.minimum; nm <= FACADE_SPECTRAL_RANGE_NANOMETERS.maximum; nm++) {\n const w = nm === FACADE_SPECTRAL_RANGE_NANOMETERS.minimum || nm === FACADE_SPECTRAL_RANGE_NANOMETERS.maximum ? 0.5 : 1;\n sum += w * shape.evaluate(nm) * estimateCie1931ColorMatchingFunctions(nm).y;\n }\n if (!(sum > 0)) throw new InvalidConfigurationError(\"The illuminant has no luminous power.\");\n return illuminanceLux / (PHOTOPIC_MAXIMUM_LUMINOUS_EFFICACY_LM_PER_W * sum);\n}\n\n/** A point of the scene plane passed to caller scene functions. */\nexport interface ScenePlanePoint {\n /** Metres on the plane, from the optical axis: +x right, +y up (as seen from the camera). */\n xM: number;\n yM: number;\n /** The same point in frame units (u = ±1 at the left/right frame edges, v up on the same scale). */\n u: number;\n v: number;\n wavelengthNanometers: number;\n /**\n * 2.3, only with a fixed-size chart (`chartSize`): the point in chart-local frame units (±1 at the chart's\n * left/right edges, v up on the same scale, ±chart height/width at its top/bottom). The function is then\n * called only for points on the chart; the surround is the placement's surround reflectance.\n */\n chartU?: number;\n chartV?: number;\n}\n/** Caller Lambertian reflectance (in [0, 1]) lit by the facade illuminant. */\nexport interface CallerReflectanceScene { kind: \"reflectance-function\"; sceneId: string; evaluate(point: Readonly<ScenePlanePoint>): number }\n/** Caller absolute spectral radiance in W·m⁻²·sr⁻¹·nm⁻¹; the facade illuminant is not used. */\nexport interface CallerRadianceScene { kind: \"radiance-function\"; sceneId: string; evaluate(point: Readonly<ScenePlanePoint>): number }\n\nexport interface PlanarSceneGeometry {\n distanceM: number;\n /** Metres per frame unit on the plane (half the framed width). */\n metresPerFrameUnit: number;\n /**\n * 2.3, opt-in fixed-size chart: the chart is `widthM` × `heightM` on the plane, centred on the optical axis;\n * outside it the plane is a neutral Lambertian surround of `surroundReflectance`, lit by the same illuminant.\n * A chart preset is then resolved in its own frame (aspect heightM / widthM). Without it the chart fills the frame.\n */\n chart?: { widthM: number; heightM: number; surroundReflectance: number };\n}\n\nexport interface PlanarSceneRadianceProvider {\n sceneId: string;\n providerProfileId: string;\n evaluateRadiance(request: Readonly<SceneRadianceEvaluationRequest>): SceneRadianceEvaluationResult;\n evaluateApertureRadiance(request: Readonly<SceneRadianceEvaluationRequest>, ray: Readonly<SensorApertureRay>): SceneRadianceEvaluationResult;\n /** Spectral radiance at a plane point (frame units), the same value the callbacks return. */\n radianceAt(u: number, v: number, wavelengthNanometers: number): number;\n /**\n * 2.3, chart scenes only: the chart material at a plane point (frame units), or `materials.length` for the\n * surround of a fixed-size chart; `materialRadiance` gives that material's spectral radiance, the same value\n * `radianceAt` returns at its points.\n */\n chartMaterialAt?(u: number, v: number): number;\n materialRadiance?(material: number, wavelengthNanometers: number): number;\n}\n\nconst UNCERTAINTY = Object.freeze({ kind: \"not-quantified\" as const, limitation: \"Analytic planar Lambertian scene; no measured scene, BRDF or illumination.\" });\n\n/**\n * Wraps a chart or caller scene as a provider for the native environment RAW task. `irradianceScale` is\n * from {@link calculateIlluminantIrradianceScale}; caller radiance scenes ignore the illuminant.\n */\nexport function buildPlanarSceneRadianceProvider(input: {\n scene: ResolvedChartScene | CallerReflectanceScene | CallerRadianceScene;\n sceneId: string;\n providerProfileId: string;\n illuminant: ResolvedCaptureIlluminant;\n irradianceScale: number;\n geometry: PlanarSceneGeometry;\n evidence: readonly EvidenceProvenance[];\n limitations: readonly string[];\n}): PlanarSceneRadianceProvider {\n const { scene, illuminant, irradianceScale, geometry } = input;\n const scale = geometry.metresPerFrameUnit, distance = geometry.distanceM, sceneId = input.sceneId, providerProfileId = input.providerProfileId;\n const evidence = input.evidence, limitations = input.limitations;\n const caller = \"kind\" in scene ? scene : undefined, chart = caller ? undefined : scene as ResolvedChartScene;\n const placed = geometry.chart, half = placed ? placed.widthM / 2 : 0, chartAspect = placed ? placed.heightM / placed.widthM : 0;\n function radianceAt(u: number, v: number, nm: number): number {\n if (placed) {\n // Fixed-size chart (2.3): chart-local frame units from the plane point in metres.\n const xM = u * scale, yM = v * scale, cu = xM / half, cv = yM / half;\n if (!(Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect)) return placed.surroundReflectance * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;\n if (chart) return chart.reflectanceAt(cu, cv, nm) * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;\n return callerValue(Object.freeze({ xM, yM, u, v, wavelengthNanometers: nm, chartU: cu, chartV: cv }), nm);\n }\n if (chart) return chart.reflectanceAt(u, v, nm) * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;\n return callerValue(Object.freeze({ xM: u * scale, yM: v * scale, u, v, wavelengthNanometers: nm }), nm);\n }\n function callerValue(point: Readonly<ScenePlanePoint>, nm: number): number {\n const value = caller!.evaluate(point);\n if (caller!.kind === \"reflectance-function\") {\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < 0 || value > 1) throw new InvalidConfigurationError(\"Scene reflectance function must return a value in [0, 1].\");\n return value * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;\n }\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) throw new InvalidConfigurationError(\"Scene radiance function must return a finite non-negative radiance.\");\n return value;\n }\n function result(request: Readonly<SceneRadianceEvaluationRequest>, radiance: number): SceneRadianceEvaluationResult {\n return { schemaVersion: \"0.1.0\", sampleId: request.sampleId, sceneId, providerProfileId, wavelengthNanometers: request.wavelengthNanometers,\n wavelengthBasis: request.wavelengthBasis as SceneRadianceEvaluationResult[\"wavelengthBasis\"], quantity: \"outgoing-spectral-radiance\", unit: \"W/m^2/sr/nm\",\n spectralRadianceWattsPerSquareMeterSteradianNanometer: radiance, scientificStatus: \"approximation\", uncertainty: UNCERTAINTY, evidence, limitations };\n }\n const chartAccess = chart ? {\n chartMaterialAt(u: number, v: number): number {\n if (!placed) return chart.materialAt(u, v);\n const cu = u * scale / half, cv = v * scale / half;\n return Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect ? chart.materialAt(cu, cv) : chart.materials.length;\n },\n materialRadiance(material: number, nm: number): number {\n const m = chart.materials[material];\n let value: number;\n if (m === undefined) value = placed ? placed.surroundReflectance : NaN;\n else if (m.kind === \"neutral\") value = m.reflectance;\n else {\n value = m.spectrum.evaluate(nm);\n if (!(value >= 0 && value <= 1)) throw new InvalidConfigurationError(\"Chart reflectance spectrum left [0, 1].\");\n }\n if (!(value >= 0)) throw new InvalidConfigurationError(\"Unknown chart material.\");\n return value * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;\n }\n } : {};\n return {\n sceneId, providerProfileId, radianceAt, ...chartAccess,\n evaluateRadiance(request): SceneRadianceEvaluationResult {\n const target = request.target;\n if (target.kind !== \"environment-direction\") throw new InvalidConfigurationError(\"Planar scene provider needs environment-direction queries.\");\n const o = target.outgoingDirectionUnitVector, lz = -o.z;\n if (!(lz > 0)) throw new InvalidConfigurationError(\"Planar scene query does not point toward the scene plane.\");\n const t = distance / lz;\n return result(request, radianceAt(-o.x * t / scale, -o.y * t / scale, request.wavelengthNanometers));\n },\n evaluateApertureRadiance(request, ray): SceneRadianceEvaluationResult {\n const d = ray.directionUnitVector, origin = ray.originM;\n if (!(d.z > 0)) throw new InvalidConfigurationError(\"Planar scene pupil ray does not point toward the scene plane.\");\n const t = (distance - origin.z) / d.z;\n return result(request, radianceAt((origin.x + d.x * t) / scale, (origin.y + d.y * t) / scale, request.wavelengthNanometers));\n }\n };\n}\n\n/** 2.3: a chart's physical size on the scene plane (`simulateCapture` `chartSize`, `createPlanarSceneRadianceProvider` `chartSize`). */\nexport interface ChartSizeOption {\n /** Chart width in metres, (0, 10 000]. */\n widthM: number;\n /** Chart height in metres. Default: widthM × the frame aspect (height / width), so the chart has the frame's shape. */\n heightM?: number;\n /** Neutral reflectance of the plane around the chart, lit by the same illuminant. Default 0.18. */\n surroundReflectance?: number;\n}\n/** Default surround of a fixed-size chart: an 18 % grey plane. */\nexport const CHART_SIZE_DEFAULT_SURROUND_REFLECTANCE = 0.18;\n/** Internal: validates a chart size and fills its defaults; `defaulted` names the fields taken from defaults. */\nexport function resolveChartSizeOption(value: unknown, frameAspect: number): { widthM: number; heightM: number; surroundReflectance: number; defaulted: (\"heightM\" | \"surroundReflectance\")[] } {\n requireInputObject(value, \"chartSize\");\n const record = value as Record<string, unknown>;\n for (const key of Object.keys(record)) if (![\"widthM\", \"heightM\", \"surroundReflectance\"].includes(key)) throw new InvalidConfigurationError(\"Unknown chartSize field: \" + key + \".\");\n const size = (x: unknown, name: string): number => {\n if (typeof x !== \"number\" || !Number.isFinite(x) || x <= 0 || x > 10_000) throw new InvalidConfigurationError(\"chartSize.\" + name + \" must be a positive number of metres up to 10000.\");\n return x;\n };\n const defaulted: (\"heightM\" | \"surroundReflectance\")[] = [];\n const widthM = size(record.widthM, \"widthM\");\n const heightM = record.heightM === undefined ? (defaulted.push(\"heightM\"), widthM * frameAspect) : size(record.heightM, \"heightM\");\n const surround = record.surroundReflectance === undefined ? (defaulted.push(\"surroundReflectance\"), CHART_SIZE_DEFAULT_SURROUND_REFLECTANCE) : record.surroundReflectance;\n if (typeof surround !== \"number\" || !Number.isFinite(surround) || surround < 0 || surround > 1) throw new InvalidConfigurationError(\"chartSize.surroundReflectance must be a reflectance in [0, 1].\");\n return { widthM, heightM, surroundReflectance: surround, defaulted };\n}\n\n/**\n * Public scene-preset provider. Places an engine chart (or a caller reflectance or radiance function) on\n * a plane `distanceM` in front of the camera and `framedWidthM` wide (frame units u = ±1 at its edges),\n * lit by `illuminant` at `illuminanceLux`. The returned `evaluateRadiance` and `evaluateApertureRadiance`\n * follow the native environment RAW provider contract. They answer requests for scene `sceneId` and\n * provider `providerProfileId`.\n */\nexport function createPlanarSceneRadianceProvider(input: {\n scene: ChartScene | CallerReflectanceScene | CallerRadianceScene;\n illuminant: CaptureIlluminant;\n illuminanceLux: number;\n distanceM: number;\n framedWidthM: number;\n /** Frame height / width. */\n aspect: number;\n sceneId: string;\n providerProfileId: string;\n /**\n * 2.3, opt-in: place the chart at this physical size, centred, instead of filling the frame; the chart preset\n * is resolved with aspect heightM / widthM and the rest of the plane is the surround.\n */\n chartSize?: ChartSizeOption;\n}): PlanarSceneRadianceProvider & { chart: ResolvedChartScene | null } {\n requireInputObject(input, \"createPlanarSceneRadianceProvider input\");\n const keys = [\"scene\", \"illuminant\", \"illuminanceLux\", \"distanceM\", \"framedWidthM\", \"aspect\", \"sceneId\", \"providerProfileId\", \"chartSize\"];\n for (const key of Object.keys(input)) if (!keys.includes(key)) throw new InvalidConfigurationError(\"createPlanarSceneRadianceProvider input has unknown field \\\"\" + key + \"\\\".\");\n for (const key of [\"illuminanceLux\", \"distanceM\", \"framedWidthM\", \"aspect\"] as const) {\n const value = input[key];\n if (typeof value !== \"number\" || !Number.isFinite(value) || value <= 0) throw new InvalidConfigurationError(key + \" must be a positive finite number.\");\n }\n for (const key of [\"sceneId\", \"providerProfileId\"] as const) if (typeof input[key] !== \"string\" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(input[key])) throw new InvalidConfigurationError(key + \" must be a public opaque ID.\");\n requireInputObject(input.scene, \"scene\");\n const caller = \"kind\" in input.scene ? requireCallerScene(input.scene) : undefined;\n const size = input.chartSize === undefined ? undefined : resolveChartSizeOption(input.chartSize, input.aspect);\n const chart = caller ? null : resolveChartScene({ scene: input.scene as ChartScene, aspect: size ? size.heightM / size.widthM : input.aspect });\n const illuminant = resolveCaptureIlluminant(input.illuminant);\n const provider = buildPlanarSceneRadianceProvider({ scene: chart ?? caller!, sceneId: input.sceneId, providerProfileId: input.providerProfileId, illuminant,\n irradianceScale: calculateIlluminantIrradianceScale(illuminant.shape, input.illuminanceLux),\n geometry: { distanceM: input.distanceM, metresPerFrameUnit: input.framedWidthM / 2,\n ...(size ? { chart: { widthM: size.widthM, heightM: size.heightM, surroundReflectance: size.surroundReflectance } } : {}) },\n evidence: [{ sourceOrigin: \"photivra\", sourceReference: \"photivra:planar-scene-provider\", reuseStatus: \"photivra-owned\" }],\n limitations: [\"Planar Lambertian scene under uniform illumination; no shadows, inter-reflection, gloss or fluorescence.\"] });\n return { ...provider, chart };\n}\n\n/** Validates a caller scene function record. */\nexport function requireCallerScene(value: unknown): CallerReflectanceScene | CallerRadianceScene {\n requireInputObject(value, \"scene\");\n const record = value as Record<string, unknown>;\n for (const key of Object.keys(record)) if (key !== \"kind\" && key !== \"sceneId\" && key !== \"evaluate\") throw new InvalidConfigurationError(\"Unknown scene field: \" + key + \".\");\n if ((record.kind !== \"reflectance-function\" && record.kind !== \"radiance-function\") || typeof record.evaluate !== \"function\" ||\n typeof record.sceneId !== \"string\" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/.test(record.sceneId)) throw new InvalidConfigurationError(\"A caller scene needs kind, a public sceneId and an evaluate function.\");\n return record as unknown as CallerReflectanceScene |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IAAI,KAAK,sBAAsB,IAAI,MAAM,CAAC,IAAI,KAAK,mBAAmB,CAAC,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU;QAC1H,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,oCAAoC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,yBAAyB,CAAC,uEAAuE,CAAC,CAAC;IACjN,OAAO,MAAiE,CAAC;AAC3E,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Turns a facade scene and an illuminant into a scene radiance provider for the existing native\n * environment RAW contract (`NativeEnvironmentRawProvider.evaluateRadiance` and, for pupil sampling,\n * `evaluateApertureRadiance`). The scene is an engine chart, a caller reflectance function or a caller\n * radiance function.\n *\n * Geometry: one plane perpendicular to the optical axis at `distanceM` in front of the camera. A query's\n * outgoing direction o (scene toward camera, see docs/SENSOR_ENVIRONMENT_QUERY.md) gives the look\n * direction l = -o; the plane point is l·distanceM/l.z. With a pupil ray, the plane point is the ray from\n * its lens origin to z = distanceM.\n *\n * Radiometry: a Lambertian reflector of reflectance ρ(λ) under irradiance E(λ) has radiance\n * L(λ) = ρ(λ)·E(λ)/π (W·m⁻²·sr⁻¹·nm⁻¹). The illuminant spectral shape S(λ) is scaled so that the\n * plane illuminance is E_v = K_m ∫ E(λ) V(λ) dλ with K_m = 683 lm/W (CIE photometric definition) and\n * V(λ) = ȳ(λ) from the engine's analytic CIE 1931 fit. The light is uniform\n * over the plane, with no shadows. Inter-reflection, gloss and fluorescence are not modelled.\n * @see docs/QUICK_START.md\n */\n\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { requireInputObject } from \"../core/record-validation.js\";\nimport { estimateCie1931ColorMatchingFunctions, prepareColorimetricSpectrum, type ColorimetricSpectrum,\n type PreparedColorimetricSpectrum } from \"../color/color-matching-functions.js\";\nimport { createCieIlluminantASpectrum, createCieDaylightSpectrum, createPlanckianSpectrum, createPortableCieDaylightSpectrum, createPortableCieIlluminantASpectrum,\n createPortablePlanckianSpectrum, type CieDaylightBasis } from \"../color/illuminants.js\";\nimport type { SceneRadianceEvaluationRequest, SceneRadianceEvaluationResult } from \"../schema/scene-radiance.js\";\nimport type { EvidenceProvenance } from \"../core/evidence-provenance.js\";\nimport type { SensorApertureRay } from \"../optics/sensor-aperture-rays.js\";\nimport { resolveChartMaterial, resolveChartScene, type ChartReflectance, type ChartScene, type ResolvedChartScene } from \"./chart-scenes.js\";\n\n/** CIE maximum luminous efficacy for photopic vision, lm/W. */\nexport const PHOTOPIC_MAXIMUM_LUMINOUS_EFFICACY_LM_PER_W = 683;\n/** Wavelength range of every facade spectrum and of the facade sensor quadrature, nm. */\nexport const FACADE_SPECTRAL_RANGE_NANOMETERS = Object.freeze({ minimum: 380, maximum: 780 });\n\n/**\n * Illuminant choices. CIE D65 is not bundled: its S0/S1/S2 basis tables must come from the caller\n * (`daylight`). `planckian` is Planck's law; `cie-a` is CIE illuminant A from its defining formula.\n */\nexport type CaptureIlluminant =\n | \"cie-a\"\n | { kind: \"planckian\"; temperatureKelvin: number }\n | { kind: \"cie-a\" }\n | { kind: \"daylight\"; correlatedColorTemperatureKelvin: number; basis: CieDaylightBasis }\n | { kind: \"spectrum\"; spectrum: ColorimetricSpectrum; label?: string };\n\nexport interface ResolvedCaptureIlluminant {\n /** Short public description, for example \"planckian-6500K\". */\n id: string;\n description: string;\n /** Relative spectral shape (arbitrary scale) over at least 380-780 nm. */\n shape: PreparedColorimetricSpectrum;\n /** Original spectrum, for colorimetric white-balance calculations. */\n spectrum: ColorimetricSpectrum;\n}\n\nexport function resolveCaptureIlluminant(value: CaptureIlluminant): ResolvedCaptureIlluminant {\n return resolveIlluminant(value, CAPTURE_SPECTRA);\n}\n/**\n * The spectrum constructors of the engine's own illuminant formulas: the capture's, or the portable ones (the display view).\n * They are passed in rather than chosen inside {@link resolveIlluminant}, so a bundle that only captures does not contain the\n * portable ones.\n */\ninterface IlluminantSpectra { planckian: typeof createPlanckianSpectrum; cieA: typeof createCieIlluminantASpectrum; daylight: typeof createCieDaylightSpectrum }\nconst CAPTURE_SPECTRA: IlluminantSpectra = { planckian: createPlanckianSpectrum, cieA: createCieIlluminantASpectrum, daylight: createCieDaylightSpectrum };\n/**\n * Internal (not exported from the package): {@link resolveCaptureIlluminant} with the engine's own formulas (Planckian,\n * CIE A, daylight locus) evaluated with the portable power and e^x − 1 (`portablePow`, `portableExpm1`), so the spectrum\n * has the same bits in every JavaScript engine. The display view uses it; captures keep {@link resolveCaptureIlluminant}.\n * A caller spectrum is the caller's own.\n */\nexport function resolvePortableCaptureIlluminant(value: CaptureIlluminant): ResolvedCaptureIlluminant {\n return resolveIlluminant(value, { planckian: createPortablePlanckianSpectrum, cieA: createPortableCieIlluminantASpectrum, daylight: createPortableCieDaylightSpectrum });\n}\nfunction resolveIlluminant(value: CaptureIlluminant, spectra: IlluminantSpectra): ResolvedCaptureIlluminant {\n if (value === \"cie-a\") return resolveIlluminant({ kind: \"cie-a\" }, spectra);\n requireInputObject(value, \"illuminant\");\n const record = value as unknown as Record<string, unknown>;\n const allowed: Record<string, readonly string[]> = { planckian: [\"kind\", \"temperatureKelvin\"], \"cie-a\": [\"kind\"],\n daylight: [\"kind\", \"correlatedColorTemperatureKelvin\", \"basis\"], spectrum: [\"kind\", \"spectrum\", \"label\"] };\n const keys = typeof record.kind === \"string\" ? allowed[record.kind] : undefined;\n if (!keys) throw new InvalidConfigurationError(\"Unknown illuminant kind.\");\n for (const key of Object.keys(record)) if (!keys.includes(key)) throw new InvalidConfigurationError(\"Unknown illuminant field: \" + key + \".\");\n let spectrum: ColorimetricSpectrum, id: string, description: string;\n try {\n switch (value.kind) {\n case \"planckian\": {\n const t = value.temperatureKelvin;\n if (typeof t !== \"number\" || !Number.isFinite(t) || t < 1000 || t > 25000) throw new InvalidConfigurationError(\"Planckian temperature must be 1000-25000 K.\");\n spectrum = spectra.planckian({ temperatureKelvin: t, wavelengthRangeNanometers: { ...FACADE_SPECTRAL_RANGE_NANOMETERS } });\n id = \"planckian-\" + t + \"K\"; description = \"Planck blackbody spectrum at \" + t + \" K (Planck's law).\";\n break;\n }\n case \"cie-a\":\n spectrum = spectra.cieA(); id = \"cie-a\"; description = \"CIE standard illuminant A from its defining formula: Planck's law with c2 = 1.435e-2 m·K and T = 2848 K, 100 at 560 nm.\";\n break;\n case \"daylight\":\n spectrum = spectra.daylight({ correlatedColorTemperatureKelvin: value.correlatedColorTemperatureKelvin, coefficientRounding: \"cie-three-decimals\", basis: value.basis });\n id = \"cie-daylight-\" + value.correlatedColorTemperatureKelvin + \"K\"; description = \"CIE daylight from the caller's S0/S1/S2 basis (\" + value.basis.datasetId + \").\";\n break;\n case \"spectrum\":\n spectrum = value.spectrum; id = \"caller-spectrum\";\n description = \"Caller illuminant spectrum\" + (typeof value.label === \"string\" ? \" (\" + value.label + \")\" : \"\") + \".\";\n break;\n }\n } catch (error) {\n if (error instanceof InvalidConfigurationError) throw error;\n throw new InvalidConfigurationError(\"Invalid illuminant: \" + (error instanceof Error ? error.message : \"invalid\"));\n }\n let shape: PreparedColorimetricSpectrum;\n try { shape = prepareColorimetricSpectrum(spectrum, \"illuminant\"); } catch (error) {\n throw new InvalidConfigurationError(\"Invalid illuminant spectrum: \" + (error instanceof Error ? error.message : \"invalid\"));\n }\n const range = shape.wavelengthRangeNanometers;\n if (range.minimum > FACADE_SPECTRAL_RANGE_NANOMETERS.minimum || range.maximum < FACADE_SPECTRAL_RANGE_NANOMETERS.maximum)\n throw new InvalidConfigurationError(\"The illuminant spectrum must cover 380-780 nm.\");\n for (let nm = FACADE_SPECTRAL_RANGE_NANOMETERS.minimum; nm <= FACADE_SPECTRAL_RANGE_NANOMETERS.maximum; nm += 1) {\n const s = shape.evaluate(nm);\n if (!(s >= 0)) throw new InvalidConfigurationError(\"The illuminant spectrum must be non-negative over 380-780 nm.\");\n }\n return Object.freeze({ id, description, shape, spectrum });\n}\n\n/**\n * Factor k such that k·S(λ) (W·m⁻²·nm⁻¹) gives `illuminanceLux` on the plane: E_v = 683 ∫ k S ȳ dλ,\n * integrated with the 1 nm trapezoid rule over 380-780 nm (ȳ outside this range is below 4e-5 of its peak).\n */\nexport function calculateIlluminantIrradianceScale(shape: PreparedColorimetricSpectrum, illuminanceLux: number): number {\n if (typeof shape !== \"object\" || shape === null || typeof shape.evaluate !== \"function\") throw new InvalidConfigurationError(\"A prepared illuminant spectrum is required.\");\n if (typeof illuminanceLux !== \"number\" || !Number.isFinite(illuminanceLux) || illuminanceLux <= 0 || illuminanceLux > 1e7)\n throw new InvalidConfigurationError(\"Illuminance must be a positive number of lux up to 1e7.\");\n let sum = 0;\n for (let nm = FACADE_SPECTRAL_RANGE_NANOMETERS.minimum; nm <= FACADE_SPECTRAL_RANGE_NANOMETERS.maximum; nm++) {\n const w = nm === FACADE_SPECTRAL_RANGE_NANOMETERS.minimum || nm === FACADE_SPECTRAL_RANGE_NANOMETERS.maximum ? 0.5 : 1;\n sum += w * shape.evaluate(nm) * estimateCie1931ColorMatchingFunctions(nm).y;\n }\n if (!(sum > 0)) throw new InvalidConfigurationError(\"The illuminant has no luminous power.\");\n return illuminanceLux / (PHOTOPIC_MAXIMUM_LUMINOUS_EFFICACY_LM_PER_W * sum);\n}\n\n/** A point of the scene plane passed to caller scene functions. */\nexport interface ScenePlanePoint {\n /** Metres on the plane, from the optical axis: +x right, +y up (as seen from the camera). */\n xM: number;\n yM: number;\n /** The same point in frame units (u = ±1 at the left/right frame edges, v up on the same scale). */\n u: number;\n v: number;\n wavelengthNanometers: number;\n /**\n * 2.3, only with a fixed-size chart (`chartSize`): the point in chart-local frame units (±1 at the chart's\n * left/right edges, v up on the same scale, ±chart height/width at its top/bottom). The function is then\n * called only for points on the chart; the surround is the placement's surround reflectance.\n */\n chartU?: number;\n chartV?: number;\n}\n/** Caller Lambertian reflectance (in [0, 1]) lit by the facade illuminant. */\nexport interface CallerReflectanceScene { kind: \"reflectance-function\"; sceneId: string; evaluate(point: Readonly<ScenePlanePoint>): number }\n/** Caller absolute spectral radiance in W·m⁻²·sr⁻¹·nm⁻¹; the facade illuminant is not used. */\nexport interface CallerRadianceScene { kind: \"radiance-function\"; sceneId: string; evaluate(point: Readonly<ScenePlanePoint>): number }\n/** 2.7: a scene-plane point without a wavelength, passed to a material scene's `materialAt`. */\nexport type SceneMaterialPoint = Omit<ScenePlanePoint, \"wavelengthNanometers\">;\n/**\n * 2.7 (#386): a piecewise-constant caller scene, lit by the facade illuminant like a reflectance function. `materials` are\n * reflectances as a chart's patches take them (a neutral number in [0, 1] or a reflectance spectrum covering 380–780 nm, at\n * most {@link CALLER_MATERIAL_SCENE_MAX_MATERIALS}); `materialAt` returns the index of the material at a plane point (an\n * integer from 0 to materials.length − 1). The radiance at a point is that material's, exactly as for a reflectance function\n * returning its reflectance, but renderers can tabulate each material once: the display view then takes the chart path.\n */\nexport interface CallerMaterialScene {\n kind: \"material-function\";\n sceneId: string;\n materials: readonly ChartReflectance[];\n materialAt(point: Readonly<SceneMaterialPoint>): number;\n}\n/** Most materials a {@link CallerMaterialScene} may list. */\nexport const CALLER_MATERIAL_SCENE_MAX_MATERIALS = 65_536;\n/** Internal: a validated material scene with its materials prepared (and the caller inputs, for the scene digest). */\nexport interface ResolvedCallerMaterialScene {\n kind: \"material-function\";\n sceneId: string;\n materials: ResolvedChartScene[\"materials\"];\n materialInputs: readonly unknown[];\n materialAt(point: Readonly<SceneMaterialPoint>): number;\n}\n/** Internal: a validated caller scene. */\nexport type ResolvedCallerScene = CallerReflectanceScene | CallerRadianceScene | ResolvedCallerMaterialScene;\n\nexport interface PlanarSceneGeometry {\n distanceM: number;\n /** Metres per frame unit on the plane (half the framed width). */\n metresPerFrameUnit: number;\n /**\n * 2.3, opt-in fixed-size chart: the chart is `widthM` × `heightM` on the plane, centred on the optical axis;\n * outside it the plane is a neutral Lambertian surround of `surroundReflectance`, lit by the same illuminant.\n * A chart preset is then resolved in its own frame (aspect heightM / widthM). Without it the chart fills the frame.\n */\n chart?: { widthM: number; heightM: number; surroundReflectance: number };\n}\n\nexport interface PlanarSceneRadianceProvider {\n sceneId: string;\n providerProfileId: string;\n evaluateRadiance(request: Readonly<SceneRadianceEvaluationRequest>): SceneRadianceEvaluationResult;\n evaluateApertureRadiance(request: Readonly<SceneRadianceEvaluationRequest>, ray: Readonly<SensorApertureRay>): SceneRadianceEvaluationResult;\n /** Spectral radiance at a plane point (frame units), the same value the callbacks return. */\n radianceAt(u: number, v: number, wavelengthNanometers: number): number;\n /**\n * 2.3, chart scenes only: the chart material at a plane point (frame units), or `materials.length` for the\n * surround of a fixed-size chart; `materialRadiance` gives that material's spectral radiance, the same value\n * `radianceAt` returns at its points.\n */\n chartMaterialAt?(u: number, v: number): number;\n materialRadiance?(material: number, wavelengthNanometers: number): number;\n}\n\nconst UNCERTAINTY = Object.freeze({ kind: \"not-quantified\" as const, limitation: \"Analytic planar Lambertian scene; no measured scene, BRDF or illumination.\" });\n\n/** Most distinct wavelengths {@link tabulatedSpectrum} keeps; later ones are evaluated on every call. */\nconst TABULATED_SPECTRUM_MAX_ENTRIES = 4096;\n\n/**\n * Internal (#385): `spectrum.evaluate` remembered per distinct wavelength. A prepared spectrum is a pure function of the\n * wavelength, so the table returns the same double the call would; renderers ask for the same few spectral nodes millions\n * of times, and the illuminant's formula (two transcendental evaluations) was about 30 % of a caller-scene display view.\n */\nexport function tabulatedSpectrum(spectrum: Readonly<PreparedColorimetricSpectrum>): (wavelengthNanometers: number) => number {\n const table = new Map<number, number>();\n return (nm) => {\n let value = table.get(nm);\n if (value === undefined) {\n value = spectrum.evaluate(nm);\n if (table.size < TABULATED_SPECTRUM_MAX_ENTRIES) table.set(nm, value);\n }\n return value;\n };\n}\n\n/**\n * Wraps a chart or caller scene as a provider for the native environment RAW task. `irradianceScale` is\n * from {@link calculateIlluminantIrradianceScale}; caller radiance scenes ignore the illuminant.\n */\nexport function buildPlanarSceneRadianceProvider(input: {\n scene: ResolvedChartScene | ResolvedCallerScene;\n sceneId: string;\n providerProfileId: string;\n illuminant: ResolvedCaptureIlluminant;\n irradianceScale: number;\n geometry: PlanarSceneGeometry;\n evidence: readonly EvidenceProvenance[];\n limitations: readonly string[];\n}): PlanarSceneRadianceProvider {\n const { scene, illuminant, irradianceScale, geometry } = input;\n const scale = geometry.metresPerFrameUnit, distance = geometry.distanceM, sceneId = input.sceneId, providerProfileId = input.providerProfileId;\n const evidence = input.evidence, limitations = input.limitations;\n const caller = \"kind\" in scene ? scene : undefined, chart = caller ? undefined : scene as ResolvedChartScene;\n const materialScene = caller?.kind === \"material-function\" ? caller : undefined, materials = chart ? chart.materials : materialScene?.materials;\n const placed = geometry.chart, half = placed ? placed.widthM / 2 : 0, chartAspect = placed ? placed.heightM / placed.widthM : 0;\n const shapeAt = tabulatedSpectrum(illuminant.shape);\n /** A material scene's material at a frame point: the caller's index, or `materials.length` for a fixed-size chart's surround. */\n function callerMaterialAt(u: number, v: number): number {\n const xM = u * scale, yM = v * scale;\n let point: SceneMaterialPoint;\n if (placed) {\n const cu = xM / half, cv = yM / half;\n if (!(Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect)) return materialScene!.materials.length;\n point = Object.freeze({ xM, yM, u, v, chartU: cu, chartV: cv });\n } else point = Object.freeze({ xM, yM, u, v });\n const index = materialScene!.materialAt(point);\n if (!Number.isInteger(index) || index < 0 || index >= materialScene!.materials.length) throw new InvalidConfigurationError(\"Scene materialAt must return an index into its materials.\");\n return index;\n }\n function radianceAt(u: number, v: number, nm: number): number {\n if (materialScene) return materialRadianceOf(callerMaterialAt(u, v), nm);\n if (placed) {\n // Fixed-size chart (2.3): chart-local frame units from the plane point in metres.\n const xM = u * scale, yM = v * scale, cu = xM / half, cv = yM / half;\n if (!(Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect)) return placed.surroundReflectance * irradianceScale * shapeAt(nm) / Math.PI;\n if (chart) return chart.reflectanceAt(cu, cv, nm) * irradianceScale * shapeAt(nm) / Math.PI;\n return callerValue(Object.freeze({ xM, yM, u, v, wavelengthNanometers: nm, chartU: cu, chartV: cv }), nm);\n }\n if (chart) return chart.reflectanceAt(u, v, nm) * irradianceScale * shapeAt(nm) / Math.PI;\n return callerValue(Object.freeze({ xM: u * scale, yM: v * scale, u, v, wavelengthNanometers: nm }), nm);\n }\n function callerValue(point: Readonly<ScenePlanePoint>, nm: number): number {\n const value = (caller as CallerReflectanceScene | CallerRadianceScene).evaluate(point);\n if (caller!.kind === \"reflectance-function\") {\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < 0 || value > 1) throw new InvalidConfigurationError(\"Scene reflectance function must return a value in [0, 1].\");\n return value * irradianceScale * shapeAt(nm) / Math.PI;\n }\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) throw new InvalidConfigurationError(\"Scene radiance function must return a finite non-negative radiance.\");\n return value;\n }\n function result(request: Readonly<SceneRadianceEvaluationRequest>, radiance: number): SceneRadianceEvaluationResult {\n return { schemaVersion: \"0.1.0\", sampleId: request.sampleId, sceneId, providerProfileId, wavelengthNanometers: request.wavelengthNanometers,\n wavelengthBasis: request.wavelengthBasis as SceneRadianceEvaluationResult[\"wavelengthBasis\"], quantity: \"outgoing-spectral-radiance\", unit: \"W/m^2/sr/nm\",\n spectralRadianceWattsPerSquareMeterSteradianNanometer: radiance, scientificStatus: \"approximation\", uncertainty: UNCERTAINTY, evidence, limitations };\n }\n /** Spectral radiance of material `material` (`materials.length`: a fixed-size chart's surround), in the chart's expression order. */\n function materialRadianceOf(material: number, nm: number): number {\n const m = materials![material];\n let value: number;\n if (m === undefined) value = placed ? placed.surroundReflectance : NaN;\n else if (m.kind === \"neutral\") value = m.reflectance;\n else {\n value = m.spectrum.evaluate(nm);\n if (!(value >= 0 && value <= 1)) throw new InvalidConfigurationError(\"Chart reflectance spectrum left [0, 1].\");\n }\n if (!(value >= 0)) throw new InvalidConfigurationError(\"Unknown chart material.\");\n return value * irradianceScale * shapeAt(nm) / Math.PI;\n }\n const chartAccess = chart ? {\n chartMaterialAt(u: number, v: number): number {\n if (!placed) return chart.materialAt(u, v);\n const cu = u * scale / half, cv = v * scale / half;\n return Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect ? chart.materialAt(cu, cv) : chart.materials.length;\n },\n materialRadiance: materialRadianceOf\n } : materialScene ? { chartMaterialAt: callerMaterialAt, materialRadiance: materialRadianceOf } : {};\n return {\n sceneId, providerProfileId, radianceAt, ...chartAccess,\n evaluateRadiance(request): SceneRadianceEvaluationResult {\n const target = request.target;\n if (target.kind !== \"environment-direction\") throw new InvalidConfigurationError(\"Planar scene provider needs environment-direction queries.\");\n const o = target.outgoingDirectionUnitVector, lz = -o.z;\n if (!(lz > 0)) throw new InvalidConfigurationError(\"Planar scene query does not point toward the scene plane.\");\n const t = distance / lz;\n return result(request, radianceAt(-o.x * t / scale, -o.y * t / scale, request.wavelengthNanometers));\n },\n evaluateApertureRadiance(request, ray): SceneRadianceEvaluationResult {\n const d = ray.directionUnitVector, origin = ray.originM;\n if (!(d.z > 0)) throw new InvalidConfigurationError(\"Planar scene pupil ray does not point toward the scene plane.\");\n const t = (distance - origin.z) / d.z;\n return result(request, radianceAt((origin.x + d.x * t) / scale, (origin.y + d.y * t) / scale, request.wavelengthNanometers));\n }\n };\n}\n\n/** 2.3: a chart's physical size on the scene plane (`simulateCapture` `chartSize`, `createPlanarSceneRadianceProvider` `chartSize`). */\nexport interface ChartSizeOption {\n /** Chart width in metres, (0, 10 000]. */\n widthM: number;\n /** Chart height in metres. Default: widthM × the frame aspect (height / width), so the chart has the frame's shape. */\n heightM?: number;\n /** Neutral reflectance of the plane around the chart, lit by the same illuminant. Default 0.18. */\n surroundReflectance?: number;\n}\n/** Default surround of a fixed-size chart: an 18 % grey plane. */\nexport const CHART_SIZE_DEFAULT_SURROUND_REFLECTANCE = 0.18;\n/** Internal: validates a chart size and fills its defaults; `defaulted` names the fields taken from defaults. */\nexport function resolveChartSizeOption(value: unknown, frameAspect: number): { widthM: number; heightM: number; surroundReflectance: number; defaulted: (\"heightM\" | \"surroundReflectance\")[] } {\n requireInputObject(value, \"chartSize\");\n const record = value as Record<string, unknown>;\n for (const key of Object.keys(record)) if (![\"widthM\", \"heightM\", \"surroundReflectance\"].includes(key)) throw new InvalidConfigurationError(\"Unknown chartSize field: \" + key + \".\");\n const size = (x: unknown, name: string): number => {\n if (typeof x !== \"number\" || !Number.isFinite(x) || x <= 0 || x > 10_000) throw new InvalidConfigurationError(\"chartSize.\" + name + \" must be a positive number of metres up to 10000.\");\n return x;\n };\n const defaulted: (\"heightM\" | \"surroundReflectance\")[] = [];\n const widthM = size(record.widthM, \"widthM\");\n const heightM = record.heightM === undefined ? (defaulted.push(\"heightM\"), widthM * frameAspect) : size(record.heightM, \"heightM\");\n const surround = record.surroundReflectance === undefined ? (defaulted.push(\"surroundReflectance\"), CHART_SIZE_DEFAULT_SURROUND_REFLECTANCE) : record.surroundReflectance;\n if (typeof surround !== \"number\" || !Number.isFinite(surround) || surround < 0 || surround > 1) throw new InvalidConfigurationError(\"chartSize.surroundReflectance must be a reflectance in [0, 1].\");\n return { widthM, heightM, surroundReflectance: surround, defaulted };\n}\n\n/**\n * Public scene-preset provider. Places an engine chart (or a caller reflectance or radiance function) on\n * a plane `distanceM` in front of the camera and `framedWidthM` wide (frame units u = ±1 at its edges),\n * lit by `illuminant` at `illuminanceLux`. The returned `evaluateRadiance` and `evaluateApertureRadiance`\n * follow the native environment RAW provider contract. They answer requests for scene `sceneId` and\n * provider `providerProfileId`.\n */\nexport function createPlanarSceneRadianceProvider(input: {\n scene: ChartScene | CallerReflectanceScene | CallerRadianceScene | CallerMaterialScene;\n illuminant: CaptureIlluminant;\n illuminanceLux: number;\n distanceM: number;\n framedWidthM: number;\n /** Frame height / width. */\n aspect: number;\n sceneId: string;\n providerProfileId: string;\n /**\n * 2.3, opt-in: place the chart at this physical size, centred, instead of filling the frame; the chart preset\n * is resolved with aspect heightM / widthM and the rest of the plane is the surround.\n */\n chartSize?: ChartSizeOption;\n}): PlanarSceneRadianceProvider & { chart: ResolvedChartScene | null } {\n requireInputObject(input, \"createPlanarSceneRadianceProvider input\");\n const keys = [\"scene\", \"illuminant\", \"illuminanceLux\", \"distanceM\", \"framedWidthM\", \"aspect\", \"sceneId\", \"providerProfileId\", \"chartSize\"];\n for (const key of Object.keys(input)) if (!keys.includes(key)) throw new InvalidConfigurationError(\"createPlanarSceneRadianceProvider input has unknown field \\\"\" + key + \"\\\".\");\n for (const key of [\"illuminanceLux\", \"distanceM\", \"framedWidthM\", \"aspect\"] as const) {\n const value = input[key];\n if (typeof value !== \"number\" || !Number.isFinite(value) || value <= 0) throw new InvalidConfigurationError(key + \" must be a positive finite number.\");\n }\n for (const key of [\"sceneId\", \"providerProfileId\"] as const) if (typeof input[key] !== \"string\" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(input[key])) throw new InvalidConfigurationError(key + \" must be a public opaque ID.\");\n requireInputObject(input.scene, \"scene\");\n const caller = \"kind\" in input.scene ? requireCallerScene(input.scene) : undefined;\n const size = input.chartSize === undefined ? undefined : resolveChartSizeOption(input.chartSize, input.aspect);\n const chart = caller ? null : resolveChartScene({ scene: input.scene as ChartScene, aspect: size ? size.heightM / size.widthM : input.aspect });\n const illuminant = resolveCaptureIlluminant(input.illuminant);\n const provider = buildPlanarSceneRadianceProvider({ scene: chart ?? caller!, sceneId: input.sceneId, providerProfileId: input.providerProfileId, illuminant,\n irradianceScale: calculateIlluminantIrradianceScale(illuminant.shape, input.illuminanceLux),\n geometry: { distanceM: input.distanceM, metresPerFrameUnit: input.framedWidthM / 2,\n ...(size ? { chart: { widthM: size.widthM, heightM: size.heightM, surroundReflectance: size.surroundReflectance } } : {}) },\n evidence: [{ sourceOrigin: \"photivra\", sourceReference: \"photivra:planar-scene-provider\", reuseStatus: \"photivra-owned\" }],\n limitations: [\"Planar Lambertian scene under uniform illumination; no shadows, inter-reflection, gloss or fluorescence.\"] });\n return { ...provider, chart };\n}\n\n/** Validates a caller scene record (a function scene as given; a material scene with its materials prepared). */\nexport function requireCallerScene(value: unknown): ResolvedCallerScene {\n requireInputObject(value, \"scene\");\n const record = value as Record<string, unknown>;\n if (record.kind === \"material-function\") {\n for (const key of Object.keys(record)) if (key !== \"kind\" && key !== \"sceneId\" && key !== \"materials\" && key !== \"materialAt\") throw new InvalidConfigurationError(\"Unknown scene field: \" + key + \".\");\n if (typeof record.materialAt !== \"function\" || typeof record.sceneId !== \"string\" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/.test(record.sceneId) ||\n !Array.isArray(record.materials) || record.materials.length < 1 || record.materials.length > CALLER_MATERIAL_SCENE_MAX_MATERIALS)\n throw new InvalidConfigurationError(\"A material scene needs a public sceneId, 1 to \" + CALLER_MATERIAL_SCENE_MAX_MATERIALS + \" materials and a materialAt function.\");\n const inputs = [...record.materials as unknown[]];\n return Object.freeze({ kind: \"material-function\" as const, sceneId: record.sceneId, materialAt: record.materialAt as ResolvedCallerMaterialScene[\"materialAt\"],\n materials: Object.freeze(inputs.map((m, index) => resolveChartMaterial(m, \"scene.materials[\" + index + \"]\"))),\n materialInputs: Object.freeze(inputs.map((m) => (typeof m === \"number\" ? undefined : m))) });\n }\n for (const key of Object.keys(record)) if (key !== \"kind\" && key !== \"sceneId\" && key !== \"evaluate\") throw new InvalidConfigurationError(\"Unknown scene field: \" + key + \".\");\n if ((record.kind !== \"reflectance-function\" && record.kind !== \"radiance-function\") || typeof record.evaluate !== \"function\" ||\n typeof record.sceneId !== \"string\" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/.test(record.sceneId)) throw new InvalidConfigurationError(\"A caller scene needs kind, a public sceneId and an evaluate function.\");\n return record as unknown as CallerReflectanceScene | CallerRadianceScene;\n}\n"]}
@@ -19,7 +19,7 @@ import type { CalculateEnvironmentSensorPhotoSignalInput } from "../sensor/envir
19
19
  import { type DiffractionLimitedPsfProfile } from "../optics/diffraction-psf-profile.js";
20
20
  import { type AntiAliasingPointSplitComponent } from "../sensor/optical-stack.js";
21
21
  import { type ChartScene, type ResolvedChartScene } from "./chart-scenes.js";
22
- import { type ChartSizeOption, type CaptureIlluminant, type CallerRadianceScene, type CallerReflectanceScene, type PlanarSceneRadianceProvider, type ResolvedCaptureIlluminant } from "./scene-radiance.js";
22
+ import { type ChartSizeOption, type CaptureIlluminant, type CallerMaterialScene, type CallerRadianceScene, type CallerReflectanceScene, type ResolvedCallerScene, type PlanarSceneRadianceProvider, type ResolvedCaptureIlluminant } from "./scene-radiance.js";
23
23
  /** Version of how the facade builds requests. It changes whenever the same input would build a different request. */
24
24
  export declare const SIMULATE_CAPTURE_FACADE_VERSION: "1.0.0";
25
25
  export type SimulateCaptureExposureMode = "manual" | "aperture-priority" | "shutter-priority" | "program";
@@ -163,7 +163,7 @@ export interface SimulateCaptureOptions {
163
163
  compensationStops?: number;
164
164
  };
165
165
  /** Required: an engine chart (for example `{ preset: "uniform" }`, an 18 % grey card) or a caller reflectance/radiance function. */
166
- scene: ChartScene | CallerReflectanceScene | CallerRadianceScene;
166
+ scene: ChartScene | CallerReflectanceScene | CallerRadianceScene | CallerMaterialScene;
167
167
  /** Distance from the camera to the scene plane in metres. Default 5. */
168
168
  subjectDistanceM?: number;
169
169
  /**
@@ -483,6 +483,7 @@ export declare function fail(message: string): never;
483
483
  type ReadoutProfile = GenericEquipmentTierPreset["body"]["readout"][number]["profile"];
484
484
  /** Diagnostic clock for the 2.1 stage timings: `performance.now()` where the host has it. Never affects output. */
485
485
  export declare function clockMs(): number;
486
+ export declare function allowKeys(value: unknown, name: string, keys: readonly string[]): Record<string, unknown>;
486
487
  /** The white balance measured from a perfect white diffuser under the scene illuminant ("scene-illuminant"). */
487
488
  export declare function sceneIlluminantWhiteBalance(illuminant: ResolvedCaptureIlluminant): ResolvedWhiteBalanceState;
488
489
  /** Bilinear RGGB demosaic as explicit linear neighbourhood kernels (weights sum to one per output channel). */
@@ -659,7 +660,7 @@ export interface DisplayViewRunContext {
659
660
  };
660
661
  boxSamples: number;
661
662
  buildProvider: (sceneIlluminant: ResolvedCaptureIlluminant, scale: number) => PlanarSceneRadianceProvider;
662
- callerScene: CallerReflectanceScene | CallerRadianceScene | undefined;
663
+ callerScene: ResolvedCallerScene | undefined;
663
664
  chart: ResolvedChartScene | undefined;
664
665
  chartReport: {
665
666
  widthM: number;
@@ -710,7 +711,7 @@ export interface DisplayViewRunContext {
710
711
  }>;
711
712
  resolvedIso: number;
712
713
  sceneOption: unknown;
713
- scenePreset: "composite" | "uniform" | "patches" | "slanted-edge" | "siemens-star" | "step-wedge" | "grey-ramp" | "checkerboard" | "point-grid" | "dead-leaves" | "bar-groups" | "hyperbolic-wedge" | "zone-plate" | "slanted-squares" | "line-grid" | "fiducial" | "reflectance-function" | "radiance-function";
714
+ scenePreset: "composite" | "uniform" | "patches" | "slanted-edge" | "siemens-star" | "step-wedge" | "grey-ramp" | "checkerboard" | "point-grid" | "dead-leaves" | "bar-groups" | "hyperbolic-wedge" | "zone-plate" | "slanted-squares" | "line-grid" | "fiducial" | "reflectance-function" | "radiance-function" | "material-function";
714
715
  shutterSeconds: number;
715
716
  started: number;
716
717
  subjectDistanceM: number;
@@ -741,8 +742,15 @@ export interface ParsedDisplayView {
741
742
  height: number;
742
743
  };
743
744
  }
744
- /** Internal: the request path shared by {@link simulateCapture}, {@link simulateIdealReference} and the display view, whose renderer is passed in. */
745
- export declare function runCapture(options: SimulateCaptureOptions, run: "capture" | "ideal-reference" | "display-view", viewOption?: unknown, renderView?: (context: DisplayViewRunContext) => Promise<DisplayViewResult>): Promise<SimulateCaptureResult | IdealReferenceResult | DisplayViewResult>;
745
+ /** Internal: validates a display view against the capture's output size and fills its defaults. */
746
+ export declare function parseDisplayViewOption(value: unknown, frameWidth: number, frameHeight: number): ParsedDisplayView;
747
+ /** Internal: passed as the view of a "display-view" run to resolve the request without a view (`prepareDisplayView`, #387). */
748
+ export declare const DISPLAY_VIEW_WITHOUT_VIEW: unique symbol;
749
+ /**
750
+ * Internal: the request path shared by {@link simulateCapture}, {@link simulateIdealReference} and the display view, whose renderer is
751
+ * passed in; for a display view the renderer's value is returned (a result, or a prepared view with DISPLAY_VIEW_WITHOUT_VIEW).
752
+ */
753
+ export declare function runCapture(options: SimulateCaptureOptions, run: "capture" | "ideal-reference" | "display-view", viewOption?: unknown, renderView?: (context: DisplayViewRunContext) => Promise<unknown>): Promise<unknown>;
746
754
  /** Chart preset ids accepted by `simulateCapture({ scene: { preset } })`. */
747
755
  export declare const SIMULATE_CAPTURE_CHART_PRESETS: readonly ("composite" | "uniform" | "patches" | "slanted-edge" | "siemens-star" | "step-wedge" | "grey-ramp" | "checkerboard" | "point-grid" | "dead-leaves" | "bar-groups" | "hyperbolic-wedge" | "zone-plate" | "slanted-squares" | "line-grid" | "fiducial")[];
748
756
  export {};
@@ -242,7 +242,7 @@ function integerIn(value, name, minimum, maximum) {
242
242
  fail(name + " must be an integer from " + minimum + " to " + maximum + ".");
243
243
  return value;
244
244
  }
245
- function allowKeys(value, name, keys) {
245
+ export function allowKeys(value, name, keys) {
246
246
  if (value === undefined)
247
247
  return {};
248
248
  requireInputObject(value, name);
@@ -493,7 +493,8 @@ export async function simulateIdealReference(options) {
493
493
  }
494
494
  /** Default stratified samples per axis of a display view (`view.samplesPerAxis`): 16 × 16 sampled real pixels per display pixel with detail, 4 × 4 where it is uniform. */
495
495
  export const SIMULATE_DISPLAY_VIEW_DEFAULT_SAMPLES_PER_AXIS = 16;
496
- function parseDisplayViewOption(value, frameWidth, frameHeight) {
496
+ /** Internal: validates a display view against the capture's output size and fills its defaults. */
497
+ export function parseDisplayViewOption(value, frameWidth, frameHeight) {
497
498
  if (value === undefined)
498
499
  fail("simulateDisplayView needs a view, for example { width: 384, height: 256 }.");
499
500
  const v = allowKeys(value, "view", ["width", "height", "samplesPerAxis", "format", "region"]);
@@ -510,7 +511,12 @@ function parseDisplayViewOption(value, frameWidth, frameHeight) {
510
511
  }
511
512
  return { width, height, samplesPerAxis, bitDepth: format === "srgb-8" ? 8 : 16, format: format, ...(region ? { region } : {}) };
512
513
  }
513
- /** Internal: the request path shared by {@link simulateCapture}, {@link simulateIdealReference} and the display view, whose renderer is passed in. */
514
+ /** Internal: passed as the view of a "display-view" run to resolve the request without a view (`prepareDisplayView`, #387). */
515
+ export const DISPLAY_VIEW_WITHOUT_VIEW = Symbol("display view without view");
516
+ /**
517
+ * Internal: the request path shared by {@link simulateCapture}, {@link simulateIdealReference} and the display view, whose renderer is
518
+ * passed in; for a display view the renderer's value is returned (a result, or a prepared view with DISPLAY_VIEW_WITHOUT_VIEW).
519
+ */
514
520
  export async function runCapture(options, run, viewOption, renderView) {
515
521
  const started = Date.now(), idealReference = run === "ideal-reference", displayView = run === "display-view";
516
522
  requireInputObject(options, "simulateCapture options");
@@ -742,7 +748,7 @@ export async function runCapture(options, run, viewOption, renderView) {
742
748
  }
743
749
  const boxAperture = sensorOptions.pixelAperture !== undefined && sensorOptions.pixelAperture !== "point";
744
750
  // Display view: its own parameters, and the capture options it reproduces, checked before any scene work.
745
- const parsedView = displayView ? parseDisplayViewOption(viewOption, width, height) : undefined;
751
+ const parsedView = displayView && viewOption !== DISPLAY_VIEW_WITHOUT_VIEW ? parseDisplayViewOption(viewOption, width, height) : undefined;
746
752
  if (displayView) {
747
753
  const unsupported = (option, reason) => fail("simulateDisplayView does not support " + option + ": " + reason);
748
754
  if (pupil)
@@ -893,11 +899,16 @@ export async function runCapture(options, run, viewOption, renderView) {
893
899
  illuminantRecord?.kind === "daylight" ? { basisDatasetId: illuminantRecord.basis?.datasetId, spectrum: spectrumDigestForm(illuminant.spectrum, illuminant.shape) } : undefined;
894
900
  const materialInputs = chart ? chartMaterialInputs(chart) : [];
895
901
  const sceneSpectra = chart ? chart.materials.flatMap((m, index) => m.kind !== "spectrum" ? [] : [{ material: index, spectrum: spectrumDigestForm(materialInputs[index], m.spectrum) }]) : [];
902
+ // 2.7: a material scene's materials enter the digest as data (neutral reflectances, and caller spectra as above).
903
+ const sceneMaterials = callerScene?.kind === "material-function" ? callerScene.materials.map((m, index) => (m.kind === "neutral" ? m.reflectance :
904
+ spectrumDigestForm(callerScene.materialInputs[index], m.spectrum))) : undefined;
896
905
  const sceneDescription = { facadeVersion: SIMULATE_CAPTURE_FACADE_VERSION, scene: chart ? { preset: chart.preset, parameters: chart.parameters } :
897
906
  { kind: callerScene.kind, sceneId: callerScene.sceneId }, illuminant: illuminant.id, illuminanceLux, subjectDistanceM, framedWidthM: 2 * metresPerFrameUnit, aspect,
898
907
  ...(chartSize ? { chartSize: { widthM: chartSize.widthM, heightM: chartSize.heightM, surroundReflectance: chartSize.surroundReflectance } } : {}),
899
- ...(illuminantSpectrum === undefined ? {} : { illuminantSpectrum }), ...(sceneSpectra.length === 0 ? {} : { sceneSpectra }) };
900
- if (callerScene)
908
+ ...(illuminantSpectrum === undefined ? {} : { illuminantSpectrum }), ...(sceneSpectra.length === 0 ? {} : { sceneSpectra }), ...(sceneMaterials ? { sceneMaterials } : {}) };
909
+ if (callerScene?.kind === "material-function")
910
+ assume("scene.digest", "model", "caller-function-not-hashed", "The source digest covers the caller's sceneId, its materials and the framing, not the body of the caller's materialAt function.");
911
+ else if (callerScene)
901
912
  assume("scene.digest", "model", "caller-function-not-hashed", "The source digest covers the caller's sceneId and the framing, not the body of the caller's evaluate function.");
902
913
  const sourceSha256 = await sha256Hex(JSON.stringify(sceneDescription, (_key, value) => (typeof value === "object" && value !== null && "evaluate" in value ? "caller-spectrum" : value)));
903
914
  checkAbort();
@@ -1365,7 +1376,8 @@ export async function runCapture(options, run, viewOption, renderView) {
1365
1376
  return CHANNELS.map((c) => { let e = 0; for (const [nm, a] of electronsPerRadiance[c])
1366
1377
  e += a * values.get(nm); return e * relativePerElectron[c]; });
1367
1378
  };
1368
- const materialSignals = provider.chartMaterialAt ? Array.from({ length: chart.materials.length + (chartSize ? 1 : 0) }, (_, m) => signalOf((nm) => provider.materialRadiance(m, nm))) : undefined;
1379
+ const materialCount = chart ? chart.materials.length : callerScene?.kind === "material-function" ? callerScene.materials.length : 0;
1380
+ const materialSignals = provider.chartMaterialAt ? Array.from({ length: materialCount + (chartSize ? 1 : 0) }, (_, m) => signalOf((nm) => provider.materialRadiance(m, nm))) : undefined;
1369
1381
  // 4. Pixels: the native sites of the output (or region) pixels, each centre-sampled or box-integrated like the capture.
1370
1382
  const x0 = (region ? region.x : 0) + margin, y0 = (region ? region.y : 0) + margin, n = boxSamples, unit = 2 / width;
1371
1383
  const referenceIntent = intentOf(whiteBalanceState), referenceGains = referenceIntent ? [referenceIntent.channelGains.red, referenceIntent.channelGains.green, referenceIntent.channelGains.blue] : null;