Skip to content

Realistic watercolor drawings

TypeScript paintwatercolor
7.1 KB
Raw Blame
// Generated from spectral.js reflectance data (Ronald van Wijnen, MIT) by an offline fit.
// Do not edit by hand.
//
// Pigment model: a colour's spectral absorbance A(λ) = -ln R(λ) (38 bands, 380–750nm)
// is projected onto a 7-vector basis (uncentred SVD of absorbance spectra across the
// sRGB gamut). Absorbance is linear in pigment concentration, so these coefficients
// can be added, advected and diffused by the fluid sim while mixing stays physically
// subtractive (blue + yellow = green). Reconstruction error vs. the full 38-band model
// averages ΔE_OK ≈ 0.1 (×100 scale), well under the visible threshold.

export const SPECTRAL_EPSILON = 1e-4;

/** Reflectance of the 6 spectral.js primaries (cyan, magenta, yellow, red, green, blue) per band. */
export const PRIMARIES: readonly (readonly number[])[] = [[0.96853629,0.51567122,0.02055257,0.03147571,0.49108579,0.97901834],[0.96855103,0.5401552,0.02059936,0.03146636,0.46944057,0.97901649],[0.96859338,0.62645502,0.02062723,0.03140624,0.4016578,0.97901118],[0.96877345,0.75595012,0.02073387,0.03119611,0.2449042,0.97892146],[0.96942204,0.92826996,0.02114202,0.03053888,0.0682688,0.97858555],[0.97143709,0.97223624,0.02233154,0.02856855,0.02732883,0.97743705],[0.97541862,0.98616174,0.02556857,0.02459485,0.013606,0.97428075],[0.98074186,0.98955255,0.03330189,0.0192952,0.01000187,0.96663223],[0.98580992,0.98676237,0.05185294,0.01423112,0.01284127,0.94822893],[0.98971194,0.97312575,0.10087639,0.01033111,0.02636635,0.89937713],[0.99238027,0.91944277,0.24000413,0.00765876,0.07058713,0.76070164],[0.99409844,0.32564851,0.53589066,0.00593693,0.70421692,0.4642044],[0.995172,0.13820628,0.79874659,0.00485616,0.85473994,0.20123039],[0.99576545,0.05015143,0.91186529,0.00426186,0.95081565,0.08808402],[0.99593552,0.02912336,0.95399623,0.00409039,0.9717037,0.04592894],[0.99564041,0.02421691,0.97137099,0.00438375,0.97651888,0.02860373],[0.99464769,0.02660696,0.97939505,0.00537525,0.97429245,0.02060067],[0.99229579,0.03407586,0.98345207,0.00772962,0.97012917,0.01656701],[0.98638762,0.04835936,0.98553736,0.0136612,0.9425863,0.01451549],[0.96829712,0.0001172,0.98648905,0.03181352,0.99989207,0.01357964],[0.89228016,0.00008554,0.98674535,0.10791525,0.99989891,0.01331243],[0.53740239,0.85267882,0.98657555,0.46249516,0.13823139,0.01347661],[0.15360445,0.93188793,0.98611877,0.84604333,0.06968113,0.01387181],[0.05705719,0.94810268,0.98559942,0.94275572,0.05628787,0.01435472],[0.03126539,0.94200977,0.98507063,0.96860996,0.06111561,0.01479836],[0.02205445,0.91478045,0.98460039,0.97783966,0.08987709,0.0151525],[0.01802271,0.87065445,0.98425301,0.98187757,0.13656016,0.01540513],[0.0161346,0.78827548,0.98403909,0.98377315,0.22169624,0.01557233],[0.01520947,0.65738359,0.98388535,0.98470202,0.32176956,0.0156571],[0.01475977,0.59909403,0.98376116,0.98515481,0.36157329,0.01571025],[0.01454263,0.56817268,0.98368246,0.98537114,0.4836192,0.01571916],[0.01444459,0.54031997,0.98365023,0.98546685,0.46488579,0.01572133],[0.01439897,0.52110241,0.98361309,0.98550011,0.47440306,0.01572502],[0.0143762,0.51041094,0.98357259,0.98551031,0.4857699,0.01571717],[0.01436343,0.50526577,0.98353856,0.98550741,0.49267971,0.01571905],[0.01435687,0.5025508,0.98351247,0.98551323,0.49625685,0.01571059],[0.0143537,0.50126452,0.98350101,0.98551563,0.49807754,0.01569728],[0.01435408,0.50083021,0.98350852,0.98551547,0.49889859,0.0157002]];

