Skip to main content

Lighting and color subpaths

Import pathUse it to
@math.gl/geometry/lightingSample angular intensity, integrate luminous flux, and resample photometric profiles.
@math.gl/core/colorSample color lookup tables and apply them to RGB or RGBA buffers.

Both entry points operate on numerical tables and return CPU data. Supply measurements or lookup tables from your application or a reader such as loaders.gl.

Usage​

import {
createPhotometricSampler,
integrateLuminousFlux,
resamplePhotometricProfile
} from '@math.gl/geometry/lighting';
import type {PhotometricProfile} from '@math.gl/geometry/lighting';

const profile: PhotometricProfile = {
verticalAngles: [0, 90, 180],
horizontalAngles: [0],
intensities: [0, 100, 0],
symmetry: 'rotational'
};
const sample = createPhotometricSampler(profile);
const candela = sample(45, 120); // vertical, horizontal, in degrees
const lumens = integrateLuminousFlux(profile);
const grid = resamplePhotometricProfile(profile, {
verticalCount: 181,
horizontalCount: 360,
normalization: 'peak'
});

Features​

FeatureSupportContract
Angular intensity samplingYesBilinear interpolation, explicit symmetry, degrees and candela
Luminous fluxYesSolid-angle integration of the angular interpolant, returning lumens
Regular angular gridsYesOwned Float64 buffers with coordinates, units and optional peak normalization
Color LUT samplingYesPer-channel 1D linear or red-fastest 3D trilinear interpolation
Floating RGB/RGBA buffersYesNew Float32 output; alpha bypasses the LUT
File parsing and image decodingSeparateApplications obtain tables from a reader such as loaders.gl
World-axis transforms and GPU resourcesSeparateApplications choose axes, image formats and renderer objects

Photometric model​

PhotometricProfile describes polar/azimuth measurements independently of their file encoding. Angles are degrees, and scaled intensities are candela. There is no world-axis convention: the application chooses the pole and azimuth origin.

FieldDescription
verticalAnglesOrdered polar coordinates within [0, 180]
horizontalAnglesOrdered azimuth coordinates within [0, 360]
intensitiesSamples with vertical angle varying fastest
intensityScaleOptional uniform multiplier; default 1
symmetryRequired extension rule described below

The three data fields accept plain arrays or typed arrays through ArrayLike<number>. At least two vertical coordinates are required. Intensities must be finite and nonnegative, and their count must match the two axes. Lamp, ballast and file metadata are not read or inferred.

Explicit symmetry​

ModeRequired horizontal coverageInterpretation
rotationalOne measured planeSame distribution for every azimuth
quadrant0 through 90 degreesMirror the quadrant around the full circle
bilateralAny ordered 180-degree extent within [0, 360]Mirror around that extent, preserving its origin
none0 through 360 degreesUse the full authored circle

Partial nonsymmetric azimuth tables are outside the initial scope. Symmetry is never guessed from a format, filename or array length. An explicit mode that does not match the angular coverage rejects.

Sampling and integration​

createPhotometricSampler snapshots the input arrays and applies intensityScale once. Later source mutations do not affect the sampler. It interpolates bilinearly between measured knots. Vertical queries must be finite and within [0, 180]; directions outside the measured vertical extent return zero. Horizontal queries can be any finite angle and wrap around the circle.

integrateLuminousFlux integrates the piecewise bilinear angular distribution over solid angle: ∫∫ I(θ, φ) sin(θ) dθ dφ, using radians for integration. It uses the actual nonuniform intervals and analytical vertical weights, including stable narrow-interval evaluation near either pole. An isotropic one-candela distribution integrates to 4π lumens. This is the flux of the interpolant, without reconstructing missing measurements or applying near-field geometry, exposure or operating-condition adjustments. Invalid inputs and numeric overflow reject.

Resampled grids​

resamplePhotometricProfile(profile, options) returns PhotometricGrid:

FieldDescription
width, heightVertical samples per row and horizontal rows
dataFloat64 samples, indexed as horizontalIndex * width + verticalIndex
verticalAnglesCoordinates from 0 through 180, including both poles
horizontalAnglesCoordinates in [0, 360), excluding the duplicate seam
unitcandela, or relative after peak normalization
peakCandelaMeasured peak before normalization

Defaults are 181 vertical samples and 360 horizontal rows. Vertical count must be at least two and horizontal count at least one; their product is capped at 4,194,304. The arrays belong to the result. No GPU texture or axis conversion is created.

normalization: 'none' preserves candela. 'peak' divides by the measured peak, which need not lie on the resampled grid. Zero distributions remain zero. Subnormal positive peaks do not require an infinite reciprocal.

Numerical color LUTs​

ColorLUT is independent of Cube, 3dl, image layouts or any other encoding. It contains dimension (1 or 3), size, interleaved Float32 RGB data, three-channel domainMinimum/domainMaximum, and optional normalized Float64 inputGrid knots. Three-dimensional storage is red-fastest: 3 * (red + size * (green + size * blue)). Knots must increase strictly from 0 through 1; domain spans must be finite and positive.

import {createColorLUTSampler, applyColorLUT} from '@math.gl/core/color';
import type {ColorLUT} from '@math.gl/core/color';

const lut: ColorLUT = {
dimension: 1,
size: 2,
data: Float32Array.of(0, 0, 0, 1, 1, 1),
domainMinimum: [0, 0, 0],
domainMaximum: [1, 1, 1]
};
const sampleColor = createColorLUTSampler(lut);
const rgb = sampleColor(0.25, 0.5, 0.75);
const rgba = applyColorLUT(lut, Float32Array.of(0.25, 0.5, 0.75, 1), {components: 4});

The sampler snapshots data, domains and knots. It interpolates each channel independently for 1D tables, or uses trilinear interpolation for 3D tables, including nonuniform input knots. Finite inputs clamp to the authored domain. Signed/HDR outputs are not clamped.

applyColorLUT accepts interleaved Float32 or Float64 RGB buffers; set components: 4 for RGBA. It returns a new Float32 buffer and preserves the source. Alpha bypasses the LUT and is copied at Float32 precision; nonfinite or unrepresentable alpha rejects. Empty buffers return empty arrays. Incomplete pixels and nonfinite colors reject. There is no implicit byte scaling, sRGB/linear conversion, exposure, gamut mapping or premultiplication policy: supply values in the table's intended domain and encoding.

Composing with loaders.gl​

Parsing remains in loaders.gl; math.gl does not import it. Applications can map a parsed IES profile into the photometric model and explicitly choose the symmetry appropriate to that source. For a rotational profile:

import {load} from '@loaders.gl/core';
import {IESLoader} from '@loaders.gl/images';
import {createPhotometricSampler} from '@math.gl/geometry/lighting';

const measured = await load('rotational.ies', IESLoader);
const sample = createPhotometricSampler({
verticalAngles: measured.verticalAngles,
horizontalAngles: measured.horizontalAngles,
intensities: measured.candelaValues,
intensityScale: measured.candelaMultiplier,
symmetry: 'rotational'
});

loader-produced ColorLUT values are structurally compatible with the numerical model; pass the decoded table directly to createColorLUTSampler or applyColorLUT. Importing these utilities adds no mandatory dependency to either project. File readers retain their own revision, metadata, codec and precision contracts.