| 1 |
/* |
| 2 |
* Copyright (C) 2018 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <cstdint> |
| 18 |
#include <cstdlib> |
| 19 |
#include <complex> |
| 20 |
#include <fstream> |
| 21 |
#include <iomanip> |
| 22 |
#include <iostream> |
| 23 |
|
| 24 |
#include <vector> |
| 25 |
|
| 26 |
#include <getopt/getopt.h> |
| 27 |
|
| 28 |
#include <utils/Path.h> |
| 29 |
|
| 30 |
#include <math/mat3.h> |
| 31 |
#include <math/scalar.h> |
| 32 |
#include <math/vec3.h> |
| 33 |
|
| 34 |
using namespace filament::math; |
| 35 |
using namespace std::complex_literals; |
| 36 |
|
| 37 |
static float g_incidenceAngle = 81.7f; |
| 38 |
|
| 39 |
static void printUsage(const char* name) { |
| 40 |
std::string execName(utils::Path(name).getName()); |
| 41 |
std::string usage( |
| 42 |
"SPECULAR_COLOR computes the base color of a conductor from spectral data\n" |
| 43 |
"Usage:\n" |
| 44 |
" SPECULAR_COLOR [options] <spectral data file>\n" |
| 45 |
"\n" |
| 46 |
"Options:\n" |
| 47 |
" --help, -h\n" |
| 48 |
" Print this message\n\n" |
| 49 |
" --license\n" |
| 50 |
" Print copyright and license information\n\n" |
| 51 |
); |
| 52 |
|
| 53 |
const std::string from("SPECULAR_COLOR"); |
| 54 |
for (size_t pos = usage.find(from); pos != std::string::npos; pos = usage.find(from, pos)) { |
| 55 |
usage.replace(pos, from.length(), execName); |
| 56 |
} |
| 57 |
printf("%s", usage.c_str()); |
| 58 |
} |
| 59 |
|
| 60 |
static void license() { |
| 61 |
static const char *license[] = { |
| 62 |
#include "licenses/licenses.inc" |
| 63 |
nullptr |
| 64 |
}; |
| 65 |
|
| 66 |
const char **p = &license[0]; |
| 67 |
while (*p) |
| 68 |
std::cout << *p++ << std::endl; |
| 69 |
} |
| 70 |
|
| 71 |
static int handleArguments(int argc, char* argv[]) { |
| 72 |
static constexpr const char* OPTSTR = "hla:"; |
| 73 |
static const struct option OPTIONS[] = { |
| 74 |
{ "help", no_argument, nullptr, 'h' }, |
| 75 |
{ "license", no_argument, nullptr, 'l' }, |
| 76 |
{ "angle", required_argument, nullptr, 'a' }, |
| 77 |
{ nullptr, 0, nullptr, 0 } // termination of the option list |
| 78 |
}; |
| 79 |
|
| 80 |
int opt; |
| 81 |
int optionIndex = 0; |
| 82 |
|
| 83 |
while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { |
| 84 |
std::string arg(optarg ? optarg : ""); |
| 85 |
switch (opt) { |
| 86 |
default: |
| 87 |
case 'h': |
| 88 |
printUsage(argv[0]); |
| 89 |
exit(0); |
| 90 |
case 'l': |
| 91 |
license(); |
| 92 |
exit(0); |
| 93 |
case 'a': |
| 94 |
g_incidenceAngle = std::stof(arg); |
| 95 |
break; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
return optind; |
| 100 |
} |
| 101 |
|
| 102 |
// CIE 1931 10-deg color matching functions (CMFs), from 360nm to 830nm, at 1nm intervals |
| 103 |
// |
| 104 |
// Data source: |
| 105 |
// http://cvrl.ioo.ucl.ac.uk/cmfs.htm |
| 106 |
// http://cvrl.ioo.ucl.ac.uk/database/text/cmfs/ciexyz64.htm |
| 107 |
const size_t CIE_XYZ_START = 360; |
| 108 |
const size_t CIE_XYZ_COUNT = 471; |
| 109 |
const float3 CIE_XYZ[CIE_XYZ_COUNT] = { // NOLINT |
| 110 |
{ 0.000000122200f, 0.000000013398f, 0.000000535027f }, |
| 111 |
{ 0.000000185138f, 0.000000020294f, 0.000000810720f }, |
| 112 |
{ 0.000000278830f, 0.000000030560f, 0.000001221200f }, |
| 113 |
{ 0.000000417470f, 0.000000045740f, 0.000001828700f }, |
| 114 |
{ 0.000000621330f, 0.000000068050f, 0.000002722200f }, |
| 115 |
{ 0.000000919270f, 0.000000100650f, 0.000004028300f }, |
| 116 |
{ 0.000001351980f, 0.000000147980f, 0.000005925700f }, |
| 117 |
{ 0.000001976540f, 0.000000216270f, 0.000008665100f }, |
| 118 |
{ 0.000002872500f, 0.000000314200f, 0.000012596000f }, |
| 119 |
{ 0.000004149500f, 0.000000453700f, 0.000018201000f }, |
| 120 |
{ 0.000005958600f, 0.000000651100f, 0.000026143700f }, |
| 121 |
{ 0.000008505600f, 0.000000928800f, 0.000037330000f }, |
| 122 |
{ 0.000012068600f, 0.000001317500f, 0.000052987000f }, |
| 123 |
{ 0.000017022600f, 0.000001857200f, 0.000074764000f }, |
| 124 |
{ 0.000023868000f, 0.000002602000f, 0.000104870000f }, |
| 125 |
{ 0.000033266000f, 0.000003625000f, 0.000146220000f }, |
| 126 |
{ 0.000046087000f, 0.000005019000f, 0.000202660000f }, |
| 127 |
{ 0.000063472000f, 0.000006907000f, 0.000279230000f }, |
| 128 |
{ 0.000086892000f, 0.000009449000f, 0.000382450000f }, |
| 129 |
{ 0.000118246000f, 0.000012848000f, 0.000520720000f }, |
| 130 |
{ 0.000159952000f, 0.000017364000f, 0.000704776000f }, |
| 131 |
{ 0.000215080000f, 0.000023327000f, 0.000948230000f }, |
| 132 |
{ 0.000287490000f, 0.000031150000f, 0.001268200000f }, |
| 133 |
{ 0.000381990000f, 0.000041350000f, 0.001686100000f }, |
| 134 |
{ 0.000504550000f, 0.000054560000f, 0.002228500000f }, |
| 135 |
{ 0.000662440000f, 0.000071560000f, 0.002927800000f }, |
| 136 |
{ 0.000864500000f, 0.000093300000f, 0.003823700000f }, |
| 137 |
{ 0.001121500000f, 0.000120870000f, 0.004964200000f }, |
| 138 |
{ 0.001446160000f, 0.000155640000f, 0.006406700000f }, |
| 139 |
{ 0.001853590000f, 0.000199200000f, 0.008219300000f }, |
| 140 |
{ 0.002361600000f, 0.000253400000f, 0.010482200000f }, |
| 141 |
{ 0.002990600000f, 0.000320200000f, 0.013289000000f }, |
| 142 |
{ 0.003764500000f, 0.000402400000f, 0.016747000000f }, |
| 143 |
{ 0.004710200000f, 0.000502300000f, 0.020980000000f }, |
| 144 |
{ 0.005858100000f, 0.000623200000f, 0.026127000000f }, |
| 145 |
{ 0.007242300000f, 0.000768500000f, 0.032344000000f }, |
| 146 |
{ 0.008899600000f, 0.000941700000f, 0.039802000000f }, |
| 147 |
{ 0.010870900000f, 0.001147800000f, 0.048691000000f }, |
| 148 |
{ 0.013198900000f, 0.001390300000f, 0.059210000000f }, |
| 149 |
{ 0.015929200000f, 0.001674000000f, 0.071576000000f }, |
| 150 |
{ 0.019109700000f, 0.002004400000f, 0.086010900000f }, |
| 151 |
{ 0.022788000000f, 0.002386000000f, 0.102740000000f }, |
| 152 |
{ 0.027011000000f, 0.002822000000f, 0.122000000000f }, |
| 153 |
{ 0.031829000000f, 0.003319000000f, 0.144020000000f }, |
| 154 |
{ 0.037278000000f, 0.003880000000f, 0.168990000000f }, |
| 155 |
{ 0.043400000000f, 0.004509000000f, 0.197120000000f }, |
| 156 |
{ 0.050223000000f, 0.005209000000f, 0.228570000000f }, |
| 157 |
{ 0.057764000000f, 0.005985000000f, 0.263470000000f }, |
| 158 |
{ 0.066038000000f, 0.006833000000f, 0.301900000000f }, |
| 159 |
{ 0.075033000000f, 0.007757000000f, 0.343870000000f }, |
| 160 |
{ 0.084736000000f, 0.008756000000f, 0.389366000000f }, |
| 161 |
{ 0.095041000000f, 0.009816000000f, 0.437970000000f }, |
| 162 |
{ 0.105836000000f, 0.010918000000f, 0.489220000000f }, |
| 163 |
{ 0.117066000000f, 0.012058000000f, 0.542900000000f }, |
| 164 |
{ 0.128682000000f, 0.013237000000f, 0.598810000000f }, |
| 165 |
{ 0.140638000000f, 0.014456000000f, 0.656760000000f }, |
| 166 |
{ 0.152893000000f, 0.015717000000f, 0.716580000000f }, |
| 167 |
{ 0.165416000000f, 0.017025000000f, 0.778120000000f }, |
| 168 |
{ 0.178191000000f, 0.018399000000f, 0.841310000000f }, |
| 169 |
{ 0.191214000000f, 0.019848000000f, 0.906110000000f }, |
| 170 |
{ 0.204492000000f, 0.021391000000f, 0.972542000000f }, |
| 171 |
{ 0.217650000000f, 0.022992000000f, 1.038900000000f }, |
| 172 |
{ 0.230267000000f, 0.024598000000f, 1.103100000000f }, |
| 173 |
{ 0.242311000000f, 0.026213000000f, 1.165100000000f }, |
| 174 |
{ 0.253793000000f, 0.027841000000f, 1.224900000000f }, |
| 175 |
{ 0.264737000000f, 0.029497000000f, 1.282500000000f }, |
| 176 |
{ 0.275195000000f, 0.031195000000f, 1.338200000000f }, |
| 177 |
{ 0.285301000000f, 0.032927000000f, 1.392600000000f }, |
| 178 |
{ 0.295143000000f, 0.034738000000f, 1.446100000000f }, |
| 179 |
{ 0.304869000000f, 0.036654000000f, 1.499400000000f }, |
| 180 |
{ 0.314679000000f, 0.038676000000f, 1.553480000000f }, |
| 181 |
{ 0.324355000000f, 0.040792000000f, 1.607200000000f }, |
| 182 |
{ 0.333570000000f, 0.042946000000f, 1.658900000000f }, |
| 183 |
{ 0.342243000000f, 0.045114000000f, 1.708200000000f }, |
| 184 |
{ 0.350312000000f, 0.047333000000f, 1.754800000000f }, |
| 185 |
{ 0.357719000000f, 0.049602000000f, 1.798500000000f }, |
| 186 |
{ 0.364482000000f, 0.051934000000f, 1.839200000000f }, |
| 187 |
{ 0.370493000000f, 0.054337000000f, 1.876600000000f }, |
| 188 |
{ 0.375727000000f, 0.056822000000f, 1.910500000000f }, |
| 189 |
{ 0.380158000000f, 0.059399000000f, 1.940800000000f }, |
| 190 |
{ 0.383734000000f, 0.062077000000f, 1.967280000000f }, |
| 191 |
{ 0.386327000000f, 0.064737000000f, 1.989100000000f }, |
| 192 |
{ 0.387858000000f, 0.067285000000f, 2.005700000000f }, |
| 193 |
{ 0.388396000000f, 0.069764000000f, 2.017400000000f }, |
| 194 |
{ 0.387978000000f, 0.072218000000f, 2.024400000000f }, |
| 195 |
{ 0.386726000000f, 0.074704000000f, 2.027300000000f }, |
| 196 |
{ 0.384696000000f, 0.077272000000f, 2.026400000000f }, |
| 197 |
{ 0.382006000000f, 0.079979000000f, 2.022300000000f }, |
| 198 |
{ 0.378709000000f, 0.082874000000f, 2.015300000000f }, |
| 199 |
{ 0.374915000000f, 0.086000000000f, 2.006000000000f }, |
| 200 |
{ 0.370702000000f, 0.089456000000f, 1.994800000000f }, |
| 201 |
{ 0.366089000000f, 0.092947000000f, 1.981400000000f }, |
| 202 |
{ 0.361045000000f, 0.096275000000f, 1.965300000000f }, |
| 203 |
{ 0.355518000000f, 0.099535000000f, 1.946400000000f }, |
| 204 |
{ 0.349486000000f, 0.102829000000f, 1.924800000000f }, |
| 205 |
{ 0.342957000000f, 0.106256000000f, 1.900700000000f }, |
| 206 |
{ 0.335893000000f, 0.109901000000f, 1.874100000000f }, |
| 207 |
{ 0.328284000000f, 0.113835000000f, 1.845100000000f }, |
| 208 |
{ 0.320150000000f, 0.118167000000f, 1.813900000000f }, |
| 209 |
{ 0.311475000000f, 0.122932000000f, 1.780600000000f }, |
| 210 |
{ 0.302273000000f, 0.128201000000f, 1.745370000000f }, |
| 211 |
{ 0.292858000000f, 0.133457000000f, 1.709100000000f }, |
| 212 |
{ 0.283502000000f, 0.138323000000f, 1.672300000000f }, |
| 213 |
{ 0.274044000000f, 0.143042000000f, 1.634700000000f }, |
| 214 |
{ 0.264263000000f, 0.147787000000f, 1.595600000000f }, |
| 215 |
{ 0.254085000000f, 0.152761000000f, 1.554900000000f }, |
| 216 |
{ 0.243392000000f, 0.158102000000f, 1.512200000000f }, |
| 217 |
{ 0.232187000000f, 0.163941000000f, 1.467300000000f }, |
| 218 |
{ 0.220488000000f, 0.170362000000f, 1.419900000000f }, |
| 219 |
{ 0.208198000000f, 0.177425000000f, 1.370000000000f }, |
| 220 |
{ 0.195618000000f, 0.185190000000f, 1.317560000000f }, |
| 221 |
{ 0.183034000000f, 0.193025000000f, 1.262400000000f }, |
| 222 |
{ 0.170222000000f, 0.200313000000f, 1.205000000000f }, |
| 223 |
{ 0.157348000000f, 0.207156000000f, 1.146600000000f }, |
| 224 |
{ 0.144650000000f, 0.213644000000f, 1.088000000000f }, |
| 225 |
{ 0.132349000000f, 0.219940000000f, 1.030200000000f }, |
| 226 |
{ 0.120584000000f, 0.226170000000f, 0.973830000000f }, |
| 227 |
{ 0.109456000000f, 0.232467000000f, 0.919430000000f }, |
| 228 |
{ 0.099042000000f, 0.239025000000f, 0.867460000000f }, |
| 229 |
{ 0.089388000000f, 0.245997000000f, 0.818280000000f }, |
| 230 |
{ 0.080507000000f, 0.253589000000f, 0.772125000000f }, |
| 231 |
{ 0.072034000000f, 0.261876000000f, 0.728290000000f }, |
| 232 |
{ 0.063710000000f, 0.270643000000f, 0.686040000000f }, |
| 233 |
{ 0.055694000000f, 0.279645000000f, 0.645530000000f }, |
| 234 |
{ 0.048117000000f, 0.288694000000f, 0.606850000000f }, |
| 235 |
{ 0.041072000000f, 0.297665000000f, 0.570060000000f }, |
| 236 |
{ 0.034642000000f, 0.306469000000f, 0.535220000000f }, |
| 237 |
{ 0.028896000000f, 0.315035000000f, 0.502340000000f }, |
| 238 |
{ 0.023876000000f, 0.323335000000f, 0.471400000000f }, |
| 239 |
{ 0.019628000000f, 0.331366000000f, 0.442390000000f }, |
| 240 |
{ 0.016172000000f, 0.339133000000f, 0.415254000000f }, |
| 241 |
{ 0.013300000000f, 0.347860000000f, 0.390024000000f }, |
| 242 |
{ 0.010759000000f, 0.358326000000f, 0.366399000000f }, |
| 243 |
{ 0.008542000000f, 0.370001000000f, 0.344015000000f }, |
| 244 |
{ 0.006661000000f, 0.382464000000f, 0.322689000000f }, |
| 245 |
{ 0.005132000000f, 0.395379000000f, 0.302356000000f }, |
| 246 |
{ 0.003982000000f, 0.408482000000f, 0.283036000000f }, |
| 247 |
{ 0.003239000000f, 0.421588000000f, 0.264816000000f }, |
| 248 |
{ 0.002934000000f, 0.434619000000f, 0.247848000000f }, |
| 249 |
{ 0.003114000000f, 0.447601000000f, 0.232318000000f }, |
| 250 |
{ 0.003816000000f, 0.460777000000f, 0.218502000000f }, |
| 251 |
{ 0.005095000000f, 0.474340000000f, 0.205851000000f }, |
| 252 |
{ 0.006936000000f, 0.488200000000f, 0.193596000000f }, |
| 253 |
{ 0.009299000000f, 0.502340000000f, 0.181736000000f }, |
| 254 |
{ 0.012147000000f, 0.516740000000f, 0.170281000000f }, |
| 255 |
{ 0.015444000000f, 0.531360000000f, 0.159249000000f }, |
| 256 |
{ 0.019156000000f, 0.546190000000f, 0.148673000000f }, |
| 257 |
{ 0.023250000000f, 0.561180000000f, 0.138609000000f }, |
| 258 |
{ 0.027690000000f, 0.576290000000f, 0.129096000000f }, |
| 259 |
{ 0.032444000000f, 0.591500000000f, 0.120215000000f }, |
| 260 |
{ 0.037465000000f, 0.606741000000f, 0.112044000000f }, |
| 261 |
{ 0.042956000000f, 0.622150000000f, 0.104710000000f }, |
| 262 |
{ 0.049114000000f, 0.637830000000f, 0.098196000000f }, |
| 263 |
{ 0.055920000000f, 0.653710000000f, 0.092361000000f }, |
| 264 |
{ 0.063349000000f, 0.669680000000f, 0.087088000000f }, |
| 265 |
{ 0.071358000000f, 0.685660000000f, 0.082248000000f }, |
| 266 |
{ 0.079901000000f, 0.701550000000f, 0.077744000000f }, |
| 267 |
{ 0.088909000000f, 0.717230000000f, 0.073456000000f }, |
| 268 |
{ 0.098293000000f, 0.732570000000f, 0.069268000000f }, |
| 269 |
{ 0.107949000000f, 0.747460000000f, 0.065060000000f }, |
| 270 |
{ 0.117749000000f, 0.761757000000f, 0.060709000000f }, |
| 271 |
{ 0.127839000000f, 0.775340000000f, 0.056457000000f }, |
| 272 |
{ 0.138450000000f, 0.788220000000f, 0.052609000000f }, |
| 273 |
{ 0.149516000000f, 0.800460000000f, 0.049122000000f }, |
| 274 |
{ 0.161041000000f, 0.812140000000f, 0.045954000000f }, |
| 275 |
{ 0.172953000000f, 0.823330000000f, 0.043050000000f }, |
| 276 |
{ 0.185209000000f, 0.834120000000f, 0.040368000000f }, |
| 277 |
{ 0.197755000000f, 0.844600000000f, 0.037839000000f }, |
| 278 |
{ 0.210538000000f, 0.854870000000f, 0.035384000000f }, |
| 279 |
{ 0.223460000000f, 0.865040000000f, 0.032949000000f }, |
| 280 |
{ 0.236491000000f, 0.875211000000f, 0.030451000000f }, |
| 281 |
{ 0.249633000000f, 0.885370000000f, 0.028029000000f }, |
| 282 |
{ 0.262972000000f, 0.895370000000f, 0.025862000000f }, |
| 283 |
{ 0.276515000000f, 0.905150000000f, 0.023920000000f }, |
| 284 |
{ 0.290269000000f, 0.914650000000f, 0.022174000000f }, |
| 285 |
{ 0.304213000000f, 0.923810000000f, 0.020584000000f }, |
| 286 |
{ 0.318361000000f, 0.932550000000f, 0.019127000000f }, |
| 287 |
{ 0.332705000000f, 0.940810000000f, 0.017740000000f }, |
| 288 |
{ 0.347232000000f, 0.948520000000f, 0.016403000000f }, |
| 289 |
{ 0.361926000000f, 0.955600000000f, 0.015064000000f }, |
| 290 |
{ 0.376772000000f, 0.961988000000f, 0.013676000000f }, |
| 291 |
{ 0.391683000000f, 0.967540000000f, 0.012308000000f }, |
| 292 |
{ 0.406594000000f, 0.972230000000f, 0.011056000000f }, |
| 293 |
{ 0.421539000000f, 0.976170000000f, 0.009915000000f }, |
| 294 |
{ 0.436517000000f, 0.979460000000f, 0.008872000000f }, |
| 295 |
{ 0.451584000000f, 0.982200000000f, 0.007918000000f }, |
| 296 |
{ 0.466782000000f, 0.984520000000f, 0.007030000000f }, |
| 297 |
{ 0.482147000000f, 0.986520000000f, 0.006223000000f }, |
| 298 |
{ 0.497738000000f, 0.988320000000f, 0.005453000000f }, |
| 299 |
{ 0.513606000000f, 0.990020000000f, 0.004714000000f }, |
| 300 |
{ 0.529826000000f, 0.991761000000f, 0.003988000000f }, |
| 301 |
{ 0.546440000000f, 0.993530000000f, 0.003289000000f }, |
| 302 |
{ 0.563426000000f, 0.995230000000f, 0.002646000000f }, |
| 303 |
{ 0.580726000000f, 0.996770000000f, 0.002063000000f }, |
| 304 |
{ 0.598290000000f, 0.998090000000f, 0.001533000000f }, |
| 305 |
{ 0.616053000000f, 0.999110000000f, 0.001091000000f }, |
| 306 |
{ 0.633948000000f, 0.999770000000f, 0.000711000000f }, |
| 307 |
{ 0.651901000000f, 1.000000000000f, 0.000407000000f }, |
| 308 |
{ 0.669824000000f, 0.999710000000f, 0.000184000000f }, |
| 309 |
{ 0.687632000000f, 0.998850000000f, 0.000047000000f }, |
| 310 |
{ 0.705224000000f, 0.997340000000f, 0.000000000000f }, |
| 311 |
{ 0.722773000000f, 0.995260000000f, 0.000000000000f }, |
| 312 |
{ 0.740483000000f, 0.992740000000f, 0.000000000000f }, |
| 313 |
{ 0.758273000000f, 0.989750000000f, 0.000000000000f }, |
| 314 |
{ 0.776083000000f, 0.986300000000f, 0.000000000000f }, |
| 315 |
{ 0.793832000000f, 0.982380000000f, 0.000000000000f }, |
| 316 |
{ 0.811436000000f, 0.977980000000f, 0.000000000000f }, |
| 317 |
{ 0.828822000000f, 0.973110000000f, 0.000000000000f }, |
| 318 |
{ 0.845879000000f, 0.967740000000f, 0.000000000000f }, |
| 319 |
{ 0.862525000000f, 0.961890000000f, 0.000000000000f }, |
| 320 |
{ 0.878655000000f, 0.955552000000f, 0.000000000000f }, |
| 321 |
{ 0.894208000000f, 0.948601000000f, 0.000000000000f }, |
| 322 |
{ 0.909206000000f, 0.940981000000f, 0.000000000000f }, |
| 323 |
{ 0.923672000000f, 0.932798000000f, 0.000000000000f }, |
| 324 |
{ 0.937638000000f, 0.924158000000f, 0.000000000000f }, |
| 325 |
{ 0.951162000000f, 0.915175000000f, 0.000000000000f }, |
| 326 |
{ 0.964283000000f, 0.905954000000f, 0.000000000000f }, |
| 327 |
{ 0.977068000000f, 0.896608000000f, 0.000000000000f }, |
| 328 |
{ 0.989590000000f, 0.887249000000f, 0.000000000000f }, |
| 329 |
{ 1.001910000000f, 0.877986000000f, 0.000000000000f }, |
| 330 |
{ 1.014160000000f, 0.868934000000f, 0.000000000000f }, |
| 331 |
{ 1.026500000000f, 0.860164000000f, 0.000000000000f }, |
| 332 |
{ 1.038800000000f, 0.851519000000f, 0.000000000000f }, |
| 333 |
{ 1.051000000000f, 0.842963000000f, 0.000000000000f }, |
| 334 |
{ 1.062900000000f, 0.834393000000f, 0.000000000000f }, |
| 335 |
{ 1.074300000000f, 0.825623000000f, 0.000000000000f }, |
| 336 |
{ 1.085200000000f, 0.816764000000f, 0.000000000000f }, |
| 337 |
{ 1.095200000000f, 0.807544000000f, 0.000000000000f }, |
| 338 |
{ 1.104200000000f, 0.797947000000f, 0.000000000000f }, |
| 339 |
{ 1.112000000000f, 0.787893000000f, 0.000000000000f }, |
| 340 |
{ 1.118520000000f, 0.777405000000f, 0.000000000000f }, |
| 341 |
{ 1.123800000000f, 0.766490000000f, 0.000000000000f }, |
| 342 |
{ 1.128000000000f, 0.755309000000f, 0.000000000000f }, |
| 343 |
{ 1.131100000000f, 0.743845000000f, 0.000000000000f }, |
| 344 |
{ 1.133200000000f, 0.732190000000f, 0.000000000000f }, |
| 345 |
{ 1.134300000000f, 0.720353000000f, 0.000000000000f }, |
| 346 |
{ 1.134300000000f, 0.708281000000f, 0.000000000000f }, |
| 347 |
{ 1.133300000000f, 0.696055000000f, 0.000000000000f }, |
| 348 |
{ 1.131200000000f, 0.683621000000f, 0.000000000000f }, |
| 349 |
{ 1.128100000000f, 0.671048000000f, 0.000000000000f }, |
| 350 |
{ 1.123990000000f, 0.658341000000f, 0.000000000000f }, |
| 351 |
{ 1.118900000000f, 0.645545000000f, 0.000000000000f }, |
| 352 |
{ 1.112900000000f, 0.632718000000f, 0.000000000000f }, |
| 353 |
{ 1.105900000000f, 0.619815000000f, 0.000000000000f }, |
| 354 |
{ 1.098000000000f, 0.606887000000f, 0.000000000000f }, |
| 355 |
{ 1.089100000000f, 0.593878000000f, 0.000000000000f }, |
| 356 |
{ 1.079200000000f, 0.580781000000f, 0.000000000000f }, |
| 357 |
{ 1.068400000000f, 0.567653000000f, 0.000000000000f }, |
| 358 |
{ 1.056700000000f, 0.554490000000f, 0.000000000000f }, |
| 359 |
{ 1.044000000000f, 0.541228000000f, 0.000000000000f }, |
| 360 |
{ 1.030480000000f, 0.527963000000f, 0.000000000000f }, |
| 361 |
{ 1.016000000000f, 0.514634000000f, 0.000000000000f }, |
| 362 |
{ 1.000800000000f, 0.501363000000f, 0.000000000000f }, |
| 363 |
{ 0.984790000000f, 0.488124000000f, 0.000000000000f }, |
| 364 |
{ 0.968080000000f, 0.474935000000f, 0.000000000000f }, |
| 365 |
{ 0.950740000000f, 0.461834000000f, 0.000000000000f }, |
| 366 |
{ 0.932800000000f, 0.448823000000f, 0.000000000000f }, |
| 367 |
{ 0.914340000000f, 0.435917000000f, 0.000000000000f }, |
| 368 |
{ 0.895390000000f, 0.423153000000f, 0.000000000000f }, |
| 369 |
{ 0.876030000000f, 0.410526000000f, 0.000000000000f }, |
| 370 |
{ 0.856297000000f, 0.398057000000f, 0.000000000000f }, |
| 371 |
{ 0.836350000000f, 0.385835000000f, 0.000000000000f }, |
| 372 |
{ 0.816290000000f, 0.373951000000f, 0.000000000000f }, |
| 373 |
{ 0.796050000000f, 0.362311000000f, 0.000000000000f }, |
| 374 |
{ 0.775610000000f, 0.350863000000f, 0.000000000000f }, |
| 375 |
{ 0.754930000000f, 0.339554000000f, 0.000000000000f }, |
| 376 |
{ 0.733990000000f, 0.328309000000f, 0.000000000000f }, |
| 377 |
{ 0.712780000000f, 0.317118000000f, 0.000000000000f }, |
| 378 |
{ 0.691290000000f, 0.305936000000f, 0.000000000000f }, |
| 379 |
{ 0.669520000000f, 0.294737000000f, 0.000000000000f }, |
| 380 |
{ 0.647467000000f, 0.283493000000f, 0.000000000000f }, |
| 381 |
{ 0.625110000000f, 0.272222000000f, 0.000000000000f }, |
| 382 |
{ 0.602520000000f, 0.260990000000f, 0.000000000000f }, |
| 383 |
{ 0.579890000000f, 0.249877000000f, 0.000000000000f }, |
| 384 |
{ 0.557370000000f, 0.238946000000f, 0.000000000000f }, |
| 385 |
{ 0.535110000000f, 0.228254000000f, 0.000000000000f }, |
| 386 |
{ 0.513240000000f, 0.217853000000f, 0.000000000000f }, |
| 387 |
{ 0.491860000000f, 0.207780000000f, 0.000000000000f }, |
| 388 |
{ 0.471080000000f, 0.198072000000f, 0.000000000000f }, |
| 389 |
{ 0.450960000000f, 0.188748000000f, 0.000000000000f }, |
| 390 |
{ 0.431567000000f, 0.179828000000f, 0.000000000000f }, |
| 391 |
{ 0.412870000000f, 0.171285000000f, 0.000000000000f }, |
| 392 |
{ 0.394750000000f, 0.163059000000f, 0.000000000000f }, |
| 393 |
{ 0.377210000000f, 0.155151000000f, 0.000000000000f }, |
| 394 |
{ 0.360190000000f, 0.147535000000f, 0.000000000000f }, |
| 395 |
{ 0.343690000000f, 0.140211000000f, 0.000000000000f }, |
| 396 |
{ 0.327690000000f, 0.133170000000f, 0.000000000000f }, |
| 397 |
{ 0.312170000000f, 0.126400000000f, 0.000000000000f }, |
| 398 |
{ 0.297110000000f, 0.119892000000f, 0.000000000000f }, |
| 399 |
{ 0.282500000000f, 0.113640000000f, 0.000000000000f }, |
| 400 |
{ 0.268329000000f, 0.107633000000f, 0.000000000000f }, |
| 401 |
{ 0.254590000000f, 0.101870000000f, 0.000000000000f }, |
| 402 |
{ 0.241300000000f, 0.096347000000f, 0.000000000000f }, |
| 403 |
{ 0.228480000000f, 0.091063000000f, 0.000000000000f }, |
| 404 |
{ 0.216140000000f, 0.086010000000f, 0.000000000000f }, |
| 405 |
{ 0.204300000000f, 0.081187000000f, 0.000000000000f }, |
| 406 |
{ 0.192950000000f, 0.076583000000f, 0.000000000000f }, |
| 407 |
{ 0.182110000000f, 0.072198000000f, 0.000000000000f }, |
| 408 |
{ 0.171770000000f, 0.068024000000f, 0.000000000000f }, |
| 409 |
{ 0.161920000000f, 0.064052000000f, 0.000000000000f }, |
| 410 |
{ 0.152568000000f, 0.060281000000f, 0.000000000000f }, |
| 411 |
{ 0.143670000000f, 0.056697000000f, 0.000000000000f }, |
| 412 |
{ 0.135200000000f, 0.053292000000f, 0.000000000000f }, |
| 413 |
{ 0.127130000000f, 0.050059000000f, 0.000000000000f }, |
| 414 |
{ 0.119480000000f, 0.046998000000f, 0.000000000000f }, |
| 415 |
{ 0.112210000000f, 0.044096000000f, 0.000000000000f }, |
| 416 |
{ 0.105310000000f, 0.041345000000f, 0.000000000000f }, |
| 417 |
{ 0.098786000000f, 0.038750700000f, 0.000000000000f }, |
| 418 |
{ 0.092610000000f, 0.036297800000f, 0.000000000000f }, |
| 419 |
{ 0.086773000000f, 0.033983200000f, 0.000000000000f }, |
| 420 |
{ 0.081260600000f, 0.031800400000f, 0.000000000000f }, |
| 421 |
{ 0.076048000000f, 0.029739500000f, 0.000000000000f }, |
| 422 |
{ 0.071114000000f, 0.027791800000f, 0.000000000000f }, |
| 423 |
{ 0.066454000000f, 0.025955100000f, 0.000000000000f }, |
| 424 |
{ 0.062062000000f, 0.024226300000f, 0.000000000000f }, |
| 425 |
{ 0.057930000000f, 0.022601700000f, 0.000000000000f }, |
| 426 |
{ 0.054050000000f, 0.021077900000f, 0.000000000000f }, |
| 427 |
{ 0.050412000000f, 0.019650500000f, 0.000000000000f }, |
| 428 |
{ 0.047006000000f, 0.018315300000f, 0.000000000000f }, |
| 429 |
{ 0.043823000000f, 0.017068600000f, 0.000000000000f }, |
| 430 |
{ 0.040850800000f, 0.015905100000f, 0.000000000000f }, |
| 431 |
{ 0.038072000000f, 0.014818300000f, 0.000000000000f }, |
| 432 |
{ 0.035468000000f, 0.013800800000f, 0.000000000000f }, |
| 433 |
{ 0.033031000000f, 0.012849500000f, 0.000000000000f }, |
| 434 |
{ 0.030753000000f, 0.011960700000f, 0.000000000000f }, |
| 435 |
{ 0.028623000000f, 0.011130300000f, 0.000000000000f }, |
| 436 |
{ 0.026635000000f, 0.010355500000f, 0.000000000000f }, |
| 437 |
{ 0.024781000000f, 0.009633200000f, 0.000000000000f }, |
| 438 |
{ 0.023052000000f, 0.008959900000f, 0.000000000000f }, |
| 439 |
{ 0.021441000000f, 0.008332400000f, 0.000000000000f }, |
| 440 |
{ 0.019941300000f, 0.007748800000f, 0.000000000000f }, |
| 441 |
{ 0.018544000000f, 0.007204600000f, 0.000000000000f }, |
| 442 |
{ 0.017241000000f, 0.006697500000f, 0.000000000000f }, |
| 443 |
{ 0.016027000000f, 0.006225100000f, 0.000000000000f }, |
| 444 |
{ 0.014896000000f, 0.005785000000f, 0.000000000000f }, |
| 445 |
{ 0.013842000000f, 0.005375100000f, 0.000000000000f }, |
| 446 |
{ 0.012862000000f, 0.004994100000f, 0.000000000000f }, |
| 447 |
{ 0.011949000000f, 0.004639200000f, 0.000000000000f }, |
| 448 |
{ 0.011100000000f, 0.004309300000f, 0.000000000000f }, |
| 449 |
{ 0.010311000000f, 0.004002800000f, 0.000000000000f }, |
| 450 |
{ 0.009576880000f, 0.003717740000f, 0.000000000000f }, |
| 451 |
{ 0.008894000000f, 0.003452620000f, 0.000000000000f }, |
| 452 |
{ 0.008258100000f, 0.003205830000f, 0.000000000000f }, |
| 453 |
{ 0.007666400000f, 0.002976230000f, 0.000000000000f }, |
| 454 |
{ 0.007116300000f, 0.002762810000f, 0.000000000000f }, |
| 455 |
{ 0.006605200000f, 0.002564560000f, 0.000000000000f }, |
| 456 |
{ 0.006130600000f, 0.002380480000f, 0.000000000000f }, |
| 457 |
{ 0.005690300000f, 0.002209710000f, 0.000000000000f }, |
| 458 |
{ 0.005281900000f, 0.002051320000f, 0.000000000000f }, |
| 459 |
{ 0.004903300000f, 0.001904490000f, 0.000000000000f }, |
| 460 |
{ 0.004552630000f, 0.001768470000f, 0.000000000000f }, |
| 461 |
{ 0.004227500000f, 0.001642360000f, 0.000000000000f }, |
| 462 |
{ 0.003925800000f, 0.001525350000f, 0.000000000000f }, |
| 463 |
{ 0.003645700000f, 0.001416720000f, 0.000000000000f }, |
| 464 |
{ 0.003385900000f, 0.001315950000f, 0.000000000000f }, |
| 465 |
{ 0.003144700000f, 0.001222390000f, 0.000000000000f }, |
| 466 |
{ 0.002920800000f, 0.001135550000f, 0.000000000000f }, |
| 467 |
{ 0.002713000000f, 0.001054940000f, 0.000000000000f }, |
| 468 |
{ 0.002520200000f, 0.000980140000f, 0.000000000000f }, |
| 469 |
{ 0.002341100000f, 0.000910660000f, 0.000000000000f }, |
| 470 |
{ 0.002174960000f, 0.000846190000f, 0.000000000000f }, |
| 471 |
{ 0.002020600000f, 0.000786290000f, 0.000000000000f }, |
| 472 |
{ 0.001877300000f, 0.000730680000f, 0.000000000000f }, |
| 473 |
{ 0.001744100000f, 0.000678990000f, 0.000000000000f }, |
| 474 |
{ 0.001620500000f, 0.000631010000f, 0.000000000000f }, |
| 475 |
{ 0.001505700000f, 0.000586440000f, 0.000000000000f }, |
| 476 |
{ 0.001399200000f, 0.000545110000f, 0.000000000000f }, |
| 477 |
{ 0.001300400000f, 0.000506720000f, 0.000000000000f }, |
| 478 |
{ 0.001208700000f, 0.000471110000f, 0.000000000000f }, |
| 479 |
{ 0.001123600000f, 0.000438050000f, 0.000000000000f }, |
| 480 |
{ 0.001044760000f, 0.000407410000f, 0.000000000000f }, |
| 481 |
{ 0.000971560000f, 0.000378962000f, 0.000000000000f }, |
| 482 |
{ 0.000903600000f, 0.000352543000f, 0.000000000000f }, |
| 483 |
{ 0.000840480000f, 0.000328001000f, 0.000000000000f }, |
| 484 |
{ 0.000781870000f, 0.000305208000f, 0.000000000000f }, |
| 485 |
{ 0.000727450000f, 0.000284041000f, 0.000000000000f }, |
| 486 |
{ 0.000676900000f, 0.000264375000f, 0.000000000000f }, |
| 487 |
{ 0.000629960000f, 0.000246109000f, 0.000000000000f }, |
| 488 |
{ 0.000586370000f, 0.000229143000f, 0.000000000000f }, |
| 489 |
{ 0.000545870000f, 0.000213376000f, 0.000000000000f }, |
| 490 |
{ 0.000508258000f, 0.000198730000f, 0.000000000000f }, |
| 491 |
{ 0.000473300000f, 0.000185115000f, 0.000000000000f }, |
| 492 |
{ 0.000440800000f, 0.000172454000f, 0.000000000000f }, |
| 493 |
{ 0.000410580000f, 0.000160678000f, 0.000000000000f }, |
| 494 |
{ 0.000382490000f, 0.000149730000f, 0.000000000000f }, |
| 495 |
{ 0.000356380000f, 0.000139550000f, 0.000000000000f }, |
| 496 |
{ 0.000332110000f, 0.000130086000f, 0.000000000000f }, |
| 497 |
{ 0.000309550000f, 0.000121290000f, 0.000000000000f }, |
| 498 |
{ 0.000288580000f, 0.000113106000f, 0.000000000000f }, |
| 499 |
{ 0.000269090000f, 0.000105501000f, 0.000000000000f }, |
| 500 |
{ 0.000250969000f, 0.000098428000f, 0.000000000000f }, |
| 501 |
{ 0.000234130000f, 0.000091853000f, 0.000000000000f }, |
| 502 |
{ 0.000218470000f, 0.000085738000f, 0.000000000000f }, |
| 503 |
{ 0.000203910000f, 0.000080048000f, 0.000000000000f }, |
| 504 |
{ 0.000190350000f, 0.000074751000f, 0.000000000000f }, |
| 505 |
{ 0.000177730000f, 0.000069819000f, 0.000000000000f }, |
| 506 |
{ 0.000165970000f, 0.000065222000f, 0.000000000000f }, |
| 507 |
{ 0.000155020000f, 0.000060939000f, 0.000000000000f }, |
| 508 |
{ 0.000144800000f, 0.000056942000f, 0.000000000000f }, |
| 509 |
{ 0.000135280000f, 0.000053217000f, 0.000000000000f }, |
| 510 |
{ 0.000126390000f, 0.000049737000f, 0.000000000000f }, |
| 511 |
{ 0.000118100000f, 0.000046491000f, 0.000000000000f }, |
| 512 |
{ 0.000110370000f, 0.000043464000f, 0.000000000000f }, |
| 513 |
{ 0.000103150000f, 0.000040635000f, 0.000000000000f }, |
| 514 |
{ 0.000096427000f, 0.000038000000f, 0.000000000000f }, |
| 515 |
{ 0.000090151000f, 0.000035540500f, 0.000000000000f }, |
| 516 |
{ 0.000084294000f, 0.000033244800f, 0.000000000000f }, |
| 517 |
{ 0.000078830000f, 0.000031100600f, 0.000000000000f }, |
| 518 |
{ 0.000073729000f, 0.000029099000f, 0.000000000000f }, |
| 519 |
{ 0.000068969000f, 0.000027230700f, 0.000000000000f }, |
| 520 |
{ 0.000064525800f, 0.000025486000f, 0.000000000000f }, |
| 521 |
{ 0.000060376000f, 0.000023856100f, 0.000000000000f }, |
| 522 |
{ 0.000056500000f, 0.000022333200f, 0.000000000000f }, |
| 523 |
{ 0.000052880000f, 0.000020910400f, 0.000000000000f }, |
| 524 |
{ 0.000049498000f, 0.000019580800f, 0.000000000000f }, |
| 525 |
{ 0.000046339000f, 0.000018338400f, 0.000000000000f }, |
| 526 |
{ 0.000043389000f, 0.000017177700f, 0.000000000000f }, |
| 527 |
{ 0.000040634000f, 0.000016093400f, 0.000000000000f }, |
| 528 |
{ 0.000038060000f, 0.000015080000f, 0.000000000000f }, |
| 529 |
{ 0.000035657000f, 0.000014133600f, 0.000000000000f }, |
| 530 |
{ 0.000033411700f, 0.000013249000f, 0.000000000000f }, |
| 531 |
{ 0.000031315000f, 0.000012422600f, 0.000000000000f }, |
| 532 |
{ 0.000029355000f, 0.000011649900f, 0.000000000000f }, |
| 533 |
{ 0.000027524000f, 0.000010927700f, 0.000000000000f }, |
| 534 |
{ 0.000025811000f, 0.000010251900f, 0.000000000000f }, |
| 535 |
{ 0.000024209000f, 0.000009619600f, 0.000000000000f }, |
| 536 |
{ 0.000022711000f, 0.000009028100f, 0.000000000000f }, |
| 537 |
{ 0.000021308000f, 0.000008474000f, 0.000000000000f }, |
| 538 |
{ 0.000019994000f, 0.000007954800f, 0.000000000000f }, |
| 539 |
{ 0.000018764000f, 0.000007468600f, 0.000000000000f }, |
| 540 |
{ 0.000017611500f, 0.000007012800f, 0.000000000000f }, |
| 541 |
{ 0.000016532000f, 0.000006585800f, 0.000000000000f }, |
| 542 |
{ 0.000015521000f, 0.000006185700f, 0.000000000000f }, |
| 543 |
{ 0.000014574000f, 0.000005810700f, 0.000000000000f }, |
| 544 |
{ 0.000013686000f, 0.000005459000f, 0.000000000000f }, |
| 545 |
{ 0.000012855000f, 0.000005129800f, 0.000000000000f }, |
| 546 |
{ 0.000012075000f, 0.000004820600f, 0.000000000000f }, |
| 547 |
{ 0.000011345000f, 0.000004531200f, 0.000000000000f }, |
| 548 |
{ 0.000010659000f, 0.000004259100f, 0.000000000000f }, |
| 549 |
{ 0.000010017000f, 0.000004004200f, 0.000000000000f }, |
| 550 |
{ 0.000009413630f, 0.000003764730f, 0.000000000000f }, |
| 551 |
{ 0.000008847900f, 0.000003539950f, 0.000000000000f }, |
| 552 |
{ 0.000008317100f, 0.000003329140f, 0.000000000000f }, |
| 553 |
{ 0.000007819000f, 0.000003131150f, 0.000000000000f }, |
| 554 |
{ 0.000007351600f, 0.000002945290f, 0.000000000000f }, |
| 555 |
{ 0.000006913000f, 0.000002770810f, 0.000000000000f }, |
| 556 |
{ 0.000006501500f, 0.000002607050f, 0.000000000000f }, |
| 557 |
{ 0.000006115300f, 0.000002453290f, 0.000000000000f }, |
| 558 |
{ 0.000005752900f, 0.000002308940f, 0.000000000000f }, |
| 559 |
{ 0.000005412700f, 0.000002173380f, 0.000000000000f }, |
| 560 |
{ 0.000005093470f, 0.000002046130f, 0.000000000000f }, |
| 561 |
{ 0.000004793800f, 0.000001926620f, 0.000000000000f }, |
| 562 |
{ 0.000004512500f, 0.000001814400f, 0.000000000000f }, |
| 563 |
{ 0.000004248300f, 0.000001708950f, 0.000000000000f }, |
| 564 |
{ 0.000004000200f, 0.000001609880f, 0.000000000000f }, |
| 565 |
{ 0.000003767100f, 0.000001516770f, 0.000000000000f }, |
| 566 |
{ 0.000003548000f, 0.000001429210f, 0.000000000000f }, |
| 567 |
{ 0.000003342100f, 0.000001346860f, 0.000000000000f }, |
| 568 |
{ 0.000003148500f, 0.000001269450f, 0.000000000000f }, |
| 569 |
{ 0.000002966500f, 0.000001196620f, 0.000000000000f }, |
| 570 |
{ 0.000002795310f, 0.000001128090f, 0.000000000000f }, |
| 571 |
{ 0.000002634500f, 0.000001063680f, 0.000000000000f }, |
| 572 |
{ 0.000002483400f, 0.000001003130f, 0.000000000000f }, |
| 573 |
{ 0.000002341400f, 0.000000946220f, 0.000000000000f }, |
| 574 |
{ 0.000002207800f, 0.000000892630f, 0.000000000000f }, |
| 575 |
{ 0.000002082000f, 0.000000842160f, 0.000000000000f }, |
| 576 |
{ 0.000001963600f, 0.000000794640f, 0.000000000000f }, |
| 577 |
{ 0.000001851900f, 0.000000749780f, 0.000000000000f }, |
| 578 |
{ 0.000001746500f, 0.000000707440f, 0.000000000000f }, |
| 579 |
{ 0.000001647100f, 0.000000667480f, 0.000000000000f }, |
| 580 |
{ 0.000001553140f, 0.000000629700f, 0.000000000000f } |
| 581 |
}; |
| 582 |
|
| 583 |
// CIE Standard Illuminant D65 relative spectral power distribution, |
| 584 |
// from 300nm to 830, at 5nm intervals |
| 585 |
// |
| 586 |
// Data source: |
| 587 |
// https://en.wikipedia.org/wiki/Illuminant_D65 |
| 588 |
// https://cielab.xyz/pdf/CIE_sel_colorimetric_tables.xls |
| 589 |
const size_t CIE_D65_INTERVAL = 5; |
| 590 |
const size_t CIE_D65_START = 300; |
| 591 |
const size_t CIE_D65_END = 830; |
| 592 |
const size_t CIE_D65_COUNT = 107; |
| 593 |
const float CIE_D65[CIE_D65_COUNT] = { |
| 594 |
0.0341f, |
| 595 |
1.6643f, |
| 596 |
3.2945f, |
| 597 |
11.7652f, |
| 598 |
20.2360f, |
| 599 |
28.6447f, |
| 600 |
37.0535f, |
| 601 |
38.5011f, |
| 602 |
39.9488f, |
| 603 |
42.4302f, |
| 604 |
44.9117f, |
| 605 |
45.7750f, |
| 606 |
46.6383f, |
| 607 |
49.3637f, |
| 608 |
52.0891f, |
| 609 |
51.0323f, |
| 610 |
49.9755f, |
| 611 |
52.3118f, |
| 612 |
54.6482f, |
| 613 |
68.7015f, |
| 614 |
82.7549f, |
| 615 |
87.1204f, |
| 616 |
91.4860f, |
| 617 |
92.4589f, |
| 618 |
93.4318f, |
| 619 |
90.0570f, |
| 620 |
86.6823f, |
| 621 |
95.7736f, |
| 622 |
104.865f, |
| 623 |
110.936f, |
| 624 |
117.008f, |
| 625 |
117.410f, |
| 626 |
117.812f, |
| 627 |
116.336f, |
| 628 |
114.861f, |
| 629 |
115.392f, |
| 630 |
115.923f, |
| 631 |
112.367f, |
| 632 |
108.811f, |
| 633 |
109.082f, |
| 634 |
109.354f, |
| 635 |
108.578f, |
| 636 |
107.802f, |
| 637 |
106.296f, |
| 638 |
104.790f, |
| 639 |
106.239f, |
| 640 |
107.689f, |
| 641 |
106.047f, |
| 642 |
104.405f, |
| 643 |
104.225f, |
| 644 |
104.046f, |
| 645 |
102.023f, |
| 646 |
100.000f, |
| 647 |
98.1671f, |
| 648 |
96.3342f, |
| 649 |
96.0611f, |
| 650 |
95.7880f, |
| 651 |
92.2368f, |
| 652 |
88.6856f, |
| 653 |
89.3459f, |
| 654 |
90.0062f, |
| 655 |
89.8026f, |
| 656 |
89.5991f, |
| 657 |
88.6489f, |
| 658 |
87.6987f, |
| 659 |
85.4936f, |
| 660 |
83.2886f, |
| 661 |
83.4939f, |
| 662 |
83.6992f, |
| 663 |
81.8630f, |
| 664 |
80.0268f, |
| 665 |
80.1207f, |
| 666 |
80.2146f, |
| 667 |
81.2462f, |
| 668 |
82.2778f, |
| 669 |
80.2810f, |
| 670 |
78.2842f, |
| 671 |
74.0027f, |
| 672 |
69.7213f, |
| 673 |
70.6652f, |
| 674 |
71.6091f, |
| 675 |
72.9790f, |
| 676 |
74.3490f, |
| 677 |
67.9765f, |
| 678 |
61.6040f, |
| 679 |
65.7448f, |
| 680 |
69.8856f, |
| 681 |
72.4863f, |
| 682 |
75.0870f, |
| 683 |
69.3398f, |
| 684 |
63.5927f, |
| 685 |
55.0054f, |
| 686 |
46.4182f, |
| 687 |
56.6118f, |
| 688 |
66.8054f, |
| 689 |
65.0941f, |
| 690 |
63.3828f, |
| 691 |
63.8434f, |
| 692 |
64.3040f, |
| 693 |
61.8779f, |
| 694 |
59.4519f, |
| 695 |
55.7054f, |
| 696 |
51.9590f, |
| 697 |
54.6998f, |
| 698 |
57.4406f, |
| 699 |
58.8765f, |
| 700 |
60.3125f |
| 701 |
}; |
| 702 |
|
| 703 |
// The wavelength w must be between 300nm and 830nm |
| 704 |
static float illuminantD65(float w) { |
| 705 |
auto i0 = size_t((w - CIE_D65_START) / CIE_D65_INTERVAL); |
| 706 |
uint2 indexBounds{i0, std::min(i0 + 1, CIE_D65_END)}; |
| 707 |
|
| 708 |
float2 wavelengthBounds = CIE_D65_START + float2{indexBounds} * CIE_D65_INTERVAL; |
| 709 |
float t = (w - wavelengthBounds.x) / (wavelengthBounds.y - wavelengthBounds.x); |
| 710 |
return lerp(CIE_D65[indexBounds.x], CIE_D65[indexBounds.y], t); |
| 711 |
} |
| 712 |
|
| 713 |
struct Sample { |
| 714 |
float w = 0.0f; // wavelength |
| 715 |
std::complex<float> ior; // complex IOR, n + ik |
| 716 |
}; |
| 717 |
|
| 718 |
// For std::lower_bound |
| 719 |
bool operator<(const Sample& lhs, const Sample& rhs) { |
| 720 |
return lhs.w < rhs.w; |
| 721 |
} |
| 722 |
|
| 723 |
// The wavelength w must be between 360nm and 830nm |
| 724 |
static std::complex<float> findSample(const std::vector<Sample>& samples, float w) { |
| 725 |
auto i1 = std::lower_bound(samples.begin(), samples.end(), Sample{w, 0.0f + 0.0if}); |
| 726 |
auto i0 = i1 - 1; |
| 727 |
|
| 728 |
// Interpolate the complex IORs |
| 729 |
float t = (w - i0->w) / (i1->w - i0->w); |
| 730 |
float n = lerp(i0->ior.real(), i1->ior.real(), t); |
| 731 |
float k = lerp(i0->ior.imag(), i1->ior.imag(), t); |
| 732 |
return {n, k}; |
| 733 |
} |
| 734 |
|
| 735 |
// Fresnel equation for complex IORs at normal incidence |
| 736 |
static float fresnel(const std::complex<float>& sample) { |
| 737 |
return (((sample - (1.0f + 0if)) * (std::conj(sample) - (1.0f + 0if))) / |
| 738 |
((sample + (1.0f + 0if)) * (std::conj(sample) + (1.0f + 0if)))).real(); |
| 739 |
} |
| 740 |
|
| 741 |
// Fresnel equation for complex IORs at a specified angle |
| 742 |
static float fresnel(const std::complex<float>& sample, float cosTheta) { |
| 743 |
float cosTheta2 = cosTheta * cosTheta; |
| 744 |
float sinTheta2 = 1.0f - cosTheta2; |
| 745 |
float eta2 = sample.real() * sample.real(); |
| 746 |
float etak2 = sample.imag() * sample.imag(); |
| 747 |
|
| 748 |
float t0 = eta2 - etak2 - sinTheta2; |
| 749 |
float a2plusb2 = sqrt(t0 * t0 + 4 * eta2 * etak2); |
| 750 |
float t1 = a2plusb2 + cosTheta2; |
| 751 |
float a = std::sqrt(0.5f * (a2plusb2 + t0)); |
| 752 |
float t2 = 2 * a * cosTheta; |
| 753 |
float Rs = (t1 - t2) / (t1 + t2); |
| 754 |
|
| 755 |
float t3 = cosTheta2 * a2plusb2 + sinTheta2 * sinTheta2; |
| 756 |
float t4 = t2 * sinTheta2; |
| 757 |
float Rp = Rs * (t3 - t4) / (t3 + t4); |
| 758 |
|
| 759 |
return 0.5f * (Rp + Rs); |
| 760 |
} |
| 761 |
|
| 762 |
static float3 linear_to_sRGB(float3 linear) noexcept { |
| 763 |
float3 sRGB{linear}; |
| 764 |
#pragma nounroll |
| 765 |
for (size_t i = 0; i < sRGB.size(); i++) { |
| 766 |
sRGB[i] = (sRGB[i] <= 0.0031308f) ? |
| 767 |
sRGB[i] * 12.92f : (powf(sRGB[i], 1.0f / 2.4f) * 1.055f) - 0.055f; |
| 768 |
} |
| 769 |
return sRGB; |
| 770 |
} |
| 771 |
|
| 772 |
static float3 XYZ_to_sRGB(const float3& v) { |
| 773 |
const mat3f XYZ_sRGB{ |
| 774 |
3.2404542f, -0.9692660f, 0.0556434f, |
| 775 |
-1.5371385f, 1.8760108f, -0.2040259f, |
| 776 |
-0.4985314f, 0.0415560f, 1.0572252f |
| 777 |
}; |
| 778 |
return XYZ_sRGB * v; |
| 779 |
} |
| 780 |
|
| 781 |
struct Reflectance { |
| 782 |
float3 f0{0.0f}; |
| 783 |
float3 f82{0.0f}; |
| 784 |
}; |
| 785 |
|
| 786 |
static Reflectance computeColor(const std::vector<Sample>& samples) { |
| 787 |
Reflectance xyz; |
| 788 |
|
| 789 |
float y = 0.0f; |
| 790 |
|
| 791 |
// We default to 81.7° but this can be specified by the user, so we use the |
| 792 |
// notation theta82/f81 in the code |
| 793 |
float cosTheta82 = std::cos(g_incidenceAngle * F_PI / 180.0f); |
| 794 |
|
| 795 |
// We need to evaluate the Fresnel equation at each spectral sample of |
| 796 |
// complex IOR over the visible spectrum. For each spectral sample, we |
| 797 |
// obtain a spectral reflectance sample. To find the RGB color at normal |
| 798 |
// incidence (f0, or baseColor in our material system), we must multiply |
| 799 |
// each sample by the CIE XYZ CMFs (color matching functions) and the |
| 800 |
// spectral power distribution of the desired illuminant. We choose the |
| 801 |
// standard illuminant D65 because we want to compute a color in the |
| 802 |
// sRGB color space. |
| 803 |
// We then sum (integrate) and normalize all the samples to obtain f0 |
| 804 |
// in the XYZ color space. From there, a simple color space conversion |
| 805 |
// yields a linear sRGB color. |
| 806 |
for (size_t i = 0; i < CIE_XYZ_COUNT; i++) { |
| 807 |
// Current wavelength |
| 808 |
float w = float(CIE_XYZ_START + i); |
| 809 |
|
| 810 |
// Find most appropriate CIE XYZ sample for the wavelength |
| 811 |
auto sample = findSample(samples, w); |
| 812 |
|
| 813 |
// Compute Fresnel reflectance at normal incidence |
| 814 |
float f0 = fresnel(sample); |
| 815 |
|
| 816 |
// Compute Fresnel reflectance at the peak angle for the Lazanyi error term |
| 817 |
float f82 = fresnel(sample, cosTheta82); |
| 818 |
|
| 819 |
// We need to multiply by the spectral power distribution of the illuminant |
| 820 |
float d65 = illuminantD65(w); |
| 821 |
|
| 822 |
xyz.f0 += f0 * CIE_XYZ[i] * d65; |
| 823 |
xyz.f82 += f82 * CIE_XYZ[i] * d65; |
| 824 |
|
| 825 |
y += CIE_XYZ[i].y * d65; |
| 826 |
} |
| 827 |
|
| 828 |
xyz.f0 /= y; |
| 829 |
xyz.f82 /= y; |
| 830 |
|
| 831 |
xyz.f0 = XYZ_to_sRGB(xyz.f0); |
| 832 |
xyz.f82 = XYZ_to_sRGB(xyz.f82); |
| 833 |
|
| 834 |
// Rescale values that are outside of the sRGB gamut (gold for instance) |
| 835 |
// We should provide an option to compute f0 in wide gamut color spaces |
| 836 |
if (any(greaterThan(xyz.f0, float3{1.0f}))) xyz.f0 *= 1.0f / max(xyz.f0); |
| 837 |
if (any(greaterThan(xyz.f82, float3{1.0f}))) xyz.f82 *= 1.0f / max(xyz.f82); |
| 838 |
|
| 839 |
return xyz; |
| 840 |
} |
| 841 |
|
| 842 |
static bool parseSpectralData(std::ifstream& in, std::vector<Sample>& samples) { |
| 843 |
std::string value; |
| 844 |
|
| 845 |
in >> value; |
| 846 |
if (value != "wl") return false; |
| 847 |
|
| 848 |
in >> value; |
| 849 |
if (value != "n") return false; |
| 850 |
|
| 851 |
while (in.good()) { |
| 852 |
in >> value; |
| 853 |
if (value == "wl") { |
| 854 |
in >> value; |
| 855 |
if (value != "k") return false; |
| 856 |
break; |
| 857 |
} |
| 858 |
|
| 859 |
Sample sample = { 0 }; |
| 860 |
sample.w = std::strtof(value.c_str(), nullptr) * 1000.0f; // um to nm |
| 861 |
|
| 862 |
float n; |
| 863 |
in >> n; |
| 864 |
sample.ior.real(n); |
| 865 |
|
| 866 |
samples.push_back(sample); |
| 867 |
} |
| 868 |
|
| 869 |
size_t i = 0; |
| 870 |
while (in.good() && i < samples.size()) { |
| 871 |
Sample& sample = samples[i++]; |
| 872 |
|
| 873 |
float w; |
| 874 |
in >> w; |
| 875 |
if (w * 1000.0f != sample.w) return false; |
| 876 |
|
| 877 |
float k; |
| 878 |
in >> k; |
| 879 |
sample.ior.imag(k); |
| 880 |
} |
| 881 |
|
| 882 |
return true; |
| 883 |
} |
| 884 |
|
| 885 |
void printColor(const float3& linear) { |
| 886 |
float3 sRGB = linear_to_sRGB(saturate(linear)); |
| 887 |
|
| 888 |
std::cout << std::setfill(' ') << std::setw(12) << "linear: "; |
| 889 |
std::cout << std::fixed << std::setprecision(3) << linear.r << ", "; |
| 890 |
std::cout << std::fixed << std::setprecision(3) << linear.g << ", "; |
| 891 |
std::cout << std::fixed << std::setprecision(3) << linear.b; |
| 892 |
std::cout << std::endl; |
| 893 |
|
| 894 |
std::cout << std::setfill(' ') << std::setw(12) << "sRGB: "; |
| 895 |
std::cout << std::fixed << std::setprecision(3) << sRGB.r << ", "; |
| 896 |
std::cout << std::fixed << std::setprecision(3) << sRGB.g << ", "; |
| 897 |
std::cout << std::fixed << std::setprecision(3) << sRGB.b; |
| 898 |
std::cout << std::endl; |
| 899 |
|
| 900 |
std::cout << std::setfill(' ') << std::setw(12) << "sRGB: "; |
| 901 |
std::cout << std::setprecision(3) << int(sRGB.r * 255.99f) << ", "; |
| 902 |
std::cout << std::setprecision(3) << int(sRGB.g * 255.99f) << ", "; |
| 903 |
std::cout << std::setprecision(3) << int(sRGB.b * 255.99f); |
| 904 |
std::cout << std::endl; |
| 905 |
|
| 906 |
std::cout << std::setfill(' ') << std::setw(12) << "hex: "; |
| 907 |
std::cout << "#"; |
| 908 |
std::cout << std::hex << std::setfill('0') << std::setw(2) << int(sRGB.r * 255.99f); |
| 909 |
std::cout << std::hex << std::setfill('0') << std::setw(2) << int(sRGB.g * 255.99f); |
| 910 |
std::cout << std::hex << std::setfill('0') << std::setw(2) << int(sRGB.b * 255.99f); |
| 911 |
std::cout << std::endl; |
| 912 |
|
| 913 |
// Reset decimal numbers |
| 914 |
std::cout << std::dec; |
| 915 |
} |
| 916 |
|
| 917 |
int main(int argc, char* argv[]) { |
| 918 |
int optionIndex = handleArguments(argc, argv); |
| 919 |
|
| 920 |
int numArgs = argc - optionIndex; |
| 921 |
if (numArgs < 1) { |
| 922 |
printUsage(argv[0]); |
| 923 |
return 1; |
| 924 |
} |
| 925 |
|
| 926 |
utils::Path src(argv[optionIndex]); |
| 927 |
if (!src.exists()) { |
| 928 |
std::cerr << "The spectral data " << src << " does not exist." << std::endl; |
| 929 |
return 1; |
| 930 |
} |
| 931 |
|
| 932 |
std::ifstream in(src.c_str(), std::ifstream::in); |
| 933 |
if (in.is_open()) { |
| 934 |
std::vector<Sample> samples; |
| 935 |
if (!parseSpectralData(in, samples)) { |
| 936 |
std::cerr << "Invalid spectral data file " << src << std::endl; |
| 937 |
return 1; |
| 938 |
} |
| 939 |
|
| 940 |
Reflectance reflectance = computeColor(samples); |
| 941 |
|
| 942 |
std::cout << "Material: " << src.getNameWithoutExtension() << std::endl; |
| 943 |
std::cout << std::endl; |
| 944 |
|
| 945 |
std::cout << "Reflectance at 0.0° (f0):" << std::endl; |
| 946 |
printColor(reflectance.f0); |
| 947 |
|
| 948 |
std::cout << std::endl; |
| 949 |
|
| 950 |
std::cout << "Reflectance at " << |
| 951 |
std::fixed << std::setprecision(1) << g_incidenceAngle << "°:" << std::endl; |
| 952 |
printColor(reflectance.f82); |
| 953 |
} else { |
| 954 |
std::cerr << "Could not open the source material " << src << std::endl; |
| 955 |
return 1; |
| 956 |
} |
| 957 |
|
| 958 |
return 0; |
| 959 |
} |