1// Copyright 2009-2020 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include "math/spectrum.h"
7#include "rkcommon/math/vec.ih"
8
9typedef uniform float<SPECTRUM_SAMPLES> spectrum;
10
11extern spectrum spectrum_sRGB_r;
12extern spectrum spectrum_sRGB_g;
13extern spectrum spectrum_sRGB_b;
14
15inline uniform vec3f spectrum_sRGB(const uniform int l)
16{
17  return make_vec3f(spectrum_sRGB_r[l], spectrum_sRGB_g[l], spectrum_sRGB_b[l]);
18}
19
20// note: result can be <0 or >1
21inline uniform vec3f spectrum2rgb(const spectrum &s)
22{
23  uniform vec3f rgb = make_vec3f(0.f);
24  for (uniform int l = 0; l < SPECTRUM_SAMPLES; l++)
25    rgb = rgb + s[l] * spectrum_sRGB(l);
26
27  return rgb;
28}
29