/** Absorbance basis: 7 vectors × 38 bands. */
export const BASIS: readonly (readonly number[])[] = [[0.1441295,0.1442537,0.1447023,0.1481238,0.1558969,0.1598567,0.1620447,0.1627555,0.1616249,0.1577825,0.1510664,0.1434845,0.1548815,0.1665376,0.1732235,0.176503,0.1775172,0.1768919,0.1748587,0.1783071,0.17098,0.1527153,0.1627231,0.169401,0.1714174,0.170287,0.1680602,0.1648873,0.162965,0.1626282,0.159549,0.1605975,0.1607086,0.1606138,0.1605312,0.1604933,0.1604751,0.160461],[-0.2038064,-0.203989,-0.2047454,-0.2096147,-0.2221909,-0.229624,-0.2342462,-0.2354314,-0.2303617,-0.2137209,-0.1783547,-0.124576,-0.08767601,-0.06654336,-0.05408394,-0.04631953,-0.04068168,-0.03551027,-0.02914774,-0.01869558,0.01093349,0.05936064,0.1243476,0.151563,0.1619576,0.1663112,0.1683766,0.1696986,0.171131,0.1718488,0.1723758,0.1726696,0.172894,0.1730376,0.1731037,0.1731485,0.1731795,0.1731822],[0.03137849,0.03651497,0.05369401,0.09161207,0.1575574,0.1842324,0.1949895,0.1940139,0.181434,0.1530233,0.09984866,-0.09188325,-0.1765157,-0.2432063,-0.2743489,-0.2876131,-0.2893418,-0.2831437,-0.2674148,-0.3019731,-0.2652804,0.04536814,0.1224234,0.1512875,0.1570717,0.1463656,0.128849,0.1015794,0.07210673,0.06066822,0.0405239,0.04040221,0.03731743,0.03480428,0.03341753,0.03269546,0.03233622,0.03218968],[0.3475249,0.3394636,0.3120142,0.2222812,0.02525531,-0.07617525,-0.131711,-0.1551115,-0.1569514,-0.1445308,-0.1209759,0.1224517,0.04911107,-0.01336119,-0.05756325,-0.0821194,-0.0923594,-0.09218955,-0.0876826,-0.1097293,-0.08213999,-0.2512941,-0.2629964,-0.2346993,-0.1994343,-0.1372833,-0.07003431,0.01097949,0.07361673,0.09292193,0.1495078,0.1393326,0.1419586,0.1459523,0.1484407,0.1497109,0.1503627,0.1506628],[0.06142204,0.05786618,0.04493868,-0.001667544,-0.1239341,-0.18922,-0.2092335,-0.1813051,-0.09951376,0.04750551,0.2508217,0.4173112,0.3464263,0.2114988,0.1065638,0.0396658,0.001179382,-0.02244844,-0.04379864,-0.2757395,-0.4358296,0.002079004,0.08929734,0.1616104,0.1808936,0.1600107,0.1229764,0.06541057,-0.001589698,-0.02956237,-0.06381081,-0.07050402,-0.07924397,-0.08523274,-0.08834905,-0.09000503,-0.09082922,-0.09112351],[-0.2849056,-0.2809993,-0.2670309,-0.2146758,-0.04397425,0.07688784,0.1561441,0.1960707,0.2022741,0.1829012,0.1568899,0.1352822,0.1607311,0.1282205,0.08742798,0.05524357,0.03074158,0.007401419,-0.02492709,-0.144013,-0.2534114,-0.279643,-0.284807,-0.2400265,-0.1937673,-0.1278778,-0.06158691,0.0106791,0.06228573,0.07793386,0.1189043,0.1120231,0.1139095,0.1167035,0.118432,0.119318,0.1197796,0.1199808],[-0.04867795,-0.03848097,-0.006388283,0.0006091587,-0.0367139,-0.0675538,-0.07838973,-0.06227753,-0.01207089,0.08113584,0.2171174,0.1783848,0.06910126,-0.09273659,-0.1425212,-0.1316225,-0.07574946,0.0125239,0.1328408,-0.1632446,0.05201528,0.7089535,0.1776335,-0.1592273,-0.2833049,-0.2661033,-0.1976904,-0.09221338,-0.02023599,-0.004615753,0.08051684,0.05602729,0.05512528,0.058801,0.06145249,0.06280478,0.06355499,0.06393252]];

/** Band indices sampled by the display shader (16-point fitted quadrature). */
export const DISPLAY_BANDS: readonly number[] = [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32];

/** Linear-sRGB weight of each display band: rgb = Σ_i exp(-A(λ_i)) · weight_i. */
export const DISPLAY_RGB_WEIGHTS: readonly (readonly number[])[] = [[0.007598756,0.0144316,0.02304203],[-0.07190809,-0.05764169,0.1207272],[0.299773,0.0127048,0.3249726],[-0.2579063,-0.06517872,0.4461339],[0.07037487,0.05889296,0.1350291],[-0.2104469,0.1285821,0.09775973],[-0.02718884,0.2208098,-0.09346024],[-0.3172512,0.4457301,0.04248862],[0.2293731,0.1134161,-0.06150663],[0.1930991,0.1395861,-0.01283952],[0.5274069,0.03838932,-0.02348521],[0.3899227,0.07193636,0.01268301],[-0.165677,-0.2589753,-0.01230862],[0.5972293,0.3119106,-0.00548141],[-0.197781,0.08099158,0.05785604],[-0.06596648,-0.2556352,-0.05165295]];