@photivra/engine 2.6.0 → 2.8.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +177 -1
  2. package/CITATION.cff +1 -1
  3. package/README.md +6 -6
  4. package/SECURITY.md +1 -1
  5. package/dist/capture/native-environment-lean.d.ts +35 -5
  6. package/dist/capture/native-environment-lean.js +175 -16
  7. package/dist/capture/native-environment-lean.js.map +1 -1
  8. package/dist/capture/native-environment-raw.d.ts +9 -1
  9. package/dist/capture/native-environment-raw.js +14 -9
  10. package/dist/capture/native-environment-raw.js.map +1 -1
  11. package/dist/capture/native-environment-tabulated.d.ts +58 -0
  12. package/dist/capture/native-environment-tabulated.js +91 -0
  13. package/dist/capture/native-environment-tabulated.js.map +1 -0
  14. package/dist/core/internal-radiance-evaluator.d.ts +28 -0
  15. package/dist/core/internal-radiance-evaluator.js +30 -0
  16. package/dist/core/internal-radiance-evaluator.js.map +1 -1
  17. package/dist/core/version.d.ts +1 -1
  18. package/dist/core/version.js +1 -1
  19. package/dist/core/version.js.map +1 -1
  20. package/dist/facade/chart-radiance-batch.js +3 -2
  21. package/dist/facade/chart-radiance-batch.js.map +1 -1
  22. package/dist/facade/chart-scenes.d.ts +2 -0
  23. package/dist/facade/chart-scenes.js +4 -3
  24. package/dist/facade/chart-scenes.js.map +1 -1
  25. package/dist/facade/diffraction-provider.js +30 -2
  26. package/dist/facade/diffraction-provider.js.map +1 -1
  27. package/dist/facade/display-view.d.ts +14 -78
  28. package/dist/facade/display-view.js +322 -755
  29. package/dist/facade/display-view.js.map +1 -1
  30. package/dist/facade/expected-signal-setup.d.ts +65 -0
  31. package/dist/facade/expected-signal-setup.js +56 -0
  32. package/dist/facade/expected-signal-setup.js.map +1 -0
  33. package/dist/facade/expected-signal.d.ts +83 -0
  34. package/dist/facade/expected-signal.js +571 -0
  35. package/dist/facade/expected-signal.js.map +1 -0
  36. package/dist/facade/scene-radiance.d.ts +44 -5
  37. package/dist/facade/scene-radiance.js +107 -30
  38. package/dist/facade/scene-radiance.js.map +1 -1
  39. package/dist/facade/simulate-capture.d.ts +14 -6
  40. package/dist/facade/simulate-capture.js +84 -23
  41. package/dist/facade/simulate-capture.js.map +1 -1
  42. package/dist/facade/simulate-display-view.d.ts +24 -0
  43. package/dist/facade/simulate-display-view.js +117 -94
  44. package/dist/facade/simulate-display-view.js.map +1 -1
  45. package/dist/index.d.ts +2 -2
  46. package/dist/index.js +2 -2
  47. package/dist/index.js.map +1 -1
  48. package/docs/API_REFERENCE.md +7 -1
  49. package/docs/QUICK_START.md +49 -1
  50. package/docs/api/core-version.md +1 -1
  51. package/docs/api/exports.json +32 -2
  52. package/docs/api/facade-scene-radiance.md +34 -1
  53. package/docs/api/facade-simulate-capture.md +1 -1
  54. package/docs/api/facade-simulate-display-view.md +39 -0
  55. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expected-signal.js","sourceRoot":"","sources":["../../src/facade/expected-signal.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;GAIG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AA+D3E,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,sGAAsG;AACtG,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,CAAC;AAC5B,qIAAqI;AACrI,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,CAAC;AAE3B;;;;;;;;;GASG;AACH,MAAM,UAAU,+BAA+B,CAAC,KAAqC;IACnF,MAAM,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,KAAK,GAAG,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC;IACnH,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MA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AAO,CAAC,CAAC;gBAAC,CAAC;YAAC,CAAC;YAClI,OAAO,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC;QACD,KAAK,CAAC,CAAS,EAAE,CAAS;YACxB,OAAO,EAAE,CAAC;YACV,OAAO,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;QACjG,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * The tabulated expected signal (2.6 display view; #394 also the capture's tabulated RAW path): expected photo electrons of\n * real native sites for a still, rectilinear, distortion-free planar scene. Kept apart from display-view.ts so a bundle that\n * only captures does not contain the display view or the portable functions it uses (issue #380).\n */\n\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\n\n/** A query offset from a site centre in sites (+x right, +y down) and its weight (pixel-aperture node × filter spot). */\nexport interface DisplayViewQueryOffset { x: number; y: number; weight: number }\n\n/** Scene access for the expected signal: chart materials (fast tables) or a radiance function. */\nexport type DisplayViewScene =\n | { kind: \"materials\"; materialAt(u: number, v: number): number;\n /** Per material: `{ neutral: reflectance }` (radiance = reflectance × illuminant) or the spectral radiance at each node. */\n materials: readonly ({ neutral: number } | { radiance: Float64Array })[];\n /** Illuminant radiance of a perfect white diffuser at each spectral node: irradianceScale·shape(λ)/π. */\n whiteRadiance: Float64Array }\n | { kind: \"radiance\"; radianceAt(u: number, v: number, nm: number): number };\n\nexport interface DisplayViewExpectedSignalInput {\n nativeWidth: number;\n nativeHeight: number;\n /** Frame output width: plane coordinates are 2 / outputWidth frame units per site. */\n outputWidth: number;\n /** Spectral nodes and, per CFA channel (red, green, blue), the expected electrons per unit spectral radiance at each node. */\n wavelengthsNm: readonly number[];\n electronsPerRadiance: readonly [Float64Array, Float64Array, Float64Array];\n offsets: readonly DisplayViewQueryOffset[];\n /** Diffraction: per-node kernels on the site lattice, (2R + 1)² taps in row-major order, out(x) = Σ in(x − t)·K(t). */\n kernels?: { radius: number; perNode: readonly Float64Array[] };\n scene: DisplayViewScene;\n /** CFA channel index (0 red, 1 green, 2 blue) of native site (x, y). */\n channelAt(x: number, y: number): number;\n /**\n * Without diffraction: the plane point (frame units) that the environment queries for offset `o` of native site (x, y),\n * computed with the environment's own arithmetic, so points that fall exactly on a chart boundary resolve to the same\n * material as in the capture. With diffraction the facade's object-space convolution uses the lattice formula, as here.\n */\n queryPoint?(x: number, y: number, offset: number, out: Float64Array): void;\n}\n\n/** Expected photo electrons of real native sites. */\nexport interface DisplayViewExpectedSignal {\n /**\n * Starts a new cache window: native sites [x0, x1) × [y0, y1) that the following `site` calls mostly read. Sites and\n * scene lookups inside it are computed once; anything outside is computed without caching.\n */\n window(x0: number, y0: number, x1: number, y1: number): void;\n /** Expected photo electrons of native site (x, y) for its own CFA channel (x, y inside the native raster). */\n site(x: number, y: number): number;\n /** A cheap classifier value of the scene at plane point (u, v) frame units: the material, or the radiance at one node. */\n pilot(u: number, v: number): number;\n /** Scene lookups performed so far (material or radiance queries), for diagnostics. */\n readonly lookups: number;\n /**\n * The chart material that every kernel tap of the last `site` call read, when they all read one material (its value is\n * then a function of that material and the site's CFA channel only); −1 when unknown or mixed.\n */\n readonly uniformMaterial: number;\n /** Whether `uniformMaterial` is tracked in the current window (otherwise it is not meaningful). */\n readonly tracksMaterial: boolean;\n /**\n * Whether the current window caches its sites: a second `site` call for a site inside the window then returns the stored\n * value without any work or lookup (#392).\n */\n readonly cachesSites: boolean;\n}\n\nconst OFFSET_TOLERANCE = 1e-9;\n/** Largest cache window, in sites or lattice points; larger windows are evaluated without caching. */\nconst CACHE_LIMIT = 1 << 22;\n/** Largest band of looked-up lattice materials per group, in lattice points (a band that would be larger restarts at the window). */\nconst BAND_LIMIT = 1 << 22;\n\n/**\n * Expected photo electrons per site: μ_c(i, j) = Σ_o w_o Σ_λ A_c(λ) Σ_t K_λ(t)·L(p_o(i, j) − t, λ), where p_o is the\n * query point of offset o and K the diffraction kernel (a single unit tap without diffraction). This is the sum the\n * facade's environment chain forms for a still, rectilinear, distortion-free planar scene, where the\n * radiance-to-irradiance factor is the same at every site (docs/DISPLAY_VIEW.md, \"Expected signal\").\n *\n * With diffraction, offsets that share a fractional shift read one lattice, and their kernels are combined in advance:\n * C_c(d) = Σ_members w·Σ_λ A_c(λ)·K_λ(t)·L(λ) over the taps t that reach lattice offset d. A neutral material's radiance\n * is its reflectance times the white radiance, so all neutral materials share one combined kernel per channel.\n */\nexport function createDisplayViewExpectedSignal(input: DisplayViewExpectedSignalInput): DisplayViewExpectedSignal {\n const W = input.nativeWidth, H = input.nativeHeight, g = 2 / input.outputWidth, nodes = input.wavelengthsNm.length;\n const R = input.kernels ? input.kernels.radius : 0, size = 2 * R + 1;\n if (input.kernels && input.kernels.perNode.length !== nodes) throw new InvalidConfigurationError(\"Display view kernels must match the spectral nodes.\");\n if (!input.kernels && !input.queryPoint) throw new InvalidConfigurationError(\"Display view needs the environment query points without diffraction.\");\n const A = input.electronsPerRadiance, scene = input.scene, offsets = input.offsets, channelAt = input.channelAt;\n const kernelAt = (node: number, t: number): number => (input.kernels ? input.kernels.perNode[node]![t]! : 1);\n // Materials: neutral ones by reflectance, spectral ones by index.\n let reflectance = new Float64Array(0), spectralIndex = new Int32Array(0);\n const spectral: Float64Array[] = [];\n if (scene.kind === \"materials\") {\n reflectance = new Float64Array(scene.materials.length); spectralIndex = new Int32Array(scene.materials.length).fill(-1);\n scene.materials.forEach((m, index) => { if (\"neutral\" in m) reflectance[index] = m.neutral; else { spectralIndex[index] = spectral.length; spectral.push(m.radiance); } });\n }\n // Offsets grouped by fractional shift: offsets that differ by whole sites share one lattice.\n const frac = (v: number): number => { const f = v - Math.floor(v); return f > 1 - OFFSET_TOLERANCE || f < OFFSET_TOLERANCE ? 0 : f; };\n interface Group { fx: number; fy: number; members: { ix: number; iy: number; weight: number }[]; minIx: number; maxIx: number; minIy: number; maxIy: number;\n cw: number; ch: number; neutral: Float64Array[]; spectral: Float64Array[][]; perNode: Float64Array[][]; cache: Int32Array | Float64Array; cx0: number; cy0: number; cpw: number; cph: number }\n const groups: Group[] = [];\n for (const o of offsets) {\n const fx = frac(o.x), fy = frac(o.y), ix = Math.round(o.x - fx), iy = Math.round(o.y - fy);\n let group = groups.find((q) => Math.abs(q.fx - fx) <= OFFSET_TOLERANCE && Math.abs(q.fy - fy) <= OFFSET_TOLERANCE);\n if (!group) { group = { fx, fy, members: [], minIx: ix, maxIx: ix, minIy: iy, maxIy: iy, cw: 0, ch: 0, neutral: [], spectral: [], perNode: [], cache: new Int32Array(0), cx0: 0, cy0: 0, cpw: 0, cph: 0 }; groups.push(group); }\n group.members.push({ ix, iy, weight: o.weight });\n group.minIx = Math.min(group.minIx, ix); group.maxIx = Math.max(group.maxIx, ix); group.minIy = Math.min(group.minIy, iy); group.maxIy = Math.max(group.maxIy, iy);\n }\n if (input.kernels) for (const group of groups) {\n // Combined kernel over lattice offsets d = (ix − tu, iy − tv), stored at (d − min + R).\n const cw = group.maxIx - group.minIx + size, ch = group.maxIy - group.minIy + size;\n group.cw = cw; group.ch = ch;\n const combine = (value: (c: number, node: number, t: number) => number): Float64Array[] => [0, 1, 2].map((c) => {\n const out = new Float64Array(cw * ch);\n for (const member of group.members) for (let tv = -R, t = 0; tv <= R; tv++) for (let tu = -R; tu <= R; tu++, t++) {\n let sum = 0;\n for (let n = 0; n < nodes; n++) sum += value(c, n, t);\n const index = (member.iy - tv - group.minIy + R) * cw + (member.ix - tu - group.minIx + R);\n out[index] = out[index]! + member.weight * sum;\n }\n return out;\n });\n if (scene.kind === \"materials\") {\n group.neutral = combine((c, n, t) => A[c]![n]! * kernelAt(n, t) * scene.whiteRadiance[n]!);\n const perMaterial = spectral.map((radiance) => combine((c, n, t) => A[c]![n]! * kernelAt(n, t) * radiance[n]!));\n group.spectral = [0, 1, 2].map((c) => perMaterial.map((tables) => tables[c]!));\n } else {\n // Radiance scenes: combined kernels per node, applied to the cached radiance at each node.\n group.perNode = Array.from({ length: nodes }, (_, n) => combine((c, node, t) => (node === n ? A[c]![n]! * kernelAt(n, t) : 0)));\n }\n }\n // Neutral tap-0 signal per channel and spectral per material, for the direct (no-kernel) path.\n const neutralDirect = scene.kind === \"materials\" ? [0, 1, 2].map((c) => { let s = 0; for (let n = 0; n < nodes; n++) s += A[c]![n]! * scene.whiteRadiance[n]!; return s; }) : [];\n const spectralDirect = [0, 1, 2].map((c) => spectral.map((radiance) => { let s = 0; for (let n = 0; n < nodes; n++) s += A[c]![n]! * radiance[n]!; return s; }));\n let lookups = 0;\n const point = new Float64Array(2);\n const materialSignalDirect = (m: number, c: number): number => {\n const si = spectralIndex[m];\n if (si === undefined) throw new InvalidConfigurationError(\"Unknown chart material.\");\n return si < 0 ? reflectance[m]! * neutralDirect[c]! : spectralDirect[c]![si]!;\n };\n /** Without diffraction: one site from the environment's own query points. */\n function directSite(x: number, y: number): number {\n const c = channelAt(x, y);\n let sum = 0;\n for (let o = 0; o < offsets.length; o++) {\n input.queryPoint!(x, y, o, point);\n let value: number;\n if (scene.kind === \"materials\") { value = materialSignalDirect(scene.materialAt(point[0]!, point[1]!), c); lookups++; }\n else { value = 0; for (let n = 0; n < nodes; n++) value += A[c]![n]! * scene.radianceAt(point[0]!, point[1]!, input.wavelengthsNm[n]!); lookups += nodes; }\n sum += offsets[o]!.weight * value;\n }\n return sum;\n }\n // Lattice point (p, q) of a group: the facade's lattice formula (createDiffractedPlanarProvider).\n const latticeU = (group: Group, p: number): number => (group.fx === 0 ? (p + 0.5 - W / 2) * g : (p + 0.5 + group.fx - W / 2) * g);\n const latticeV = (group: Group, q: number): number => (group.fy === 0 ? -(q + 0.5 - H / 2) * g : -(q + 0.5 + group.fy - H / 2) * g);\n const radianceScratch = new Float64Array(nodes);\n /** Material (or radiance at each node, into radianceScratch) of a group's lattice point, from the window cache when it holds it. */\n function latticeMaterial(group: Group, p: number, q: number): number {\n const i = p - group.cx0, j = q - group.cy0, cached = i >= 0 && j >= 0 && i < group.cpw && j < group.cph;\n if (cached) { const m = group.cache[j * group.cpw + i]!; if (m >= 0) return m; }\n const m = (scene as Extract<DisplayViewScene, { kind: \"materials\" }>).materialAt(latticeU(group, p), latticeV(group, q));\n lookups++;\n if (cached) group.cache[j * group.cpw + i] = m;\n return m;\n }\n function latticeRadiance(group: Group, p: number, q: number): Float64Array {\n const i = p - group.cx0, j = q - group.cy0, cached = i >= 0 && j >= 0 && i < group.cpw && j < group.cph, cache = group.cache as Float64Array;\n if (cached && !Number.isNaN(cache[(j * group.cpw + i) * nodes]!)) { for (let n = 0; n < nodes; n++) radianceScratch[n] = cache[(j * group.cpw + i) * nodes + n]!; return radianceScratch; }\n const u = latticeU(group, p), v = latticeV(group, q);\n for (let n = 0; n < nodes; n++) radianceScratch[n] = (scene as Extract<DisplayViewScene, { kind: \"radiance\" }>).radianceAt(u, v, input.wavelengthsNm[n]!);\n lookups += nodes;\n if (cached) for (let n = 0; n < nodes; n++) cache[(j * group.cpw + i) * nodes + n] = radianceScratch[n]!;\n return radianceScratch;\n }\n /** With diffraction: one site through the combined kernels on each group's lattice. */\n function kernelSite(x: number, y: number): number {\n const c = channelAt(x, y);\n let sum = 0;\n for (const group of groups) {\n const p0 = x + group.minIx - R, q0 = y + group.minIy - R, cw = group.cw, ch = group.ch;\n if (scene.kind === \"materials\") {\n const nk = group.neutral[c]!, sk = group.spectral[c]!;\n for (let dy = 0; dy < ch; dy++) for (let dx = 0; dx < cw; dx++) {\n const m = latticeMaterial(group, p0 + dx, q0 + dy), si = spectralIndex[m];\n if (si === undefined) throw new InvalidConfigurationError(\"Unknown chart material.\");\n sum += si < 0 ? reflectance[m]! * nk[dy * cw + dx]! : sk[si]![dy * cw + dx]!;\n }\n } else {\n for (let dy = 0; dy < ch; dy++) for (let dx = 0; dx < cw; dx++) {\n const radiance = latticeRadiance(group, p0 + dx, q0 + dy);\n for (let n = 0; n < nodes; n++) sum += group.perNode[n]![c]![dy * cw + dx]! * radiance[n]!;\n }\n }\n }\n return sum;\n }\n // Filled windows (chart materials with diffraction, every lattice point of the window cacheable): each group keeps a band of\n // looked-up lattice materials that covers the window's rows and grows to the right as the windows of a display row move\n // right, with summed-area tables of material changes. A site whose kernel reads one material only (each group's rectangle\n // uniform, the same material in all) takes the value of the same sum over that material, precomputed below in the same\n // order; other sites run the same sum from the band. Either way each site's value is the same sequence of operations as\n // kernelSite, so it is bit-identical. The scene lookup count stays the count kernelSite's lazy window cache makes (each\n // cache point a computed site reads counts once per window, points outside the cache once per read): the rectangles of\n // the sites computed in a window are counted when the window closes (windowLookups).\n const uniformSite = scene.kind === \"materials\" && input.kernels ? [0, 1, 2].map((c) => Float64Array.from(scene.materials, (_, m) => {\n const si = spectralIndex[m]!;\n let sum = 0;\n for (const group of groups) {\n const nk = group.neutral[c]!, sk = si < 0 ? nk : group.spectral[c]![si]!;\n for (let t = 0; t < group.cw * group.ch; t++) sum += si < 0 ? reflectance[m]! * nk[t]! : sk[t]!;\n }\n return sum;\n })) : [];\n const allNeutral = spectral.length === 0;\n /**\n * A group's band: lattice rows [y0, y0 + rows), columns [x0, x0 + filled) looked up, row stride `capacity`. `material`,\n * `reflectance` (neutral-only charts) and the summed-area tables of left changes (`changeLeft`, 1 where a point's material\n * differs from its left neighbour's) and upper changes (`changeUp`), (rows + 1) × (capacity + 1).\n */\n interface Band { x0: number; y0: number; rows: number; capacity: number; filled: number; material: Int32Array; reflectance: Float64Array; changeLeft: Int32Array; changeUp: Int32Array; v: Float64Array }\n const bands: Band[] = groups.map(() => ({ x0: 0, y0: 0, rows: 0, capacity: 0, filled: 0, material: new Int32Array(0), reflectance: new Float64Array(0),\n changeLeft: new Int32Array(0), changeUp: new Int32Array(0), v: new Float64Array(0) }));\n /** Makes the band of group g cover lattice columns [x0, x1) of rows [y0, y0 + rows), extending it to the right when it can. */\n function coverBand(g: number, x0: number, x1: number, y0: number, rows: number): void {\n const group = groups[g]!, band = bands[g]!, materials = scene as Extract<DisplayViewScene, { kind: \"materials\" }>;\n if (!(band.rows === rows && band.y0 === y0 && x0 >= band.x0 && x1 - band.x0 <= band.capacity)) {\n const capacity = Math.max(x1 - x0, Math.min(Math.floor(BAND_LIMIT / rows), W + 2 * (x1 - x0)));\n const size = rows * capacity, tables = (rows + 1) * (capacity + 1);\n band.x0 = x0; band.y0 = y0; band.rows = rows; band.capacity = capacity; band.filled = 0;\n if (band.material.length < size) { band.material = new Int32Array(size); band.reflectance = new Float64Array(allNeutral ? size : 0); }\n if (band.changeLeft.length < tables) { band.changeLeft = new Int32Array(tables); band.changeUp = new Int32Array(tables); }\n band.changeLeft.fill(0, 0, capacity + 1); band.changeUp.fill(0, 0, capacity + 1);\n for (let j = 0; j < rows; j++) { band.changeLeft[(j + 1) * (capacity + 1)] = 0; band.changeUp[(j + 1) * (capacity + 1)] = 0; }\n if (band.v.length < rows) band.v = new Float64Array(rows);\n for (let j = 0; j < rows; j++) band.v[j] = latticeV(group, y0 + j);\n }\n const stride = band.capacity, S1 = stride + 1, material = band.material, left = band.changeLeft, up = band.changeUp;\n for (let i = band.filled; i < x1 - band.x0; i++) {\n const u = latticeU(group, band.x0 + i);\n for (let j = 0; j < rows; j++) {\n const m = materials.materialAt(u, band.v[j]!);\n if (spectralIndex[m] === undefined) throw new InvalidConfigurationError(\"Unknown chart material.\");\n material[j * stride + i] = m;\n if (allNeutral) band.reflectance[j * stride + i] = reflectance[m]!;\n const changedLeft = i > 0 && material[j * stride + i - 1] !== m ? 1 : 0, changedUp = j > 0 && material[(j - 1) * stride + i] !== m ? 1 : 0;\n left[(j + 1) * S1 + i + 1] = left[j * S1 + i + 1]! + left[(j + 1) * S1 + i]! - left[j * S1 + i]! + changedLeft;\n up[(j + 1) * S1 + i + 1] = up[j * S1 + i + 1]! + up[(j + 1) * S1 + i]! - up[j * S1 + i]! + changedUp;\n }\n }\n band.filled = Math.max(band.filled, x1 - band.x0);\n }\n const rectSum = (sat: Int32Array, S1: number, i0: number, j0: number, i1: number, j1: number): number =>\n sat[j1 * S1 + i1]! - sat[j0 * S1 + i1]! - sat[j1 * S1 + i0]! + sat[j0 * S1 + i0]!;\n let filled = false;\n /** Sites outside the site window computed in this window (x, y pairs in window coordinates); their rectangles count when the window closes. */\n let outsideSites: number[] = [];\n let marks = new Uint8Array(0), cover = new Uint8Array(0);\n /** A site of a filled window: (i, j) are its coordinates in the site window, inside or outside it. */\n function filledSite(x: number, y: number, i: number, j: number): number {\n const c = channelAt(x, y), inside = i >= 0 && j >= 0 && i < sw && j < sh;\n if (inside) {\n let m = -1;\n for (let g = 0; g < groups.length; g++) {\n const group = groups[g]!, band = bands[g]!, S1 = band.capacity + 1, bi = x + group.minIx - R - band.x0, bj = y + group.minIy - R - band.y0;\n if (rectSum(band.changeLeft, S1, bi + 1, bj, bi + group.cw, bj + group.ch) !== 0 || rectSum(band.changeUp, S1, bi, bj + 1, bi + group.cw, bj + group.ch) !== 0) { m = -2; break; }\n const own = band.material[bj * band.capacity + bi]!;\n if (m === -1) m = own; else if (own !== m) { m = -2; break; }\n }\n if (m >= 0) { lastMaterial = m; return uniformSite[c]![m]!; }\n }\n lastMaterial = -1;\n let sum = 0;\n for (let g = 0; g < groups.length; g++) {\n const group = groups[g]!, band = bands[g]!, cw = group.cw, ch = group.ch, nk = group.neutral[c]!, sk = group.spectral[c]!, stride = band.capacity;\n const p0 = x + group.minIx - R, q0 = y + group.minIy - R, bi = p0 - band.x0, bj = q0 - band.y0;\n if (inside && allNeutral) {\n const refl = band.reflectance;\n for (let dy = 0, t = 0; dy < ch; dy++) {\n const row = (bj + dy) * stride + bi;\n for (let dx = 0; dx < cw; dx++, t++) sum += refl[row + dx]! * nk[t]!;\n }\n } else if (inside) {\n const material = band.material;\n for (let dy = 0, t = 0; dy < ch; dy++) {\n const row = (bj + dy) * stride + bi;\n for (let dx = 0; dx < cw; dx++, t++) {\n const m = material[row + dx]!, si = spectralIndex[m]!;\n sum += si < 0 ? reflectance[m]! * nk[t]! : sk[si]![t]!;\n }\n }\n } else {\n for (let dy = 0; dy < ch; dy++) for (let dx = 0; dx < cw; dx++) {\n const ci = i + dx, cj = j + dy;\n let m: number;\n if (ci >= 0 && cj >= 0 && ci < group.cpw && cj < group.cph) m = band.material[(bj + dy) * stride + bi + dx]!;\n else m = (scene as Extract<DisplayViewScene, { kind: \"materials\" }>).materialAt(latticeU(group, p0 + dx), latticeV(group, q0 + dy));\n const si = spectralIndex[m];\n if (si === undefined) throw new InvalidConfigurationError(\"Unknown chart material.\");\n sum += si < 0 ? reflectance[m]! * nk[dy * cw + dx]! : sk[si]![dy * cw + dx]!;\n }\n }\n }\n return sum;\n }\n /** Lattice points of an outside site's rectangles that lie outside the window caches (kernelSite looks these up on every read). */\n function outsideLookups(i: number, j: number): number {\n let count = 0;\n for (const group of groups) {\n const w = Math.max(0, Math.min(i + group.cw, group.cpw) - Math.max(i, 0)), h = Math.max(0, Math.min(j + group.ch, group.cph) - Math.max(j, 0));\n count += group.cw * group.ch - w * h;\n }\n return count;\n }\n // Site values of filled windows persist across windows (a site's value does not depend on the window): rows of native\n // sites in a ring of a power-of-two number of rows, row y in slot y mod ringRows. The window's site cache still holds the\n // sites read in the window, which is also what its lookup count needs.\n let ringRows = 0, ringOn = false, ring = new Float64Array(0), ringMaterial = new Int32Array(0), ringRowId = new Int32Array(0), windowMaterial = new Int32Array(0), lastMaterial = -1;\n /** A filled-window site read outside the site window: counted as kernelSite counts it. */\n function outsideRead(i: number, j: number): void { lookups += outsideLookups(i, j); outsideSites.push(i, j); }\n /** A site from the ring; on a miss (re)claims the row's slot when another row holds it, computes the site and stores it. */\n function ringRead(x: number, y: number, i: number, j: number): number {\n const slot = y & (ringRows - 1), q = slot * W + x;\n if (ringRowId[slot] === y) { const v = ring[q]!; if (v === v) { lastMaterial = ringMaterial[q]!; return v; } }\n else { ringRowId[slot] = y; ring.fill(NaN, slot * W, (slot + 1) * W); }\n const v = filledSite(x, y, i, j);\n ring[q] = v; ringMaterial[q] = lastMaterial;\n return v;\n }\n // Without diffraction (#392): site values persist across windows the same way, in their own ring (a site's value does not\n // depend on the window). A ring hit counts the lookups directSite would have made, so `lookups` is unchanged.\n let directRows = 0, directOn = false, directRing = new Float64Array(0), directRowId = new Int32Array(0);\n const directLookups = offsets.length * (scene.kind === \"materials\" ? 1 : nodes);\n function directRead(x: number, y: number): number {\n const slot = y & (directRows - 1), q = slot * W + x;\n if (directRowId[slot] === y) { const v = directRing[q]!; if (v === v) { lookups += directLookups; return v; } }\n else { directRowId[slot] = y; directRing.fill(NaN, slot * W, (slot + 1) * W); }\n const v = directSite(x, y);\n directRing[q] = v;\n return v;\n }\n /** A site not in the window's site cache: from a ring, a filled window without the ring, the lazy window caches, or uncached. */\n function siteMiss(x: number, y: number, i: number, j: number, cached: boolean): number {\n if (directOn) {\n const v = directRead(x, y);\n if (cached) siteCache[j * sw + i] = v;\n return v;\n }\n if (ringOn) {\n if (!cached) { outsideRead(i, j); return ringRead(x, y, i, j); }\n const v = ringRead(x, y, i, j);\n siteCache[j * sw + i] = v; windowMaterial[j * sw + i] = lastMaterial;\n return v;\n }\n if (filled && !cached) outsideRead(i, j);\n const v = filled ? filledSite(x, y, i, j) : input.kernels ? kernelSite(x, y) : directSite(x, y);\n if (cached) siteCache[j * sw + i] = v;\n return v;\n }\n /**\n * Lattice points of the closing window that kernelSite's lazy cache would have looked up: per group, the window cache points\n * covered by the rectangles of the computed sites (the site cache's filled entries and the outside sites), a box dilation.\n */\n function windowLookups(): number {\n let total = 0;\n for (const group of groups) {\n const cw = group.cw, ch = group.ch, cpw = group.cpw, cph = group.cph, ew = cpw + cw - 1, eh = cph + ch - 1;\n // Top-left marks in extended coordinates (window coordinates + (cw − 1, ch − 1)), and their bounding box.\n if (marks.length < ew * eh) { marks = new Uint8Array(ew * eh); }\n let x0 = ew, x1 = -1, y0 = eh, y1 = -1;\n const mark = (ei: number, ej: number): void => {\n if (ei < 0 || ej < 0 || ei >= ew || ej >= eh) return;\n marks[ej * ew + ei] = 1;\n if (ei < x0) x0 = ei; if (ei > x1) x1 = ei; if (ej < y0) y0 = ej; if (ej > y1) y1 = ej;\n };\n for (let j = 0; j < sh; j++) for (let i = 0; i < sw; i++) if (!Number.isNaN(siteCache[j * sw + i]!)) mark(i + cw - 1, j + ch - 1);\n for (let k = 0; k < outsideSites.length; k += 2) mark(outsideSites[k]! + cw - 1, outsideSites[k + 1]! + ch - 1);\n if (x1 < 0) continue;\n // Cache point (i, j) is covered when a mark lies in extended columns [i, i + cw) and rows [j, j + ch): a horizontal\n // then a vertical running count over the marks' box (outside it nothing is covered).\n const i0 = Math.max(0, x0 - cw + 1), i1 = Math.min(cpw - 1, x1), cwid = i1 - i0 + 1;\n if (cover.length < cwid * (y1 - y0 + 1)) cover = new Uint8Array(cwid * (y1 - y0 + 1));\n for (let r = y0; r <= y1; r++) {\n let run = 0;\n for (let e = i0; e <= i1 + cw - 1; e++) {\n run += marks[r * ew + e]!;\n if (e - cw >= i0) run -= marks[r * ew + e - cw]!;\n if (e >= i0 + cw - 1) cover[(r - y0) * cwid + e - cw + 1 - i0] = run > 0 ? 1 : 0;\n }\n marks.fill(0, r * ew + x0, r * ew + x1 + 1);\n }\n for (let i = 0; i < cwid; i++) {\n let run = 0;\n for (let r = y0; r <= y1 + ch - 1; r++) {\n if (r <= y1) run += cover[(r - y0) * cwid + i]!;\n if (r - ch >= y0 && r - ch <= y1) run -= cover[(r - ch - y0) * cwid + i]!;\n const j = r - ch + 1;\n if (j >= 0 && j < cph && run > 0) total++;\n }\n }\n }\n return total;\n }\n let sx0 = 0, sy0 = 0, sw = 0, sh = 0, siteCache = new Float64Array(0);\n const pilotNode = input.wavelengthsNm[Math.floor(nodes / 2)]!;\n return {\n get lookups(): number { return lookups + (filled ? windowLookups() : 0); },\n get uniformMaterial(): number { return lastMaterial; },\n get tracksMaterial(): boolean { return ringOn; },\n get cachesSites(): boolean { return sw > 0; },\n window(x0: number, y0: number, x1: number, y1: number): void {\n if (filled) lookups += windowLookups();\n filled = false; ringOn = false; outsideSites = [];\n sx0 = x0; sy0 = y0; sw = Math.max(0, x1 - x0); sh = Math.max(0, y1 - y0);\n if (sw * sh > CACHE_LIMIT) { sw = 0; sh = 0; }\n if (siteCache.length < sw * sh) siteCache = new Float64Array(sw * sh);\n siteCache.fill(NaN, 0, sw * sh);\n if (!input.kernels) {\n // A ring of at least twice the window's rows keeps the rows of the previous display row's windows.\n if (sh > 0 && directRows < 2 * sh) {\n let rows = 1;\n while (rows < 2 * sh) rows *= 2;\n if (rows * W <= CACHE_LIMIT) { directRows = rows; directRing = new Float64Array(rows * W).fill(NaN); directRowId = new Int32Array(rows).fill(-1); }\n }\n directOn = sh > 0 && directRows >= 2 * sh;\n return;\n }\n for (const group of groups) {\n group.cx0 = x0 + group.minIx - R; group.cy0 = y0 + group.minIy - R;\n group.cpw = sw === 0 ? 0 : sw + group.cw - 1; group.cph = sh === 0 ? 0 : sh + group.ch - 1;\n if (group.cpw * group.cph * (scene.kind === \"materials\" ? 1 : nodes) > CACHE_LIMIT) { group.cpw = 0; group.cph = 0; }\n }\n // Chart materials whose every group caches the whole window: the filled path (bands). Otherwise the lazy window caches.\n if (scene.kind === \"materials\" && sw > 0 && groups.every((group) => group.cpw > 0)) {\n groups.forEach((group, g) => coverBand(g, group.cx0, group.cx0 + group.cpw, group.cy0, group.cph));\n filled = true;\n if (windowMaterial.length < sw * sh) windowMaterial = new Int32Array(sw * sh);\n // A ring of at least twice the window's rows keeps the rows of the previous display row's windows.\n if (ringRows < 2 * sh) {\n let rows = 1;\n while (rows < 2 * sh) rows *= 2;\n if (rows * W <= CACHE_LIMIT) { ringRows = rows; ring = new Float64Array(rows * W).fill(NaN); ringMaterial = new Int32Array(rows * W); ringRowId = new Int32Array(rows).fill(-1); }\n }\n ringOn = ringRows >= 2 * sh;\n return;\n }\n for (const group of groups) {\n const n = group.cpw * group.cph * (scene.kind === \"materials\" ? 1 : nodes);\n if (scene.kind === \"materials\") { if (group.cache.length < n || !(group.cache instanceof Int32Array)) group.cache = new Int32Array(n); group.cache.fill(-1, 0, n); }\n else { if (group.cache.length < n || !(group.cache instanceof Float64Array)) group.cache = new Float64Array(n); group.cache.fill(NaN, 0, n); }\n }\n },\n site(x: number, y: number): number {\n // The window's site cache first (with the ring: the sites read in this window, which its lookup count needs too).\n const i = x - sx0, j = y - sy0, cached = i >= 0 && j >= 0 && i < sw && j < sh;\n if (cached) { const w = j * sw + i, v = siteCache[w]!; if (v === v) { if (ringOn) lastMaterial = windowMaterial[w]!; return v; } }\n return siteMiss(x, y, i, j, cached);\n },\n pilot(u: number, v: number): number {\n lookups++;\n return scene.kind === \"materials\" ? scene.materialAt(u, v) : scene.radianceAt(u, v, pilotNode);\n }\n };\n}\n"]}
@@ -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,24 @@ export interface PlanarSceneRadianceProvider {
110
137
  chartMaterialAt?(u: number, v: number): number;
111
138
  materialRadiance?(material: number, wavelengthNanometers: number): number;
112
139
  }
140
+ /** Internal (#394): the material lookup of a provider built by {@link buildPlanarSceneRadianceProvider}, if it has one. */
141
+ export declare function planarProviderMaterialOfDirection(provider: PlanarSceneRadianceProvider): ((direction: Readonly<{
142
+ x: number;
143
+ y: number;
144
+ z: number;
145
+ }>) => number | undefined) | undefined;
146
+ /**
147
+ * Internal (#385): `spectrum.evaluate` remembered per distinct wavelength. A prepared spectrum is a pure function of the
148
+ * wavelength, so the table returns the same double the call would; renderers ask for the same few spectral nodes millions
149
+ * of times, and the illuminant's formula (two transcendental evaluations) was about 30 % of a caller-scene display view.
150
+ */
151
+ export declare function tabulatedSpectrum(spectrum: Readonly<PreparedColorimetricSpectrum>): (wavelengthNanometers: number) => number;
113
152
  /**
114
153
  * Wraps a chart or caller scene as a provider for the native environment RAW task. `irradianceScale` is
115
154
  * from {@link calculateIlluminantIrradianceScale}; caller radiance scenes ignore the illuminant.
116
155
  */
117
156
  export declare function buildPlanarSceneRadianceProvider(input: {
118
- scene: ResolvedChartScene | CallerReflectanceScene | CallerRadianceScene;
157
+ scene: ResolvedChartScene | ResolvedCallerScene;
119
158
  sceneId: string;
120
159
  providerProfileId: string;
121
160
  illuminant: ResolvedCaptureIlluminant;
@@ -150,7 +189,7 @@ export declare function resolveChartSizeOption(value: unknown, frameAspect: numb
150
189
  * provider `providerProfileId`.
151
190
  */
152
191
  export declare function createPlanarSceneRadianceProvider(input: {
153
- scene: ChartScene | CallerReflectanceScene | CallerRadianceScene;
192
+ scene: ChartScene | CallerReflectanceScene | CallerRadianceScene | CallerMaterialScene;
154
193
  illuminant: CaptureIlluminant;
155
194
  illuminanceLux: number;
156
195
  distanceM: number;
@@ -167,5 +206,5 @@ export declare function createPlanarSceneRadianceProvider(input: {
167
206
  }): PlanarSceneRadianceProvider & {
168
207
  chart: ResolvedChartScene | null;
169
208
  };
170
- /** Validates a caller scene function record. */
171
- export declare function requireCallerScene(value: unknown): CallerReflectanceScene | CallerRadianceScene;
209
+ /** Validates a caller scene record (a function scene as given; a material scene with its materials prepared). */
210
+ 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,38 @@ 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;
126
+ /**
127
+ * Internal (#394, not exported from the package): per provider of a chart preset or caller material scene, the material its
128
+ * `evaluateRadiance` reads for an environment-direction query with a given outgoing direction (the same plane-point
129
+ * arithmetic), or undefined where `evaluateRadiance` would throw. Its radiance is `materialRadiance(material, wavelength)`.
130
+ */
131
+ const MATERIAL_OF_DIRECTION = new WeakMap();
132
+ /** Internal (#394): the material lookup of a provider built by {@link buildPlanarSceneRadianceProvider}, if it has one. */
133
+ export function planarProviderMaterialOfDirection(provider) {
134
+ return MATERIAL_OF_DIRECTION.get(provider);
135
+ }
124
136
  const UNCERTAINTY = Object.freeze({ kind: "not-quantified", limitation: "Analytic planar Lambertian scene; no measured scene, BRDF or illumination." });
137
+ /** Most distinct wavelengths {@link tabulatedSpectrum} keeps; later ones are evaluated on every call. */
138
+ const TABULATED_SPECTRUM_MAX_ENTRIES = 4096;
139
+ /**
140
+ * Internal (#385): `spectrum.evaluate` remembered per distinct wavelength. A prepared spectrum is a pure function of the
141
+ * wavelength, so the table returns the same double the call would; renderers ask for the same few spectral nodes millions
142
+ * of times, and the illuminant's formula (two transcendental evaluations) was about 30 % of a caller-scene display view.
143
+ */
144
+ export function tabulatedSpectrum(spectrum) {
145
+ const table = new Map();
146
+ return (nm) => {
147
+ let value = table.get(nm);
148
+ if (value === undefined) {
149
+ value = spectrum.evaluate(nm);
150
+ if (table.size < TABULATED_SPECTRUM_MAX_ENTRIES)
151
+ table.set(nm, value);
152
+ }
153
+ return value;
154
+ };
155
+ }
125
156
  /**
126
157
  * Wraps a chart or caller scene as a provider for the native environment RAW task. `irradianceScale` is
127
158
  * from {@link calculateIlluminantIrradianceScale}; caller radiance scenes ignore the illuminant.
@@ -131,19 +162,40 @@ export function buildPlanarSceneRadianceProvider(input) {
131
162
  const scale = geometry.metresPerFrameUnit, distance = geometry.distanceM, sceneId = input.sceneId, providerProfileId = input.providerProfileId;
132
163
  const evidence = input.evidence, limitations = input.limitations;
133
164
  const caller = "kind" in scene ? scene : undefined, chart = caller ? undefined : scene;
165
+ const materialScene = caller?.kind === "material-function" ? caller : undefined, materials = chart ? chart.materials : materialScene?.materials;
134
166
  const placed = geometry.chart, half = placed ? placed.widthM / 2 : 0, chartAspect = placed ? placed.heightM / placed.widthM : 0;
167
+ const shapeAt = tabulatedSpectrum(illuminant.shape);
168
+ /** A material scene's material at a frame point: the caller's index, or `materials.length` for a fixed-size chart's surround. */
169
+ function callerMaterialAt(u, v) {
170
+ const xM = u * scale, yM = v * scale;
171
+ let point;
172
+ if (placed) {
173
+ const cu = xM / half, cv = yM / half;
174
+ if (!(Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect))
175
+ return materialScene.materials.length;
176
+ point = Object.freeze({ xM, yM, u, v, chartU: cu, chartV: cv });
177
+ }
178
+ else
179
+ point = Object.freeze({ xM, yM, u, v });
180
+ const index = materialScene.materialAt(point);
181
+ if (!Number.isInteger(index) || index < 0 || index >= materialScene.materials.length)
182
+ throw new InvalidConfigurationError("Scene materialAt must return an index into its materials.");
183
+ return index;
184
+ }
135
185
  function radianceAt(u, v, nm) {
186
+ if (materialScene)
187
+ return materialRadianceOf(callerMaterialAt(u, v), nm);
136
188
  if (placed) {
137
189
  // Fixed-size chart (2.3): chart-local frame units from the plane point in metres.
138
190
  const xM = u * scale, yM = v * scale, cu = xM / half, cv = yM / half;
139
191
  if (!(Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect))
140
- return placed.surroundReflectance * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;
192
+ return placed.surroundReflectance * irradianceScale * shapeAt(nm) / Math.PI;
141
193
  if (chart)
142
- return chart.reflectanceAt(cu, cv, nm) * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;
194
+ return chart.reflectanceAt(cu, cv, nm) * irradianceScale * shapeAt(nm) / Math.PI;
143
195
  return callerValue(Object.freeze({ xM, yM, u, v, wavelengthNanometers: nm, chartU: cu, chartV: cv }), nm);
144
196
  }
145
197
  if (chart)
146
- return chart.reflectanceAt(u, v, nm) * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;
198
+ return chart.reflectanceAt(u, v, nm) * irradianceScale * shapeAt(nm) / Math.PI;
147
199
  return callerValue(Object.freeze({ xM: u * scale, yM: v * scale, u, v, wavelengthNanometers: nm }), nm);
148
200
  }
149
201
  function callerValue(point, nm) {
@@ -151,7 +203,7 @@ export function buildPlanarSceneRadianceProvider(input) {
151
203
  if (caller.kind === "reflectance-function") {
152
204
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1)
153
205
  throw new InvalidConfigurationError("Scene reflectance function must return a value in [0, 1].");
154
- return value * irradianceScale * illuminant.shape.evaluate(nm) / Math.PI;
206
+ return value * irradianceScale * shapeAt(nm) / Math.PI;
155
207
  }
156
208
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
157
209
  throw new InvalidConfigurationError("Scene radiance function must return a finite non-negative radiance.");
@@ -162,31 +214,41 @@ export function buildPlanarSceneRadianceProvider(input) {
162
214
  wavelengthBasis: request.wavelengthBasis, quantity: "outgoing-spectral-radiance", unit: "W/m^2/sr/nm",
163
215
  spectralRadianceWattsPerSquareMeterSteradianNanometer: radiance, scientificStatus: "approximation", uncertainty: UNCERTAINTY, evidence, limitations };
164
216
  }
165
- const chartAccess = chart ? {
166
- chartMaterialAt(u, v) {
167
- if (!placed)
168
- return chart.materialAt(u, v);
169
- const cu = u * scale / half, cv = v * scale / half;
170
- return Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect ? chart.materialAt(cu, cv) : chart.materials.length;
171
- },
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;
217
+ /** Spectral radiance of material `material` (`materials.length`: a fixed-size chart's surround), in the chart's expression order. */
218
+ function materialRadianceOf(material, nm) {
219
+ const m = materials[material];
220
+ let value;
221
+ if (m === undefined)
222
+ value = placed ? placed.surroundReflectance : NaN;
223
+ else if (m.kind === "neutral")
224
+ value = m.reflectance;
225
+ else {
226
+ value = m.spectrum.evaluate(nm);
227
+ if (!(value >= 0 && value <= 1))
228
+ throw new InvalidConfigurationError("Chart reflectance spectrum left [0, 1].");
187
229
  }
188
- } : {};
189
- return {
230
+ if (!(value >= 0))
231
+ throw new InvalidConfigurationError("Unknown chart material.");
232
+ return value * irradianceScale * shapeAt(nm) / Math.PI;
233
+ }
234
+ function chartMaterialAt(u, v) {
235
+ if (!placed)
236
+ return chart.materialAt(u, v);
237
+ const cu = u * scale / half, cv = v * scale / half;
238
+ return Math.abs(cu) <= 1 && Math.abs(cv) <= chartAspect ? chart.materialAt(cu, cv) : chart.materials.length;
239
+ }
240
+ const chartAccess = chart ? { chartMaterialAt, materialRadiance: materialRadianceOf } :
241
+ materialScene ? { chartMaterialAt: callerMaterialAt, materialRadiance: materialRadianceOf } : {};
242
+ // #394: evaluateRadiance's own plane-point arithmetic; radianceAt is then materialRadianceOf(material, nm) for both scene forms.
243
+ const materialAtPoint = chart ? chartMaterialAt : materialScene ? callerMaterialAt : undefined;
244
+ const materialOfDirection = materialAtPoint === undefined ? undefined : (o) => {
245
+ const lz = -o.z;
246
+ if (!(lz > 0))
247
+ return undefined;
248
+ const t = distance / lz;
249
+ return materialAtPoint(-o.x * t / scale, -o.y * t / scale);
250
+ };
251
+ const provider = {
190
252
  sceneId, providerProfileId, radianceAt, ...chartAccess,
191
253
  evaluateRadiance(request) {
192
254
  const target = request.target;
@@ -206,6 +268,9 @@ export function buildPlanarSceneRadianceProvider(input) {
206
268
  return result(request, radianceAt((origin.x + d.x * t) / scale, (origin.y + d.y * t) / scale, request.wavelengthNanometers));
207
269
  }
208
270
  };
271
+ if (materialOfDirection)
272
+ MATERIAL_OF_DIRECTION.set(provider, materialOfDirection);
273
+ return provider;
209
274
  }
210
275
  /** Default surround of a fixed-size chart: an 18 % grey plane. */
211
276
  export const CHART_SIZE_DEFAULT_SURROUND_REFLECTANCE = 0.18;
@@ -263,10 +328,22 @@ export function createPlanarSceneRadianceProvider(input) {
263
328
  limitations: ["Planar Lambertian scene under uniform illumination; no shadows, inter-reflection, gloss or fluorescence."] });
264
329
  return { ...provider, chart };
265
330
  }
266
- /** Validates a caller scene function record. */
331
+ /** Validates a caller scene record (a function scene as given; a material scene with its materials prepared). */
267
332
  export function requireCallerScene(value) {
268
333
  requireInputObject(value, "scene");
269
334
  const record = value;
335
+ if (record.kind === "material-function") {
336
+ for (const key of Object.keys(record))
337
+ if (key !== "kind" && key !== "sceneId" && key !== "materials" && key !== "materialAt")
338
+ throw new InvalidConfigurationError("Unknown scene field: " + key + ".");
339
+ if (typeof record.materialAt !== "function" || typeof record.sceneId !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/.test(record.sceneId) ||
340
+ !Array.isArray(record.materials) || record.materials.length < 1 || record.materials.length > CALLER_MATERIAL_SCENE_MAX_MATERIALS)
341
+ throw new InvalidConfigurationError("A material scene needs a public sceneId, 1 to " + CALLER_MATERIAL_SCENE_MAX_MATERIALS + " materials and a materialAt function.");
342
+ const inputs = [...record.materials];
343
+ return Object.freeze({ kind: "material-function", sceneId: record.sceneId, materialAt: record.materialAt,
344
+ materials: Object.freeze(inputs.map((m, index) => resolveChartMaterial(m, "scene.materials[" + index + "]"))),
345
+ materialInputs: Object.freeze(inputs.map((m) => (typeof m === "number" ? undefined : m))) });
346
+ }
270
347
  for (const key of Object.keys(record))
271
348
  if (key !== "kind" && key !== "sceneId" && key !== "evaluate")
272
349
  throw new InvalidConfigurationError("Unknown scene field: " + key + ".");