Spectral upsampling with sigmoid polynomials
Maps any RGB colour to a smooth reflectance spectrum by fitting a sigmoid of a quadratic polynomial, stored in a 3D coefficient table. Lets spectral renderers accept ordinary RGB textures.
In the family Post-processing, color & imaging, spectral rendering
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | Godot renders in RGB rather than spectral space with sigmoid upsampling. |
| Unity | None found | |
| Unreal 5.7 | None found | Unreal renders in RGB/ACEScg rather than spectral rendering with sigmoid upsampling. |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Reflectance spectra must be smooth and bounded between 0 and 1. Jakob and Hanika model a spectrum as s(lambda) = sigmoid(c0 lambda^2 + c1 lambda + c2). For each RGB colour in the gamut, an offline optimisation finds the three coefficients that make the spectrum, when integrated against the colour matching functions and illuminant, reproduce the colour, and the solution is continuous across the gamut. The coefficients are tabulated on a 3D grid parametrised by the largest channel and the other two, with a nonlinear scale for resolution near the gamut boundary. At render time a texture's RGB is looked up with trilinear interpolation, and a spectrum is evaluated at the sampled wavelength with two multiply-adds and a sigmoid. White maps exactly to a flat spectrum.
When to choose it
Reach for it when
- spectral renderer can't use my rgb textures
- need to turn rgb colours into plausible spectra
- rgb to spectrum and back must round trip
- metamerism and colour accuracy in a spectral path tracer
- smooth reflectance curves from three numbers
Choose it when a spectral path tracer must ingest RGB assets with plausible metamerism, or when you need round-trip RGB to spectrum to RGB conversions.
Prefer plain RGB rendering when materials are not spectrally sensitive. Prefer measured spectra for scientific accuracy. It pairs with Film emulation (spectral stock simulation) pipelines that start from spectral data.
Field marks
- Illuminant-dependent: the same RGB reflects differently under unusual lights and the spectra are not unique
- Cannot represent spectra with sharp features such as fluorescent or iridescent materials
- Table must be fitted per colour space and illuminant
- Out-of-gamut colours need clamping
Presets
Spectral Upsampling with Sigmoid Polynomials — RGB multiply (left) vs Jakob-Hanika quadratic sigmoid spectral bounce & scope (right)
{
"P_ILLUM_TEMP": 0.55,
"P_SATURATION": 0.85,
"P_SCOPE_GAIN": 0.75,
"P_SPLIT": 0.48
}Show GLSL (166 lines)
const float P_ILLUM_TEMP = 0.55; // P Illuminant Shift [0.0, 1.0, 0.02]
const float P_SATURATION = 0.85; // P Albedo Chroma [0.2, 1.0, 0.02]
const float P_SCOPE_GAIN = 0.75; // P Spectrum Scope [0.0, 1.0, 0.05]
const float P_SPLIT = 0.48; // P RGB / Spectral [0.0, 1.0, 0.02]
// Jakob & Hanika 2019 sigmoid basis: s(x) = 0.5 + x / (2 * sqrt(1 + x^2))
float sigPoly(float lam, vec3 coeff) {
float x = (coeff.x * lam + coeff.y) * lam + coeff.z;
return 0.5 + 0.5 * x / sqrt(1.0 + x * x);
}
// Smooth analytic approximation of CIE 1931 RGB-like spectral sensitivities for lam in [0, 1] (380..720nm)
vec3 wavelengthToRGB(float lam) {
float r = exp(-pow((lam - 0.74) / 0.16, 2.0)) + 0.25 * exp(-pow((lam - 0.14) / 0.09, 2.0));
float g = exp(-pow((lam - 0.48) / 0.15, 2.0));
float b = exp(-pow((lam - 0.18) / 0.12, 2.0));
return vec3(r, g, b);
}
// Fit quadratic sigmoid coefficients (c0, c1, c2) that reproduce target RGB reflectance smoothly in (0, 1)
vec3 rgbToSigmoidCoeff(vec3 rgb) {
vec3 c = clamp(rgb, 0.02, 0.98);
// Map primary balance into peak wavelength & curvature of quadratic polynomial
float c0 = -10.5 * (c.g - 0.5 * (c.r + c.b));
float c1 = 9.5 * (c.r - c.b) - c0;
float meanVal = (c.r + c.g + c.b) * 0.3333;
float c2 = (meanVal - 0.5) * 4.2 - 0.35 * c1 - 0.22 * c0;
return vec3(c0, c1, c2);
}
// Illuminant spectral power distribution (sweeping from sodium-amber narrowband to cool sky daylight)
float evalIlluminant(float lam, float temp) {
float warm = 1.45 * exp(-pow((lam - 0.68) / 0.22, 2.0)) + 0.35 * exp(-pow((lam - 0.44) / 0.14, 2.0));
float cool = 1.35 * exp(-pow((lam - 0.24) / 0.24, 2.0)) + 0.90 * exp(-pow((lam - 0.54) / 0.28, 2.0));
return mix(warm, cool, temp);
}
vec3 integrateSpectralBounce(vec3 alb1, vec3 alb2, float temp) {
vec3 k1 = rgbToSigmoidCoeff(alb1);
vec3 k2 = rgbToSigmoidCoeff(alb2);
vec3 acc = vec3(0.0);
vec3 normW = vec3(0.0);
for (int i = 0; i < 10; i++) {
float lam = (float(i) + 0.5) / 10.0;
float s1 = sigPoly(lam, k1);
float s2 = sigPoly(lam, k2);
float ill = evalIlluminant(lam, temp);
vec3 cmf = wavelengthToRGB(lam);
acc += cmf * (s1 * s2 * ill);
normW += cmf * ill;
}
return acc / max(normW, vec3(1e-4));
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float screenX = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool isSpectral = screenX >= split;
float temp = clamp(P_ILLUM_TEMP + 0.28 * sin(iTime * 0.55), 0.0, 1.0);
float sat = clamp(P_SATURATION, 0.15, 1.0);
float scopeG = clamp(P_SCOPE_GAIN, 0.0, 1.0);
// Illuminant RGB equivalent for left side naive multiplication
vec3 illRGB = mix(vec3(1.18, 0.72, 0.34), vec3(0.54, 0.84, 1.22), temp);
vec3 col = mix(vec3(0.05, 0.06, 0.09), vec3(0.11, 0.14, 0.20), smoothstep(-0.4, 0.5, uv.y));
// Three colorful ceramic spheres demonstrating spectral vs RGB multi-bounce hue preservation
vec3 ro = vec3(0.0, 0.28, 2.35);
vec3 rd = normalize(vec3(uv.x, uv.y - 0.04, -1.5));
vec3 lDir = normalize(vec3(0.55, 0.78, 0.42));
vec3 centers[3];
vec3 albedos[3];
centers[0] = vec3(-0.56, 0.04, 0.0);
centers[1] = vec3(0.00, 0.08, 0.05);
centers[2] = vec3(0.56, 0.04, 0.0);
albedos[0] = mix(vec3(0.6), vec3(0.95, 0.24, 0.36), sat);
albedos[1] = mix(vec3(0.6), vec3(0.24, 0.86, 0.44), sat);
albedos[2] = mix(vec3(0.6), vec3(0.22, 0.48, 0.96), sat);
float tMin = 1e5;
int hitId = -1;
vec3 hp = vec3(0.0);
vec3 hn = vec3(0.0, 1.0, 0.0);
// Ground reflector plane (warm ochre bounce floor)
if (rd.y < -0.005) {
float tf = (-0.28 - ro.y) / rd.y;
if (tf > 0.05 && tf < 12.0) {
tMin = tf;
hitId = 10;
hp = ro + rd * tf;
hn = vec3(0.0, 1.0, 0.0);
}
}
for (int i = 0; i < 3; i++) {
vec3 oc = ro - centers[i];
float b = dot(oc, rd);
float d = b * b - (dot(oc, oc) - 0.28 * 0.28);
if (d > 0.0) {
float ts = -b - sqrt(d);
if (ts > 0.05 && ts < tMin) {
tMin = ts;
hitId = i;
hp = ro + rd * ts;
hn = normalize(hp - centers[i]);
}
}
}
vec3 floorAlb = mix(vec3(0.6), vec3(0.92, 0.68, 0.22), sat * 0.85);
if (hitId >= 0) {
float ndl = max(dot(hn, lDir), 0.0);
vec3 surfAlb = (hitId == 10) ? floorAlb : albedos[hitId];
vec3 bounceAlb = (hitId == 10) ? albedos[1] : floorAlb;
float bounceMask = (hitId == 10) ? smoothstep(0.95, 0.20, length(hp.xz)) : max(-hn.y * 0.85 + 0.25, 0.0);
vec3 directC;
vec3 bounceC;
if (isSpectral) {
// Spectral integration of sigmoid polynomial reflectance * illuminant
directC = integrateSpectralBounce(surfAlb, vec3(0.96), temp) * 1.35;
bounceC = integrateSpectralBounce(surfAlb, bounceAlb, temp) * 0.95;
} else {
// Naive RGB tristimulus componentwise multiplication (loses metamerism & shifts secondary bounce hues)
directC = surfAlb * illRGB * 1.15;
bounceC = surfAlb * bounceAlb * illRGB * 0.95;
}
float spec = (hitId == 10) ? 0.0 : pow(max(dot(reflect(-lDir, hn), -rd), 0.0), 36.0) * 0.65;
col = directC * (0.22 + 0.95 * ndl) + bounceC * bounceMask * 0.72 + illRGB * spec;
if (hitId == 10) col = mix(vec3(0.05, 0.06, 0.09), col, exp(-tMin * 0.14));
}
// Bottom live spectral curve oscilloscope showing s(lambda) = sigmoid(c0*l^2 + c1*l + c2) across 380-720 nm
vec2 suv = fragCoord / max(iResolution.xy, vec2(1.0));
if (suv.y < 0.24 && scopeG > 0.01) {
float lam = clamp((suv.x - 0.06) / 0.88, 0.0, 1.0);
float yLocal = clamp((suv.y - 0.03) / 0.18, 0.0, 1.0);
vec3 panel = vec3(0.04, 0.05, 0.08);
// Faint wavelength rainbow baseline
vec3 rainbow = normalize(wavelengthToRGB(lam) + vec3(0.05)) * 0.25;
panel += rainbow * smoothstep(0.18, 0.0, yLocal);
// Plot the three smooth quadratic sigmoid spectra for the three spheres
for (int k = 0; k < 3; k++) {
float sVal = sigPoly(lam, rgbToSigmoidCoeff(albedos[k]));
float line = smoothstep(0.038, 0.008, abs(yLocal - sVal));
panel = mix(panel, albedos[k] * 1.45, line);
}
// Plot current illuminant SPD dashed curve
float illV = clamp(evalIlluminant(lam, temp) * 0.55, 0.0, 0.98);
float illLine = smoothstep(0.024, 0.006, abs(yLocal - illV)) * step(0.4, fract(suv.x * 48.0));
panel = mix(panel, vec3(0.95, 0.96, 1.0), illLine * 0.85);
col = mix(col, panel, scopeG * 0.90);
}
float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
col = mix(col, vec3(0.95, 0.98, 1.0), sep);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: MIT — written for this index.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| spectral-upsampling-sigmoid-live | Tesla T4 1920x1080 | 4.77× baseline (light) · 0.157 ms / 0.163 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| spectral-upsampling-sigmoid-live | NVIDIA L4 1920x1080 | 4.03× baseline (light) · 0.064 ms / 0.066 ms · 2.5× faster on L4 | opengl-timer-query · Cross-architecture validation |
| spectral-upsampling-sigmoid-live | NVIDIA A100-SXM4-40GB 1920x1080 | 3.35× baseline (light) · 0.097 ms / 0.097 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Thin-film iridescence.
Crosses
- Film stocks exposed by spectra: Expose CG renders onto simulated film stocks from spectral radiance instead of RGB, so colour crosstalk and the look of saturated lights come from the stock's layer sensitivities, not from a guess at the spectrum made after rendering.
- Film emulation (spectral stock simulation): Spectral reconstruction of RGB feeds spectral film models.
Sources
- primaryWenzel Jakob, Johannes Hanika (2019). A Low‐Dimensional Function Space for Efficient Spectral Upsampling. Computer Graphics Forum.Verified via crossref · 2026-11-29doi:10.1111/cgf.13626
- implementationmitsuba-renderer (2018). mitsuba-renderer/rgb2spec. A Low-Dimensional Function Space for Efficient Spectral UpsamplingGitHub API · license BSD-3-Clause · 2026-11-29
- implementationmitsuba-renderer (2021). mitsuba-renderer/mitsuba3. Mitsuba 3: A Retargetable Forward and Inverse RendererGitHub API · license NOASSERTION · 2026-11-29