A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(bake): baked light is a lit surface's indirect light
esengine7346e8cdb197
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0497e2c5b..6840f836e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,10 +14,16 @@ published separately; it ships inside the editor.## [Unreleased]+### Added++- **Baked light is a lit surface's indirect light.** A lit renderer — every imported model's is — reads its patch of the atlas in place of the environment's diffuse light and a probe volume's, and keeps its lamps, shadows and reflections live. The bake holds the sky as it reaches each point past whatever stands in the way, plus what the surfaces around give off, over as many bounces as asked: under ORCA Bistro's awnings and in its side streets the sky is now mostly hidden, where before every point got all of it. Before, a model's material never read the atlas at all, and a mesh drawn without one added it on top of the sky and the lamps and was lit twice. The sky a bake gathers is the environment's own irradiance, turned and tinted as the frame reads it, so an open floor bakes to exactly what the frame would light it with. An atlas holds light up to eight times a flat ambient of one, where eight plain bits stopped at one. A cutout lets the share of rays that meets its holes through, both faces of a two-sided surface give off light, and a layer lying closer above a surface than half a lumel — a decal, a wet sheen — no longer walls it off from the sky. A scene baked before reads as stale: its atlas is in the old encoding and must be baked again.+- **A model whose second UV set cannot be baked into gets a lightmap UV in its place.** One that covers under 5% of its square pays for the empty rest — ORCA Bistro's road, 3533 m² in 0.5% of it, asked for more atlas than the rest of the town together — and one that lies on itself gives every copy the same texel's light: Bistro's curbs share one strip eighty layers deep, and a building's facades a hundred. Import unwraps either instead and says why; `import-model --lightmap-uv` turns generation on from the command line. A bake names a surface whose UVs overlap, and one that does not fit names the three surfaces taking the most room and how much of their square their UVs cover.+### Fixed- **A shipped game samples normal maps and roughness maps as data.** The engine's own upload — a web export, a mini-game, a native build, the editor's Play — made every image an sRGB colour texture in a linear project whatever its import settings said, so every normal map was bent (a flat one by about fifty degrees) and every packed occlusion, roughness and metal map gamma-darkened, while the editor's viewport, which uploads through its own path, looked right. ORCA Bistro's Vespa came out as dark chrome in an exported game and blue in the editor. Khronos's NormalTangentTest now draws each normal-mapped bump as its geometric twin does.- Normal maps stay on up close. The tangent frame taken from screen derivatives was refused below a fixed size, which shrinks with the fourth power of distance and scale, so in a metre-scale scene a surface a few metres from the camera silently lost its normal map.+- The editor stays responsive while it bakes. The solve ran on the main process, so a bake of minutes left the window and the automation surface unanswered until it finished; it runs on a worker thread now.## [0.75.0] - 2026-09-27diff --git a/desktop b/desktopindex ab4b92778..660cd0cff 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit ab4b92778acf196a3dc4ab2aa85298d53ba7207b+Subproject commit 660cd0cff190a3dd566e3dbc4826812ec7fabf39diff --git a/examples/physics-3d/assets/materials/decal-target.esshader b/examples/physics-3d/assets/materials/decal-target.esshaderindex afc0d85b0..73dcd7103 100644--- a/examples/physics-3d/assets/materials/decal-target.esshader+++ b/examples/physics-3d/assets/materials/decal-target.esshader@@ -27,7 +27,7 @@ void main() {// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.// Regenerate after changing the GLSL stages above.// source-hash: 144f76db1f5f521a-// assembled-hash: 9d2b226ba9f613f0+// assembled-hash: d246aed656c8e5b4struct MaterialConstants {u_tint: vec4<f32>,}diff --git a/examples/physics-3d/assets/scenes/main.esscene b/examples/physics-3d/assets/scenes/main.essceneindex 42d1d5384..81a7d84f0 100644--- a/examples/physics-3d/assets/scenes/main.esscene+++ b/examples/physics-3d/assets/scenes/main.esscene@@ -1522,7 +1522,7 @@"bounces": 2,"samples": 64,"probeSamples": 128,- "bakedFrom": "5a02a75515a28e41"+ "bakedFrom": "f6cc8c78bdacc01c"}}]diff --git a/examples/physics-3d/assets/scenes/main_lightmap.png b/examples/physics-3d/assets/scenes/main_lightmap.pngindex 318c71abb..bfda4bca8 100644Binary files a/examples/physics-3d/assets/scenes/main_lightmap.png and b/examples/physics-3d/assets/scenes/main_lightmap.png differdiff --git a/examples/physics-3d/assets/scenes/main_probes_50.esprobes b/examples/physics-3d/assets/scenes/main_probes_50.esprobesindex 3063786cf..44eceb732 100644--- a/examples/physics-3d/assets/scenes/main_probes_50.esprobes+++ b/examples/physics-3d/assets/scenes/main_probes_50.esprobes@@ -1,5 +1,5 @@{"version": 1,"resolution": [7,3,5],- "irradiance": [0.787525,0.947183,1.21709,-0.0128871,-0.0145809,-0.0199165,-0.0216912,-0.024515,-0.0335227,-0.0226589,-0.0256378,-0.0350183,-0.00620364,-0.00699162,-0.00958744,-0.00623858,-0.00705768,-0.00964144,-0.00212922,-0.00240502,-0.00329061,-0.0105509,-0.0119378,-0.0163059,-0.00414027,-0.00468563,-0.00639859,0.738265,0.891448,1.14096,-0.0415297,-0.0469878,-0.0641822,-0.0613031,-0.0693331,-0.0947412,-0.00666444,-0.00754116,-0.0102996,-0.000164008,-0.000158209,-0.000253468,-0.0219174,-0.0247971,-0.0338723,-0.00980345,-0.0110879,-0.0151508,-0.00276039,-0.00312344,-0.00426606,-0.00145615,-0.00164875,-0.0022504,0.729309,0.881314,1.12712,-0.0423377,-0.047902,-0.0654308,-0.0694891,-0.0785949,-0.107392,-0.00111113,-0.00125799,-0.00171721,0.000277233,0.000341024,0.000428451,-0.0223998,-0.0253429,-0.0346179,-0.012195,-0.0137937,-0.0188468,0.000610242,0.000690194,0.0009431,-0.00289992,-0.00328227,-0.00448168,0.731043,0.883274,1.13051,-0.0421495,-0.0476845,-0.0650656,-0.0678313,-0.0767173,-0.104146,-0.000037873,-0.0000632033,0.000398869,0.000358063,0.000432136,0.000587018,-0.0222684,-0.0251906,-0.0343633,-0.0116801,-0.0132057,-0.0178422,0.00134595,0.00150831,0.00239428,-0.0026537,-0.00300886,-0.00399573,0.731978,0.884598,1.13217,-0.0418015,-0.047236,-0.0644199,-0.0665157,-0.0749497,-0.10175,-0.00117883,-0.00137815,-0.00181829,0.000261,0.000314551,0.00040249,-0.0219684,-0.0248094,-0.0338028,-0.0108497,-0.0121557,-0.0162857,0.000581042,0.000629326,0.000906169,-0.00289602,-0.00326983,-0.00447994,0.736184,0.889279,1.13862,-0.041569,-0.0470071,-0.0641233,-0.0634951,-0.0716774,-0.0974837,-0.00030825,-0.000513793,-0.0012571,0.000279567,0.000327529,0.000355341,-0.021922,-0.024789,-0.0338161,-0.0107839,-0.0121867,-0.0166165,0.00149675,0.00160611,0.00189905,-0.00155961,-0.00171433,-0.00216558,0.791721,0.951528,1.22328,-0.00943621,-0.010767,-0.014649,-0.0200434,-0.0227069,-0.0310171,0.0191291,0.0220943,0.0298918,0.00550889,0.00633427,0.00856755,-0.00444804,-0.00504103,-0.00688096,-0.00291591,-0.00318767,-0.00442828,0.00967131,0.0109881,0.01498,-0.00360476,-0.00425668,-0.00569966,0.805807,0.966361,1.22843,0.00464538,0.00582736,0.0161077,-0.0188377,-0.0220935,-0.0342125,0.00264398,0.00172734,-0.012994,-0.000784729,-0.000491828,0.00455903,0.00462316,0.00541285,0.00976024,-0.00966853,-0.0108696,-0.0106368,-0.00293227,-0.0037414,-0.00881827,0.00414738,0.00439394,0.00214696,0.869888,1.0315,1.25701,-0.0305729,-0.0313451,0.00211485,0.0381659,0.0364469,-0.00353697,0.0239083,0.0237532,0.00970087,-0.00560764,-0.00568146,-0.00223039,-0.0157061,-0.0161844,-0.0000619816,0.00543374,0.0051322,0.00116653,0.00998603,0.00979286,0.00420788,-0.00251078,-0.0035206,-0.00250838,0.872733,1.03502,1.25228,-0.0351628,-0.035911,0.00103145,0.0357071,0.034391,-0.0103444,-0.00652487,-0.00789001,-0.0118599,0.00171033,0.00209872,0.00210022,-0.0166023,-0.0169444,0.000485054,0.00240323,0.00212345,-0.00193543,-0.00473845,-0.00563425,-0.00717295,-0.00156314,-0.00230681,-0.00268725,0.897617,1.05928,1.27262,-0.0370033,-0.0376476,-0.000132564,0.0560212,0.0537766,0.00641127,-0.0273604,-0.0281214,-0.02588,0.00426662,0.00466886,0.00386517,-0.0175749,-0.0177926,-0.000181603,0.00581614,0.00492077,0.000763441,-0.0176386,-0.0181468,-0.0162054,0.00447083,0.00384407,0.00228687,0.866293,1.0267,1.25025,-0.0310323,-0.0309063,0.00488946,0.0321365,0.0285553,-0.012034,0.000153169,0.000932548,0.00261277,0.000405198,0.000445405,0.000222114,-0.0141244,-0.013802,0.00299221,0.00230417,0.00074042,-0.00265819,-7.02572e-7,0.000244883,0.000328009,-0.00248772,-0.00294748,-0.00197665,0.855967,1.01805,1.24643,-0.0293846,-0.0296481,0.00391648,0.0240282,0.0223671,-0.015281,-0.0032697,-0.00200703,0.0102181,0.00281246,0.00282291,-0.000283716,-0.0136189,-0.0135904,0.00275364,-0.000225988,-0.000950998,-0.00413679,-0.000110699,0.000535106,0.00452598,-0.00399642,-0.00444067,-0.00270466,0.840671,1.00377,1.25854,-0.0115186,-0.0115086,0.00245417,0.013572,0.0129435,-0.00616575,-0.0146469,-0.0142388,0.00340126,0.00589474,0.0060113,-0.000261544,-0.00490293,-0.00480297,0.0017181,-0.0000427106,-0.000297347,-0.00215991,-0.00508664,-0.0048019,0.00234961,0.00186188,0.00173097,-0.000320383,0.826417,0.98928,1.24975,-0.00612702,-0.00549768,0.0102761,-0.00135098,-0.00233875,-0.0135446,0.00980332,0.00985948,-0.00361309,-0.00383154,-0.00373039,0.00260778,0.000759315,0.00127908,0.00628389,-0.00501576,-0.00540974,-0.0037325,0.00267684,0.00259234,-0.00227333,0.00114858,0.00140236,0.00237127,0.862585,1.02687,1.27087,-0.0377318,-0.0386758,-0.0060644,0.0251237,0.0253466,0.00575492,0.00321846,0.00317184,-0.00650626,-0.00151957,-0.00156311,0.00279701,-0.0140408,-0.0143136,-0.00350849,-0.00115587,-0.0012411,0.0015694,0.00121915,0.00128701,-0.00277366,-0.00979592,-0.0103796,-0.00314211,0.862545,1.02306,1.25512,-0.0347951,-0.0338137,0.00641723,0.0239451,0.0218577,-0.00679313,0.00165876,-0.000826716,-0.00684476,0.00103151,0.00191425,0.00374638,-0.0122623,-0.0117064,0.00325966,-0.00187362,-0.00183021,-0.000362496,-0.000324679,-0.00141252,-0.00359674,-0.00678598,-0.00781077,0.0000239954,0.858094,1.02041,1.25288,-0.0287019,-0.0280413,0.0115678,0.019374,0.018084,-0.0100034,-0.0118513,-0.0127804,-0.0114621,0.00440074,0.00493505,0.00411031,-0.0085937,-0.00804031,0.00639671,-0.00333697,-0.00360009,-0.00199261,-0.00612674,-0.00670958,-0.0059653,-0.00292072,-0.002996,0.0040968,0.864926,1.02552,1.2569,-0.0356743,-0.0342942,0.00632623,0.0262537,0.0236229,-0.00644036,-0.00376309,-0.00536745,-0.00244969,0.00195964,0.00277815,0.00161023,-0.0128334,-0.0118252,0.00361899,-0.00151978,-0.00204394,-0.0012325,-0.00107928,-0.00218649,-0.00152643,-0.00616606,-0.00652539,0.00145146,0.860929,1.01903,1.25201,-0.0322552,-0.0295456,0.00989486,0.0218793,0.0158155,-0.011349,-0.0138973,-0.014167,-0.0026053,0.00618757,0.00643585,0.00177552,-0.0103929,-0.00812108,0.00617798,-0.00245319,-0.0047924,-0.0027747,-0.0050379,-0.0051125,-0.00141201,-0.0052228,-0.00480317,0.00263684,0.838889,0.998068,1.25666,-0.0148748,-0.0126035,0.0059613,0.00758676,0.00382419,-0.00812381,-0.0137112,-0.011047,0.0020605,0.00660516,0.0057567,-0.000544218,-0.00362706,-0.00218636,0.00411739,-0.00371535,-0.00443384,-0.00247125,-0.00377721,-0.00227646,0.00199289,-0.000608533,-0.000878505,0.00154139,0.729588,0.881501,1.12855,-0.0466636,-0.0529255,-0.0711144,-0.0035479,-0.00401255,-0.00528572,-0.0665827,-0.0754039,-0.10236,-0.0236455,-0.0267763,-0.0361499,-0.000952354,-0.00109514,-0.00132827,0.00322211,0.00368243,0.00472437,-0.00185382,-0.00210767,-0.00278757,-0.00860913,-0.00970861,-0.0135633,0.563616,0.693843,0.871043,-0.163331,-0.184797,-0.252421,-0.00312799,-0.00351208,-0.00483417,-0.00570718,-0.00645809,-0.00882019,-0.000219454,-0.000220942,-0.000339157,-0.000316014,-0.000356715,-0.000488385,0.00451025,0.00510706,0.00697039,-0.00326112,-0.00368997,-0.00503991,0.00737592,0.0083441,0.0113992,0.559791,0.689715,0.86526,-0.163822,-0.185318,-0.253157,-0.00636668,-0.00716658,-0.00983305,-0.00100715,-0.000914538,-0.00141072,0.000263134,0.000353588,0.000425066,-0.000634016,-0.000715471,-0.00097917,0.00408042,0.00456623,0.00627092,-0.0011343,-0.00127543,-0.0017477,0.00643167,0.00736615,0.00999823,0.569748,0.702194,0.885753,-0.156877,-0.176305,-0.240223,-0.00843966,-0.00965894,-0.0142674,0.0155465,0.0182125,0.0286535,0.004299,0.00529927,0.0079383,-0.00149169,-0.00178058,-0.00262028,0.0034182,0.00372586,0.00459904,-0.00374044,-0.00424762,-0.00644613,0.00669835,0.00739305,0.0115581,0.636246,0.773788,1.01859,-0.107924,-0.123652,-0.142397,-0.00869356,-0.00970786,-0.0149336,-0.000933168,-0.000938427,-0.00326659,-0.000198472,-0.000178327,-0.000594699,-0.00119068,-0.00132769,-0.00211018,0.00197661,0.00233468,0.00160487,-0.0022397,-0.0025286,-0.00352145,-0.000293214,-0.000212417,-0.00235295,0.56593,0.696637,0.875453,-0.162866,-0.184221,-0.251611,-0.00108127,-0.00116384,-0.0018362,0.00872915,0.00968201,0.0125574,0.00100221,0.00112188,0.00147584,-0.000251082,-0.000280249,-0.000397081,0.00479365,0.00538177,0.0072077,0.000400115,0.000424809,0.000752245,0.00789138,0.00900044,0.0125706,0.753896,0.908838,1.15837,-0.0275162,-0.0314994,-0.0481693,0.00161042,0.0018592,0.00324746,0.0554498,0.0628559,0.0901125,0.0167322,0.0191303,0.0285652,0.00101285,0.00117995,0.00209378,0.00425896,0.00485464,0.00761576,-0.000718517,-0.000792406,-0.00129749,-0.0125877,-0.0141282,-0.0188155,0.685018,0.828983,1.08396,0.0423757,0.0477317,0.060648,-0.0203852,-0.0234445,-0.0273667,-0.10302,-0.118789,-0.137095,0.0176019,0.0199147,0.02465,0.00469827,0.00537247,0.00640097,0.00685094,0.00789284,0.00870523,-0.00565859,-0.00656193,-0.00724884,-0.0182433,-0.021471,-0.0225548,0.938896,1.1009,1.27957,-0.0961265,-0.101045,-0.0178795,0.0105938,0.0109791,0.00878313,0.0177749,0.0256887,0.000116323,-0.00668568,-0.00753643,0.00269797,-0.0025645,-0.00316848,-0.00312681,-0.00505685,-0.00455844,0.00157175,0.000412445,0.00109426,0.00102478,-0.0188829,-0.0226724,-0.00726122,0.934854,1.09739,1.24403,-0.0933402,-0.0963015,0.00519509,0.0234459,0.0248569,0.0133968,-0.0201241,-0.0232147,-0.0318658,0.00521837,0.00622973,0.00726747,-0.0070124,-0.00767046,-0.00420486,-0.00304511,-0.00207966,0.00624195,0.00604584,0.00715766,0.00280056,-0.0172009,-0.0200792,-0.00698338,0.924486,1.07479,1.21137,-0.084063,-0.0845348,0.013622,0.0227788,0.02253,0.00548403,0.0106218,0.0135276,0.0108675,0.000193241,0.00164716,0.00468894,-0.00636666,-0.00541623,0.00121509,-0.00483107,-0.00469424,0.00374077,-0.00752377,-0.0131378,-0.0142631,-0.0127951,-0.0160002,-0.00690529,0.96696,1.11744,1.26742,-0.115368,-0.109733,-0.018081,0.0016826,-0.0114595,-0.0264462,-0.0306007,-0.0355156,-0.0328444,0.0143157,0.0155132,0.016764,0.00264003,0.00703448,0.0111069,-0.0149724,-0.0182801,-0.0122513,-0.00467882,-0.0078019,-0.00876577,-0.0169703,-0.0172087,-0.0114518,0.922332,1.06993,1.2196,-0.0724209,-0.0660546,0.0309251,-0.00868967,-0.0264209,-0.0382232,-0.0263078,-0.0250599,-0.00319391,0.00877531,0.00840524,0.00285222,0.0114938,0.0171521,0.018299,-0.00848421,-0.0140237,-0.00712752,-0.000639067,0.000194767,0.000417869,-0.00565968,-0.00571208,0.0064476,0.857415,1.01804,1.24283,-0.0269546,-0.0262599,0.00953764,-0.00741797,-0.0107022,-0.01362,-0.0260029,-0.0236101,0.0182372,0.0122953,0.0119556,-0.00502979,0.00244067,0.00329418,0.00395612,-0.0047584,-0.00531071,-0.000193941,0.00593884,0.00766083,0.00791532,-0.000229751,-0.000933891,-0.00391787,0.838852,0.995021,1.25119,-0.0000979706,0.00512304,0.0220052,0.010264,0.00861505,0.00387388,0.0334534,0.0283135,0.0076183,-0.0098932,-0.00784758,0.000497325,-0.00353115,-0.00281101,-0.00141305,-0.00536825,-0.00403979,0.000539755,0.00798785,0.00713675,0.004363,0.0169098,0.0169392,0.0149035,0.909469,1.07383,1.29155,-0.07795,-0.0787654,-0.0229229,0.0186709,0.0192514,0.00528001,0.0154103,0.0180308,-0.00950227,-0.00596179,-0.00740973,0.0063787,-0.00925127,-0.00964795,-0.00271448,-0.0113739,-0.0116289,-0.00273251,0.00376406,0.00405583,-0.000501207,-0.0156463,-0.0160855,-0.0049706,0.905899,1.06523,1.26451,-0.0723155,-0.0710215,0.000781854,0.0274659,0.026631,0.00488492,0.01491,0.00999729,-0.00397611,-0.00427506,-0.00218684,0.00323776,-0.0138989,-0.013974,-0.00322909,-0.010751,-0.00986196,0.0000464048,0.00377437,0.00265723,-0.000633019,-0.0125366,-0.0146785,0.000280412,0.910981,1.06943,1.2695,-0.0737794,-0.0703247,0.000466845,0.0297383,0.0288475,0.00513705,-0.00193577,-0.00419329,-0.00818939,-0.0000563344,0.00112331,0.00322709,-0.0137877,-0.0134983,-0.00151135,-0.0097459,-0.00854411,0.000311862,-0.00239997,-0.00377228,-0.00300541,-0.0110004,-0.0116548,0.00258876,0.901722,1.05422,1.2569,-0.0727203,-0.0643239,0.00501437,0.0223024,0.0152224,-0.00615814,-0.00929117,-0.0124761,-0.0065275,0.00635284,0.00834864,0.0056796,-0.00979636,-0.00582084,0.00447557,-0.00867604,-0.00851735,-0.000116535,-0.00193536,-0.0039384,-0.00275506,-0.0173655,-0.016196,-0.00126439,0.901571,1.04936,1.25496,-0.0692233,-0.0555261,0.0110364,0.0260029,0.0145526,-0.00438479,-0.0199025,-0.019158,0.000677323,0.00888239,0.00833499,-0.000468412,-0.0130033,-0.00602406,0.00339136,-0.00761941,-0.00811607,0.00114792,-0.003051,-0.00266819,0.000297521,-0.0135909,-0.00983221,0.00420063,0.868044,1.0248,1.25921,-0.0374881,-0.0325188,0.00613061,0.0151155,0.0114554,0.0000737484,-0.0300245,-0.0252113,0.00224642,0.0157921,0.01353,-0.000555196,-0.00703048,-0.00502155,0.000223395,-0.0054659,-0.00480153,0.00156354,-0.00585619,-0.00411841,0.000363892,-0.00317079,-0.00312075,0.0017963,0.720651,0.871395,1.11474,-0.0474703,-0.0538377,-0.0723607,0.00408131,0.00461605,0.00650277,-0.0717666,-0.0812632,-0.110368,-0.0239111,-0.0270766,-0.0365602,-0.000402228,-0.000472856,-0.000478158,0.00116887,0.00135889,0.00155087,0.00057963,0.000643189,0.000971666,-0.0102506,-0.0115637,-0.0160988,0.557027,0.686567,0.861739,-0.163989,-0.185531,-0.253383,0.00316621,0.00350822,0.00439399,-0.00853481,-0.00947881,-0.012309,-0.00037706,-0.000391074,-0.000542321,0.000172878,0.000191794,0.000244281,0.00227767,0.00256748,0.00345296,-0.00180018,-0.00211072,-0.00314579,0.00658935,0.00751893,0.0105032,0.552511,0.681442,0.854732,-0.164598,-0.18622,-0.254325,-0.0000830489,-0.000159492,-0.000612268,-0.00461433,-0.00505825,-0.0062771,0.0000101954,0.0000463813,0.0000549238,-0.000147549,-0.000170352,-0.000250221,0.00202972,0.0022881,0.00307183,0.00031553,0.000289325,0.000135112,0.00533448,0.00609362,0.00855408,0.545859,0.6738,0.84363,-0.165083,-0.186772,-0.255124,0.00224206,0.00251603,0.00343437,-0.00185462,-0.00207765,-0.00285246,0.000209148,0.000266991,0.000325145,-0.0000363409,-0.0000457184,-0.0000596467,0.0033277,0.00378632,0.00515389,0.000290867,0.000314571,0.000440389,0.00246301,0.00278996,0.00380932,0.552629,0.681612,0.854935,-0.16452,-0.186114,-0.254153,-0.00290311,-0.00347658,-0.00547391,0.00284302,0.00321293,0.00451005,0.000423983,0.000505319,0.000664192,-0.000383779,-0.000456257,-0.000679898,0.00420161,0.00485381,0.00695282,-0.0017596,-0.00199338,-0.00281845,0.00410455,0.00464854,0.00635018,0.559176,0.688832,0.864189,-0.163688,-0.185199,-0.252971,0.00432614,0.00491214,0.00667967,0.010577,0.0119568,0.0163401,0.00118212,0.00136366,0.00182615,0.000195662,0.000221015,0.000301617,0.00296953,0.00336546,0.00459031,0.000729087,0.000830246,0.00113037,0.00684896,0.00775051,0.0105865,0.751548,0.905906,1.15293,-0.0280363,-0.0321309,-0.0494292,0.00375288,0.00445115,0.00846776,0.0564674,0.0642137,0.0922049,0.0168487,0.0192778,0.0288288,0.00140219,0.00164695,0.00305471,0.00350511,0.00398424,0.00565179,-0.00117276,-0.00136168,-0.00234398,-0.0128171,-0.0144599,-0.019209,0.67286,0.814996,1.06843,0.0439798,0.0495161,0.0625454,0.0000247323,0.00015745,-0.000974541,-0.110925,-0.127917,-0.147279,0.0180885,0.0204556,0.0252232,0.00321242,0.0036879,0.00456159,0.00391469,0.0045115,0.00494484,0.00150869,0.00173353,0.00203731,-0.0197516,-0.0232329,-0.0245471,0.965099,1.12548,1.29885,-0.101666,-0.10652,-0.0211275,-0.0251872,-0.0251945,-0.0319519,0.0503741,0.0575017,0.0250748,-0.0141441,-0.0150773,-0.0026011,0.00157495,0.00140065,0.00382803,-0.00505758,-0.00522826,0.00161861,-0.0117523,-0.0116769,-0.0115529,-0.0105166,-0.0145092,-0.000179619,1.02392,1.18657,1.31554,-0.128526,-0.133296,-0.0238415,-0.0403386,-0.0401976,-0.0413185,-0.0123569,-0.016477,-0.0322538,0.0052482,0.00639287,0.00990086,0.00854633,0.00909299,0.0103189,-0.000596974,0.000242696,0.00819938,0.0193028,0.0197543,0.0219103,-0.00512088,-0.00921479,0.00148778,0.969893,1.1265,1.25781,-0.105129,-0.104379,0.00499944,-0.00249902,0.000946689,-0.00595163,-0.0206252,-0.0305342,-0.0267657,0.00771665,0.0113499,0.00977702,0.000541084,0.0000825694,0.00239476,-0.00575469,-0.0047204,0.00389916,-0.00284194,-0.00207311,-0.00145131,-0.00926683,-0.0125414,-0.00135991,0.992124,1.09302,1.21962,-0.13558,-0.0831041,0.0279361,0.00561967,0.00504766,0.00128706,-0.0177936,-0.0366638,-0.0306492,0.00713605,0.0156537,0.0137036,-0.00169813,-0.000904481,0.000394216,-0.00977212,-0.0016708,0.00721711,-0.00133177,-0.00229811,-0.00114058,-0.0240298,-0.0135962,-0.00357099,1.05474,1.10617,1.22863,-0.171004,-0.0876283,0.0264338,-0.0013872,-0.00185663,-0.00308571,-0.0111763,-0.0104969,0.000835384,0.00234834,0.0022525,0.000335047,0.000456121,0.000593033,0.000885879,-0.0135248,-0.00833999,0.000247345,0.00116133,0.00109285,0.00126336,-0.0170869,-0.00672794,0.00338869,0.870671,1.01893,1.24005,-0.0301916,-0.0232616,0.0134493,0.00397019,0.00317622,0.000900391,-0.0347585,-0.019871,0.0229836,0.0132139,0.00846575,-0.00845755,-0.000850258,-0.000696163,-0.00011492,-0.00235701,0.0000509863,0.0033217,-0.00189199,-0.0013238,-0.000258312,0.00195113,-0.00199173,-0.0049373,0.808792,0.96682,1.22242,0.0159524,0.0211124,0.0396861,-0.00159041,-0.0015471,0.00255754,0.00940175,0.00734804,-0.0127852,-0.00133344,0.000121403,0.00897761,-0.0000952241,-0.000147999,-0.00188593,-0.00215409,-0.00190954,0.00289122,-0.00213737,-0.00225693,-0.000298984,0.012236,0.0137175,0.0125216,0.92148,1.08333,1.29007,-0.085077,-0.0848618,-0.0213533,-0.00259171,-0.00217223,0.00000728995,0.0155319,0.0153129,-0.0166089,-0.00570755,-0.00617785,0.0095052,-0.000574847,-0.000839687,-0.00110883,-0.00981574,-0.00931148,-0.00109628,-0.00119278,-0.00133995,0.000239118,-0.0151849,-0.0165713,-0.00459275,0.901919,1.06464,1.25369,-0.0758143,-0.0765163,0.00569983,-0.00299643,-0.00304926,-0.00171185,0.00724569,0.00671011,-0.00852632,-0.00344333,-0.00314175,0.00394991,0.00213722,0.00229959,0.00181491,-0.00782614,-0.00732666,0.00274671,0.00131485,0.00159979,0.00237349,-0.0203565,-0.0221695,-0.00381807,0.925422,1.07543,1.25732,-0.0894197,-0.0800508,0.00732557,-0.00708604,-0.00814333,-0.00703393,0.0102867,0.00154257,-0.00974024,-0.00496916,0.000117048,0.00478523,0.00460644,0.00513153,0.00486308,-0.0125608,-0.00901031,0.00284252,0.00437582,0.00438815,0.00535091,-0.0162296,-0.0176502,0.0000648662,0.928181,1.07441,1.25577,-0.0961696,-0.0793091,0.00893063,-0.0027023,-0.00074091,0.000520299,-0.00395614,-0.0107644,-0.00464426,0.00178158,0.00653762,0.0040184,0.00197284,0.000991793,0.000564862,-0.0142001,-0.00961503,0.00211817,-0.00124058,-0.00121077,-0.000984548,-0.0204128,-0.0163548,0.00191706,0.913633,1.05386,1.25273,-0.0899268,-0.0649219,0.00955151,0.00344667,0.00400034,-0.000623614,-0.0155553,-0.0130259,0.00694404,0.00984336,0.00827382,-0.00157201,-0.00188872,-0.00222058,0.000277041,-0.0128433,-0.00720685,0.00309424,0.00181075,0.00191497,0.00115866,-0.0251048,-0.0165522,0.000380458,0.868599,1.02038,1.25141,-0.0396535,-0.0293288,0.0126609,0.00224346,0.00185715,0.00267647,-0.030807,-0.0227408,0.00706335,0.017188,0.0125705,-0.0029643,-0.00109957,-0.000719412,-0.00104178,-0.00708191,-0.00413841,0.00345981,-0.00156452,-0.00141442,-0.000975966,-0.00376937,-0.00247228,0.00274978,0.72515,0.87648,1.12167,-0.0469873,-0.053291,-0.0716306,0.00834334,0.00944166,0.0130885,-0.0688426,-0.0779605,-0.105861,-0.0236858,-0.0268217,-0.0362185,-0.0000902473,-0.00011964,0.00000177777,0.00243704,0.00279403,0.00351516,0.00260105,0.00293275,0.004096,-0.00959171,-0.0108205,-0.0150778,0.563616,0.693843,0.871043,-0.162846,-0.184249,-0.251671,0.0138529,0.0157006,0.0214091,-0.00780275,-0.00882908,-0.0120588,-0.000249881,-0.000255367,-0.000386179,0.00124164,0.00140566,0.0019189,0.00613283,0.00694291,0.00947802,0.00134433,0.00152077,0.0020776,0.00634808,0.00718118,0.00981068,0.559137,0.688776,0.864122,-0.163452,-0.184934,-0.252608,0.0105819,0.0119997,0.0163539,-0.00384389,-0.00434991,-0.00594055,0.000139135,0.000184776,0.000215026,0.000920217,0.00104199,0.00142215,0.00588196,0.00665907,0.00909031,0.0034442,0.00389662,0.00532286,0.00510713,0.00577713,0.00789285,0.554659,0.68371,0.857201,-0.163816,-0.185346,-0.25317,0.0117386,0.0133084,0.0181414,0.00118296,0.00133761,0.00182821,0.000435512,0.000520105,0.000673063,0.000988412,0.00111915,0.00152755,0.00694578,0.0078627,0.0107344,0.00250135,0.00282985,0.00386572,0.00306904,0.00347117,0.00474305,0.559137,0.688776,0.864122,-0.163533,-0.185026,-0.252733,0.0091934,0.0104287,0.014208,0.00567532,0.0064204,0.00877095,0.000641517,0.000753186,0.000991435,0.000871698,0.000987097,0.00134717,0.00660381,0.00747579,0.0102059,0.000647237,0.000732052,0.00100028,0.00469885,0.00531518,0.00726185,0.563616,0.693843,0.871043,-0.162846,-0.184249,-0.251671,0.00945511,0.0107248,0.0146124,0.0107938,0.0122116,0.0166814,0.00121155,0.00139813,0.00187239,0.000900844,0.00102007,0.00139221,0.00536173,0.00607046,0.00828631,0.000864462,0.000977826,0.00133599,0.00678481,0.00767531,0.0104856,0.751528,0.905878,1.15289,-0.0280379,-0.0321332,-0.049432,0.00375796,0.00445846,0.00847661,0.0564895,0.0642455,0.0922434,0.01685,0.0192797,0.0288311,0.00140249,0.00164738,0.00305523,0.00350978,0.00399097,0.00565992,-0.0011769,-0.00136764,-0.0023512,-0.0128261,-0.0144728,-0.0192246,0.706651,0.852494,1.10306,0.0240201,0.0275632,0.0433254,0.0314333,0.0352125,0.0328021,-0.0966638,-0.112063,-0.133479,0.0117573,0.0134678,0.0193296,-0.00695359,-0.00745163,-0.00516206,0.0111503,0.0126851,0.0137175,0.0117398,0.0131997,0.0126086,-0.021453,-0.0250155,-0.0259527,0.933894,1.09501,1.26748,-0.0853021,-0.0878881,-0.00407719,-0.00801393,-0.00852356,-0.00416994,0.0321723,0.0394032,0.00112057,-0.0120767,-0.013115,0.000614344,0.00086496,0.00112373,-0.000202723,-0.00482995,-0.00364683,0.0051333,-0.00282708,-0.00323916,-0.00250178,-0.0139559,-0.0175202,-0.00592695,0.938141,1.10005,1.23785,-0.0909345,-0.0925963,0.0118777,0.00194479,0.00413676,0.0146742,0.0182291,0.0180326,-0.000816134,-0.00389413,-0.00362834,0.000268687,-0.00199183,-0.00242187,-0.00496947,-0.0106262,-0.010326,0.000498151,0.000204285,0.000728844,0.0020632,-0.0125585,-0.0151211,-0.00494162,0.966527,1.12689,1.25541,-0.105191,-0.105797,0.00437464,-0.0123222,-0.00819489,0.0059847,-0.00324342,-0.00863848,-0.0118147,0.00131115,0.00303493,0.00358497,0.00301286,0.00204084,-0.00155156,-0.0103734,-0.0103495,0.000958402,0.00558231,0.00813584,0.00550424,-0.00859895,-0.0107944,-0.00200393,1.00013,1.15202,1.27762,-0.111154,-0.106909,0.00404279,-0.0386346,-0.0265561,-0.00632347,-0.0294715,-0.0354533,-0.0346571,0.00233172,0.00418796,0.00430449,0.00698349,0.00276641,-0.00186425,-0.0086327,-0.0109422,-0.0019013,0.0148009,0.0179208,0.0161684,-0.0013984,-0.0028105,0.00671903,0.958109,1.1097,1.25277,-0.102446,-0.0978496,0.00568152,-0.0164478,-0.00166234,0.0142512,-0.0229014,-0.0223646,-0.0018678,0.00662604,0.0063406,0.000834892,0.00405492,-0.000856779,-0.00473208,-0.00824168,-0.0130136,-0.00502161,0.00363385,0.00317136,0.000754159,-0.0128769,-0.0130857,0.000228784,0.870639,1.02669,1.25228,-0.0321849,-0.0298115,0.005186,-0.00375719,0.0035011,0.0113132,-0.0389663,-0.0338576,0.00823275,0.016572,0.0155614,-0.00159748,0.000685547,-0.00119294,-0.0031381,-0.0059711,-0.00746671,-0.00213956,0.00190338,-0.00131101,-0.00428816,0.00285858,0.00170487,-0.0014824,0.807127,0.964998,1.22404,0.00919574,0.0134869,0.0309469,0.0133549,0.0154844,0.0196184,-0.00313086,-0.00661309,-0.0228571,0.00150819,0.00321303,0.0107655,-0.00640232,-0.00729632,-0.00896806,-0.0000784045,0.000425359,0.00480995,0.00436709,0.00512227,0.00670657,0.00320177,0.00364664,0.00389912,0.92649,1.0871,1.3097,-0.0858392,-0.0845237,-0.0339251,-0.0473327,-0.045273,-0.0312822,0.00756472,0.00730783,-0.0181321,-0.00261921,-0.00301371,0.00956081,0.0229752,0.0223096,0.0158414,-0.000166938,-0.000221451,0.00780773,-0.000741016,-0.000134849,0.00305557,-0.017731,-0.0184015,-0.00891813,0.897639,1.05613,1.25207,-0.0612244,-0.0596955,0.0120327,-0.0228134,-0.0197891,0.00291322,0.0195289,0.0162319,-0.00108924,-0.00904386,-0.00821677,-0.00122056,0.00948967,0.00872563,-0.00179788,-0.00752514,-0.00702935,0.00256506,-0.00411746,-0.00264529,-0.000192704,-0.0083135,-0.0101913,0.00269446,0.907771,1.06759,1.26306,-0.0736205,-0.0716711,0.00382849,-0.0226755,-0.019969,0.00197534,0.00750052,0.00548297,0.000830746,-0.0044974,-0.0033213,-0.00117661,0.0114698,0.0102418,-0.000733113,-0.0097349,-0.00940024,0.00087467,-0.00271121,-0.00140815,-0.000594066,-0.0129042,-0.0137582,0.00180841,0.913791,1.06727,1.2647,-0.0814549,-0.0733716,0.00071644,-0.030298,-0.0217843,0.00182349,-0.00886589,-0.0122025,-0.0012828,0.00359929,0.0056706,0.00109406,0.0156761,0.0108487,-0.000660566,-0.00906412,-0.0100825,-0.000515189,0.00125472,0.00278213,0.000693243,-0.0176145,-0.0156187,0.000439297,0.906273,1.05978,1.27067,-0.0725652,-0.0637738,-0.00119324,-0.0270174,-0.0191019,-0.00482378,-0.0282053,-0.0270581,-0.00600855,0.0136483,0.013117,0.00330885,0.0133759,0.0085286,0.00157457,-0.00741335,-0.00786242,0.00197139,0.00669593,0.00592262,0.00328013,-0.0146028,-0.0121211,0.00119705,0.878767,1.03646,1.26987,-0.0408455,-0.0364507,0.00239457,-0.0188637,-0.0146076,-0.00243899,-0.0410435,-0.0375928,-0.00855202,0.0183833,0.0166254,0.00198221,0.00855368,0.0064041,0.000562013,-0.00707895,-0.0071747,-0.000559873,0.00822635,0.00653232,0.00244709,0.000484779,0.000910925,0.00521642,0.789868,0.949537,1.21631,-0.00911252,-0.0104758,-0.0165453,0.0241234,0.0274545,0.0392661,-0.0181919,-0.0208268,-0.0317287,-0.00366167,-0.00420053,-0.00692165,0.00528928,0.00604637,0.00908243,-0.00492692,-0.00552825,-0.00698758,0.0095642,0.0108941,0.0158683,-0.00355553,-0.00406198,-0.00605875,0.758728,0.913711,1.15937,-0.022514,-0.0260741,-0.0437304,0.0507225,0.0579777,0.0867384,-0.00370833,-0.00425517,-0.00660255,0.0000729396,0.000111922,0.000143064,0.013602,0.0156822,0.025356,-0.0112788,-0.0127476,-0.0172895,0.00181162,0.00204164,0.00268343,-0.00490572,-0.00552338,-0.00716079,0.758728,0.913711,1.15937,-0.022514,-0.0260741,-0.0437304,0.0507225,0.0579777,0.0867384,-0.00370833,-0.00425517,-0.00660255,0.0000729396,0.000111922,0.000143064,0.013602,0.0156822,0.025356,-0.0112788,-0.0127476,-0.0172895,0.00181162,0.00204164,0.00268343,-0.00490572,-0.00552338,-0.00716079,0.75425,0.908644,1.15245,-0.0228776,-0.0264855,-0.0442923,0.0518791,0.0592863,0.0885259,0.00131852,0.00143235,0.00116621,0.000369316,0.000447251,0.000601101,0.0136702,0.0157593,0.0254614,-0.010215,-0.011544,-0.0156455,0.000868765,0.000974867,0.0012263,-0.00694381,-0.00782933,-0.0103106,0.758728,0.913711,1.15937,-0.0225948,-0.0261656,-0.0438552,0.0493339,0.0564066,0.0845925,0.00581088,0.00651513,0.00810895,0.000575321,0.000680332,0.000919473,0.0135535,0.0156273,0.025281,-0.010557,-0.0119309,-0.016174,-0.000985346,-0.00112293,-0.00163915,-0.00531401,-0.00598533,-0.00779178,0.755849,0.91041,1.15562,-0.0226727,-0.0262549,-0.0439569,0.0523576,0.0598737,0.0885384,0.00719001,0.00809654,0.00990879,0.000602426,0.000711411,0.000954845,0.0136129,0.0156954,0.0253585,-0.0117495,-0.0132983,-0.0177302,-0.00203722,-0.00232907,-0.00301189,-0.00555313,-0.00625952,-0.00810385,0.796241,0.956665,1.22493,-0.0068611,-0.00796482,-0.0136065,0.0152788,0.0176076,0.027977,0.0179561,0.0205238,0.0308504,0.00392171,0.00455279,0.00737316,0.00355315,0.00412452,0.00703021,-0.000793995,-0.000942731,-0.00194683,-0.007531,-0.00862594,-0.0131979,-0.00471064,-0.00533534,-0.00734516,0.813333,0.974082,1.23553,0.0010903,0.00190592,0.0133372,0.00918369,0.011944,0.024331,0.00150872,-0.0000581462,-0.0160643,-0.000300306,0.000060746,0.00606525,-0.00140654,-0.00180289,-0.00606131,-0.00526695,-0.00602962,-0.00515423,0.00108035,0.00204046,0.00829121,0.00169881,0.00159703,-0.000313864,0.86097,1.02289,1.25414,-0.0231865,-0.0231957,0.0114541,-0.0325794,-0.0310983,0.00255305,0.00347437,0.0031823,-0.010479,-0.000366514,-0.000125263,0.00459895,0.0118317,0.0120532,-0.00302792,0.00565076,0.00539142,0.00416722,-0.0023176,-0.00243091,0.00355233,-0.00362858,-0.00397502,-0.0003442,0.87013,1.03137,1.25108,-0.0294231,-0.0292709,0.0105258,-0.0387672,-0.0370413,0.00651363,0.00650821,0.00463652,-0.00473744,0.000323448,0.000915457,0.00396084,0.015885,0.0160311,-0.0022626,0.00556688,0.00553427,0.00205382,-0.00398722,-0.00312931,0.000242407,-0.000974068,-0.00173746,0.00114782,0.875822,1.03784,1.25074,-0.0304942,-0.0303092,0.0112258,-0.0429413,-0.0416268,0.00669535,-0.0038216,-0.00560319,-0.00913562,0.00192781,0.00247405,0.00441313,0.0163904,0.0164936,-0.00259508,0.00631186,0.00613603,0.00206978,0.00119689,0.00200712,0.00281225,0.000480377,0.000133743,0.00153351,0.880493,1.04175,1.26127,-0.0305253,-0.029899,0.010089,-0.05122,-0.048703,-0.00448426,-0.00801109,-0.00913231,-0.0069401,0.00262404,0.00313145,0.00399678,0.0170528,0.0167777,-0.00169824,0.0118065,0.0108211,0.00672177,0.00275079,0.00338253,0.00189192,-0.00107536,-0.00108476,0.00217395,0.865618,1.02356,1.24738,-0.0258465,-0.0244833,0.0125106,-0.0372202,-0.0310934,0.0109689,-0.0130247,-0.0132352,-0.00584586,0.00437703,0.00471825,0.0038419,0.014132,0.013296,-0.00370075,0.00725904,0.00471211,-0.000226475,0.00546727,0.00535923,0.00111704,-0.00200336,-0.00202831,0.0019912,0.852523,1.01359,1.27331,-0.010778,-0.0100903,0.000842056,-0.0215362,-0.0185422,-0.00226226,-0.027358,-0.0262298,-0.0102384,0.00582452,0.00572716,0.000639022,0.00509579,0.00452508,-0.000792449,0.000213569,-0.000916468,-0.00221038,0.0123265,0.0113909,0.00397871,0.00647438,0.00634818,0.00416467,0.82427,0.983878,1.24638,0.000723301,0.00294988,0.016039,0.000666358,0.00304274,0.0136256,0.011476,0.00849308,-0.00556726,-0.00327714,-0.00233207,0.00371759,-0.00205932,-0.00305287,-0.00765029,-0.00245686,-0.00214606,-0.000463641,-0.00318081,-0.00214734,0.00268748,0.00530938,0.00486487,0.00427708,0.868999,1.03216,1.27086,-0.037953,-0.0383741,-0.00474732,-0.0310552,-0.0309172,-0.00505636,0.0110185,0.0101682,-0.00504804,-0.00432478,-0.00427943,0.00215797,0.01604,0.0162554,0.00300308,0.000560123,0.000873519,0.00201193,-0.00387673,-0.00379454,0.00214245,-0.00682469,-0.00773732,-0.00221503,0.876372,1.04114,1.27182,-0.0422892,-0.0434084,-0.00246175,-0.0353166,-0.0358002,-0.00476752,0.00255316,0.00338225,-0.00315661,-0.00102393,-0.00117751,0.00134538,0.0171182,0.0175835,0.00141665,0.000490966,0.000482834,0.00130326,-0.00039565,-0.000794896,0.00201539,-0.0068926,-0.00733014,0.000287504,0.885027,1.04454,1.26817,-0.0472312,-0.0456476,-0.0004554,-0.0392588,-0.035066,-0.00170556,-0.000410181,-0.00217431,-0.00265604,0.000455669,0.00131476,0.00122401,0.0188048,0.0174977,0.000284986,-0.000373124,-0.00151031,0.000624204,-0.00092854,0.000304291,0.00183224,-0.00556912,-0.00595542,0.000543631,0.868887,1.02777,1.25913,-0.0388289,-0.036203,0.00440423,-0.0279575,-0.0228292,0.00627145,-0.0104089,-0.0110189,-0.000990369,0.00484805,0.0052463,0.00101176,0.0148915,0.0128023,-0.00276595,-0.00149782,-0.0032549,-0.00133173,0.00299554,0.00340493,0.000635449,-0.00649926,-0.00606543,0.000980821,0.863098,1.02091,1.2616,-0.0336784,-0.0304636,0.00277755,-0.0253626,-0.0194091,0.00421883,-0.0158274,-0.0146206,0.000412442,0.00788026,0.00749296,0.000295793,0.0132413,0.0108451,-0.00176298,-0.000695822,-0.0025681,-0.000916487,0.00522995,0.00445702,-0.000316074,-0.00557365,-0.00518358,0.000708348,0.84953,1.01261,1.26322,-0.0215547,-0.0212029,0.00155819,-0.0146571,-0.0135717,0.00287823,-0.0191264,-0.0189868,0.000835499,0.00898013,0.00897883,0.0000825116,0.00758348,0.00717913,-0.000982311,-0.00275,-0.0031792,-0.000574117,0.00589154,0.00557327,-0.000765959,-0.000757666,-0.00066188,0.000316528]+ "irradiance": [0.787525,0.947183,1.21709,-0.0128871,-0.0145809,-0.0199165,-0.0216912,-0.024515,-0.0335227,-0.0226589,-0.0256378,-0.0350183,-0.00620364,-0.00699162,-0.00958744,-0.00623858,-0.00705768,-0.00964144,-0.00212922,-0.00240502,-0.00329061,-0.0105509,-0.0119378,-0.0163059,-0.00414027,-0.00468563,-0.00639859,0.738265,0.891448,1.14096,-0.0415297,-0.0469878,-0.0641822,-0.0613031,-0.0693331,-0.0947412,-0.00666444,-0.00754116,-0.0102996,-0.000164008,-0.000158209,-0.000253468,-0.0219174,-0.0247971,-0.0338723,-0.00980345,-0.0110879,-0.0151508,-0.00276039,-0.00312344,-0.00426606,-0.00145615,-0.00164875,-0.0022504,0.729309,0.881314,1.12712,-0.0423377,-0.047902,-0.0654308,-0.0694891,-0.0785949,-0.107392,-0.00111113,-0.00125799,-0.00171721,0.000277233,0.000341024,0.000428451,-0.0223998,-0.0253429,-0.0346179,-0.012195,-0.0137937,-0.0188468,0.000610242,0.000690194,0.0009431,-0.00289992,-0.00328227,-0.00448168,0.730707,0.882808,1.12998,-0.0422219,-0.0477847,-0.0651816,-0.0681888,-0.0772125,-0.104719,-0.000105739,-0.000157315,0.00028999,0.000345285,0.000414414,0.000566514,-0.0223234,-0.0252667,-0.0344513,-0.0118302,-0.0134136,-0.0180826,0.00130522,0.00145183,0.00232894,-0.00266381,-0.0030229,-0.00401197,0.72871,0.880371,1.12656,-0.042488,-0.0481302,-0.0655913,-0.0700922,-0.0795621,-0.107909,-0.000917724,-0.00100318,-0.00141457,0.000312197,0.000387325,0.00048253,-0.0225097,-0.0255122,-0.034729,-0.0124137,-0.0141612,-0.0189932,0.000737173,0.000856444,0.00114404,-0.00293781,-0.0033316,-0.00454241,0.733278,0.885576,1.13353,-0.0419621,-0.047508,-0.0648129,-0.0656175,-0.0743816,-0.101206,0.00226046,0.00275908,0.0032482,0.00053198,0.000649137,0.000798054,-0.0221305,-0.0250547,-0.0341818,-0.0109466,-0.0123941,-0.016902,0.00285925,0.00334212,0.00428876,-0.00236481,-0.00274025,-0.00357782,0.790954,0.950547,1.22174,-0.00960914,-0.0109881,-0.0149956,-0.0201508,-0.0228443,-0.0312323,0.0199909,0.0231963,0.0316186,0.00565002,0.00651475,0.00885036,-0.00446563,-0.00506353,-0.0069162,-0.00271103,-0.00292566,-0.00401773,0.00975895,0.0111002,0.0151556,-0.00394222,-0.00468825,-0.00637588,0.800496,0.959563,1.21962,0.00644747,0.00821149,0.0191199,-0.0227969,-0.0271348,-0.0408284,-0.00119849,-0.00315642,-0.0193024,0.0000410554,0.000592982,0.00593914,0.00555783,0.0066437,0.011335,-0.0101426,-0.0114592,-0.0114748,-0.00493011,-0.00625899,-0.0121223,0.00339554,0.0034675,0.000937253,0.860872,1.01938,1.24144,-0.0272271,-0.0267536,0.00751207,0.0300581,0.0255765,-0.0176962,0.0249131,0.0250343,0.0119226,-0.00560587,-0.0056801,-0.00224833,-0.0138034,-0.0135731,0.00301913,0.00309019,0.00200364,-0.00302856,0.0108663,0.0109264,0.00605545,-0.00242788,-0.00338045,-0.00243578,0.862347,1.02182,1.23465,-0.032222,-0.0320372,0.00582751,0.0275115,0.0239823,-0.0242222,-0.00537432,-0.00596468,-0.00850571,0.00162083,0.00191538,0.00185963,-0.0150149,-0.0148549,0.00306737,0.00103919,0.000379351,-0.00421886,-0.00426092,-0.00476123,-0.00560804,-0.00292746,-0.00395755,-0.00509168,0.887573,1.04676,1.25702,-0.0338124,-0.0335401,0.00483102,0.0480382,0.0439146,-0.00574505,-0.0260572,-0.0260476,-0.0229879,0.00432752,0.00465832,0.00392746,-0.0157253,-0.0154292,0.00267342,0.00435309,0.00317731,-0.00130267,-0.0173181,-0.0175083,-0.0153057,0.00322475,0.00232248,0.00027055,0.860906,1.02005,1.24154,-0.0291718,-0.0285755,0.00781472,0.0279506,0.0234507,-0.0185362,0.00188072,0.00324124,0.00620576,0.000174752,0.000126676,-0.000234617,-0.0129673,-0.0123648,0.00479953,0.00152834,-0.000160204,-0.00367052,0.00047771,0.000930894,0.00146565,-0.00311592,-0.00372695,-0.00314301,0.852004,1.01337,1.24106,-0.028092,-0.0280754,0.00567179,0.0203721,0.0180982,-0.0200936,-0.00189919,-0.0004092,0.0121622,0.00259356,0.00257306,-0.000565682,-0.0127473,-0.0125429,0.00392074,-0.00138562,-0.00226723,-0.0055742,0.000623176,0.00136291,0.00549433,-0.00420041,-0.00468323,-0.00303971,0.837734,1.00022,1.25399,-0.010854,-0.0107294,0.00332394,0.0114334,0.0104304,-0.00919001,-0.012505,-0.0115858,0.00701943,0.00563716,0.00570465,-0.000606735,-0.0044717,-0.00430582,0.00227023,-0.000358693,-0.000615321,-0.00239543,-0.00414448,-0.00367089,0.00379254,0.00128062,0.000988999,-0.00141091,0.822954,0.98456,1.24419,-0.00418006,-0.00284488,0.0134422,-0.0037781,-0.00565253,-0.0174685,0.00797472,0.00737906,-0.00648878,-0.00309924,-0.00273474,0.0037775,0.00165075,0.00249459,0.0077429,-0.00530499,-0.00581176,-0.00421836,0.00191514,0.00155918,-0.00347616,0.0011147,0.00136022,0.00236154,0.854811,1.01673,1.25782,-0.0320514,-0.03118,0.00335539,0.0194942,0.0180646,-0.00380148,0.00193945,0.00160735,-0.00853064,-0.00106941,-0.00101542,0.00348796,-0.0111989,-0.0106035,0.00125953,-0.00180661,-0.00203874,0.000381528,0.000636795,0.000582873,-0.00366002,-0.00867818,-0.00885823,-0.00133129,0.854748,1.01285,1.24118,-0.0294058,-0.0267382,0.0158177,0.0187663,0.0150899,-0.016121,0.0037877,0.00201504,-0.0026555,0.00026282,0.00086454,0.00225308,-0.00986331,-0.00856418,0.00746947,-0.0021122,-0.00213927,-0.000844322,0.000703785,-0.0000406061,-0.00157516,-0.00617337,-0.00698879,0.00092101,0.850005,1.01014,1.24037,-0.0229792,-0.0207523,0.0206152,0.0138771,0.0111516,-0.0183881,-0.0118688,-0.0124227,-0.0110753,0.00446025,0.00486087,0.00406341,-0.00586924,-0.0045922,0.0106492,-0.00357584,-0.00387308,-0.00225576,-0.00634459,-0.00679376,-0.00606706,-0.00225405,-0.00214503,0.00526742,0.858125,1.017,1.24561,-0.0314373,-0.0289928,0.0131091,0.0220577,0.0184534,-0.0130407,-0.00115696,-0.00187198,0.0028731,0.0012198,0.00176116,0.0000877137,-0.0108612,-0.00939949,0.0066399,-0.00147662,-0.00191581,-0.000877415,-0.000365041,-0.00118455,0.0000259359,-0.00615863,-0.00655571,0.00113428,0.855363,1.01206,1.24357,-0.0289972,-0.0254601,0.0146203,0.0179333,0.0109861,-0.0171108,-0.011662,-0.0111853,0.00137112,0.00553361,0.00554909,0.000663614,-0.00865102,-0.00598065,0.00863058,-0.00282911,-0.00516589,-0.00314004,-0.0041978,-0.00399893,0.0000983545,-0.00523437,-0.00485754,0.00236351,0.835127,0.993163,1.24984,-0.0129033,-0.0100216,0.00941048,0.00532716,0.000906712,-0.0120507,-0.0109294,-0.0074001,0.00738052,0.00566315,0.00451564,-0.00230642,-0.00275675,-0.00105727,0.00556439,-0.00359931,-0.00425899,-0.00211841,-0.0026541,-0.000813324,0.0040823,-0.00100434,-0.0013968,0.000645681,0.729509,0.881399,1.12839,-0.0467424,-0.0530276,-0.0712735,-0.00356342,-0.00403267,-0.00531706,-0.0666252,-0.075459,-0.102446,-0.0236764,-0.0268164,-0.0362123,-0.000963635,-0.00110976,-0.00135106,0.00324216,0.00370843,0.00476489,-0.00185991,-0.00211556,-0.00279986,-0.00858882,-0.00968229,-0.0135223,0.563616,0.693843,0.871043,-0.163331,-0.184797,-0.252421,-0.00312799,-0.00351208,-0.00483417,-0.00570718,-0.00645809,-0.00882019,-0.000219454,-0.000220942,-0.000339157,-0.000316014,-0.000356715,-0.000488385,0.00451025,0.00510706,0.00697039,-0.00326112,-0.00368997,-0.00503991,0.00737592,0.0083441,0.0113992,0.558189,0.687495,0.862693,-0.164101,-0.185704,-0.253604,-0.00644702,-0.00727783,-0.00996171,-0.00282568,-0.00343343,-0.0043244,0.0000356534,0.0000384371,0.0000604703,-0.000642574,-0.000727317,-0.00099287,0.00451963,0.00517458,0.00697461,-0.00120126,-0.00136814,-0.00185493,0.00570266,0.00635639,0.00883024,0.556418,0.683723,0.864382,-0.167018,-0.190358,-0.256482,-0.00684113,-0.00744186,-0.0117001,0.00829701,0.00817313,0.0170444,0.000436146,-0.000050206,0.00175217,-0.000646604,-0.000608417,-0.00126299,0.00494531,0.00583923,0.00704142,-0.00328745,-0.00361991,-0.00571979,0.00743027,0.00840923,0.0127357,0.636202,0.773727,1.01852,-0.107938,-0.123673,-0.142421,-0.00873854,-0.00977028,-0.0150059,-0.000951478,-0.000963839,-0.00329603,-0.00020291,-0.000184486,-0.000601835,-0.00120158,-0.00134282,-0.00212771,0.00195993,0.00231153,0.00157805,-0.00225331,-0.00254749,-0.00354334,-0.000294205,-0.000213799,-0.00235455,0.564091,0.694089,0.872507,-0.163334,-0.18487,-0.25236,-0.0012593,-0.00141044,-0.00212137,0.0107621,0.0124973,0.0158129,0.00137096,0.00163216,0.0020655,-0.00027098,-0.000307812,-0.000428955,0.00526789,0.00603849,0.00796702,0.000554288,0.000638355,0.0009992,0.00712257,0.00793546,0.0113389,0.752697,0.907175,1.15645,-0.0276135,-0.0316344,-0.0483254,0.00192,0.00228869,0.00374418,0.0567952,0.0647225,0.0922712,0.0168116,0.0192403,0.0286925,0.0010311,0.00120527,0.00212307,0.00454369,0.00524966,0.0080726,-0.000970871,-0.0011425,-0.00170238,-0.0131332,-0.014885,-0.0196908,0.674555,0.815024,1.06506,0.0495696,0.0574047,0.0732287,-0.0217849,-0.0252712,-0.0300659,-0.109856,-0.127845,-0.149824,0.0207393,0.024107,0.0302933,0.00523577,0.00607406,0.00741895,0.00786213,0.00923883,0.0105487,-0.00607644,-0.00709569,-0.00812058,-0.017887,-0.0209324,-0.0222696,0.883645,1.02887,1.18098,-0.0687556,-0.0645631,0.0285511,-0.00472256,-0.0086901,-0.0175563,0.0315105,0.0440019,0.0323728,-0.00759729,-0.00888225,-0.000519995,0.00213982,0.00294328,0.00454949,-0.00197669,-0.000520843,0.00709915,-0.0013919,-0.00101487,-0.000851769,-0.0218369,-0.0258815,-0.0138033,0.907239,1.06138,1.19687,-0.0800625,-0.07853,0.0266419,0.0165289,0.0157453,0.00154129,-0.0129637,-0.013242,-0.0172969,0.00336094,0.00362366,0.0040498,-0.00483681,-0.00475794,-0.00076464,-0.000344163,0.00136025,0.0108934,0.0100496,0.0123107,0.0101821,-0.020391,-0.0238571,-0.0132019,0.907376,1.05137,1.17719,-0.0804518,-0.0781026,0.0239283,0.023123,0.0225669,0.00663528,0.0237665,0.0291194,0.0300844,-0.00309608,-0.00190891,0.00191971,-0.00595762,-0.0047675,0.00200444,-0.00408008,-0.00326378,0.00687755,-0.00984809,-0.0158576,-0.0181096,-0.015417,-0.0191261,-0.0114021,0.945701,1.09109,1.23362,-0.100326,-0.0909014,0.00615767,-0.00416688,-0.0180981,-0.0337721,-0.0276966,-0.0312386,-0.0254468,0.0131775,0.0139419,0.0141744,0.00464837,0.00932008,0.013409,-0.0127293,-0.0151936,-0.00774469,-0.00591713,-0.00906822,-0.0100239,-0.0155294,-0.0153867,-0.0090672,0.906879,1.05085,1.19708,-0.062004,-0.0531223,0.0456706,-0.0158392,-0.0346743,-0.0475549,-0.022752,-0.0204167,0.00330638,0.00812736,0.00758809,0.00169503,0.0150287,0.0212744,0.0228566,-0.00779971,-0.0128522,-0.00553231,-0.000440279,0.000438956,0.000803565,-0.00499292,-0.00493047,0.00686839,0.850225,1.009,1.23215,-0.0235832,-0.021935,0.0143697,-0.0109869,-0.015063,-0.0187087,-0.0204032,-0.016588,0.0267149,0.0106351,0.00983894,-0.00739616,0.0036441,0.00480044,0.00563833,-0.00439115,-0.0047902,0.000498097,0.00771721,0.00980612,0.0104849,-0.00122416,-0.00214435,-0.00552289,0.835614,0.990697,1.24577,0.00267216,0.00883513,0.026658,0.00970429,0.00788269,0.00289505,0.0315913,0.0258439,0.00453388,-0.0088642,-0.00647811,0.00221516,-0.00325456,-0.00244938,-0.000923271,-0.00473516,-0.00319338,0.00157928,0.00773767,0.0068118,0.0039396,0.0173337,0.0175205,0.0156406,0.897277,1.05733,1.27082,-0.0664869,-0.0632194,-0.00351023,0.0150228,0.0143071,-0.000950169,0.0152068,0.0176642,-0.00928711,-0.00605199,-0.00747242,0.0058794,-0.00718409,-0.00682732,0.000740639,-0.00991774,-0.00963938,-0.000363748,0.00371928,0.00398372,-0.000491779,-0.0122695,-0.011494,0.000741346,0.893818,1.04904,1.24355,-0.0623718,-0.0576028,0.0176422,0.0242595,0.0223354,-0.00073703,0.019934,0.0166169,0.00566039,-0.00684755,-0.00559846,-0.00158721,-0.0122168,-0.0117057,-0.000351845,-0.00883122,-0.00729283,0.00336766,0.00486114,0.00409776,0.00140844,-0.0111979,-0.0127808,0.00215107,0.89989,1.05486,1.2508,-0.0650871,-0.0589376,0.0149052,0.0274111,0.0256949,0.00152978,0.00134054,0.000273788,-0.00188826,-0.00101401,-0.000228786,0.00134506,-0.0127588,-0.0120977,0.0000316478,-0.0077634,-0.00597146,0.00376577,-0.00180545,-0.00291932,-0.00194784,-0.0102449,-0.0106832,0.00359494,0.891089,1.04077,1.23957,-0.0644468,-0.0539001,0.0179448,0.0191815,0.0113632,-0.0109827,-0.00604571,-0.00818229,0.000133488,0.00552859,0.00721193,0.00385779,-0.00827134,-0.00397203,0.00663589,-0.00693874,-0.0062848,0.00284972,-0.00143038,-0.00321433,-0.00155977,-0.0164026,-0.0150354,-0.000257323,0.897824,1.04435,1.24926,-0.0661393,-0.0514124,0.0156781,0.0252964,0.013644,-0.00541746,-0.0181562,-0.0168054,0.00339956,0.00818124,0.00739884,-0.00154772,-0.0126079,-0.00551676,0.00396355,-0.0067891,-0.00698848,0.00242829,-0.00281226,-0.00236104,0.000651695,-0.0132002,-0.00932617,0.00474064,0.864498,1.02013,1.25347,-0.0350887,-0.0293282,0.00977904,0.0141562,0.0101815,-0.00134962,-0.027682,-0.0221626,0.00624837,0.0149575,0.0124329,-0.00184987,-0.00643677,-0.00423086,0.00110793,-0.00483917,-0.0039824,0.00262238,-0.00559888,-0.00378335,0.000736385,-0.00317166,-0.00309039,0.00158832,0.72053,0.871234,1.11451,-0.0475521,-0.0539442,-0.072525,0.00408972,0.00462909,0.0065097,-0.0718517,-0.0813773,-0.110522,-0.0239441,-0.0271195,-0.0366261,-0.000412469,-0.000486045,-0.000499316,0.00119227,0.00138952,0.00159679,0.000590996,0.000659491,0.00098732,-0.0102455,-0.0115585,-0.0160822,0.554043,0.682762,0.856505,-0.164178,-0.185771,-0.253713,0.00486246,0.00567046,0.00736907,-0.0115287,-0.0132953,-0.0175601,-0.000514353,-0.000566084,-0.00078312,0.000250663,0.000290947,0.000380709,0.00250558,0.00285799,0.00385269,-0.000564506,-0.000535575,-0.000978515,0.00550317,0.00613435,0.00859816,0.549883,0.678136,0.850139,-0.164764,-0.186429,-0.254615,0.00141022,0.00171929,0.00199814,-0.00725001,-0.00837437,-0.0108846,-0.000110668,-0.000105685,-0.00015636,-0.0000790722,-0.0000841975,-0.000130516,0.00223036,0.00254053,0.00342256,0.00140334,0.00165797,0.00203674,0.00437827,0.00489055,0.00688251,0.545507,0.673312,0.843066,-0.16514,-0.186851,-0.255215,0.00259318,0.00300347,0.00399883,-0.00201245,-0.00229686,-0.00310629,0.000187179,0.000236477,0.00028981,0.00000358028,0.00000971133,0.00000454124,0.00320082,0.0036102,0.00494995,0.000395478,0.000459861,0.000608633,0.00243025,0.00274446,0.00375662,0.549686,0.677862,0.849849,-0.164907,-0.186611,-0.254816,0.000379343,0.000699523,0.000208761,0.0026304,0.00297089,0.00411154,0.000416818,0.0004999,0.000647846,-0.000073289,-0.0000576319,-0.000146185,0.00271013,0.00296216,0.00436443,-0.00154956,-0.0017457,-0.00243399,0.00405615,0.00458275,0.00627093,0.559088,0.68871,0.864048,-0.163703,-0.18522,-0.252995,0.00439774,0.00501152,0.00679482,0.0106475,0.0120547,0.0164536,0.0011909,0.00137585,0.00184028,0.000204575,0.000233385,0.00031595,0.00295751,0.00334878,0.00457098,0.000687408,0.000772403,0.00106334,0.00682936,0.00772332,0.0105549,0.751503,0.905845,1.15286,-0.0280399,-0.0321359,-0.049435,0.00376431,0.00446702,0.00848615,0.0565171,0.0642827,0.0922848,0.0168516,0.0192819,0.0288335,0.00140286,0.00164789,0.0030558,0.00351562,0.00399884,0.00566869,-0.00118207,-0.00137462,-0.00235897,-0.0128373,-0.0144879,-0.0192414,0.66063,0.79867,1.04636,0.0520614,0.0603918,0.0766293,0.000309106,0.000561037,-0.000549619,-0.118535,-0.138012,-0.161404,0.0214998,0.02502,0.0313314,0.0032567,0.00372724,0.00471288,0.00451941,0.0053238,0.00602131,0.00160138,0.00187596,0.00211849,-0.019328,-0.0226004,-0.0241777,0.901682,1.04255,1.18406,-0.0729347,-0.0679661,0.0281205,-0.0202856,-0.0190296,-0.024125,0.0699396,0.083158,0.0682688,-0.0164766,-0.0181859,-0.00828854,-0.00147166,-0.00247361,-0.00135847,-0.0041447,-0.00394999,0.00313747,-0.00896078,-0.00812438,-0.00698926,-0.0131327,-0.0172831,-0.00646912,0.990061,1.14265,1.25808,-0.111902,-0.111374,0.00290989,-0.0308005,-0.0284522,-0.0265959,0.00582065,0.00684885,0.000664505,0.000419867,0.00016726,0.00180014,0.00490472,0.00455237,0.00469164,0.000366145,0.00167465,0.0102863,0.0166698,0.0166131,0.0180572,-0.00823976,-0.0130583,-0.00495064,0.943573,1.09414,1.21643,-0.0947451,-0.0915653,0.0202458,0.0043863,0.00928277,0.00543029,-0.014825,-0.0220501,-0.0135414,0.00827789,0.0116342,0.00981804,-0.000973897,-0.00174748,0.0000374596,-0.00336134,-0.00187574,0.007284,-0.00421494,-0.00376261,-0.00375973,-0.0145979,-0.0189429,-0.0100142,0.972634,1.07035,1.19206,-0.124936,-0.0710252,0.0417408,0.007824,0.00780756,0.00503326,-0.0201057,-0.0377616,-0.0298938,0.00939806,0.0177267,0.0158437,-0.00233799,-0.001708,-0.000648919,-0.00822116,-0.0000422503,0.00904504,-0.00194945,-0.00304774,-0.00209683,-0.0257499,-0.0157093,-0.00658655,1.05129,1.10191,1.22323,-0.170331,-0.0868376,0.0273426,-0.00287092,-0.00350229,-0.00514177,-0.00809702,-0.00656597,0.00591739,0.0019855,0.00180736,-0.000180869,0.00073405,0.00088698,0.00121845,-0.0134095,-0.00808421,0.000651789,0.00182268,0.00184729,0.0022726,-0.018125,-0.00809017,0.00159568,0.862763,1.00886,1.22881,-0.024228,-0.0155968,0.0219945,0.00382506,0.00298547,0.000687828,-0.0294917,-0.0132699,0.0303524,0.0104741,0.0050025,-0.0123166,-0.000802806,-0.000633561,-0.0000459908,-0.00133061,0.00134647,0.00476874,-0.00184388,-0.0012597,-0.000186928,0.00233692,-0.00140631,-0.00428852,0.802521,0.958427,1.21189,0.0205159,0.027303,0.0472672,-0.00178062,-0.00166739,0.00197414,0.00595894,0.00277929,-0.0186006,0.000122737,0.00209146,0.0114092,-0.000538009,-0.000778108,-0.00251629,-0.00153099,-0.001043,0.00388987,-0.00259544,-0.00280476,-0.00117317,0.0128127,0.0145347,0.0134559,0.906121,1.06256,1.26429,-0.0711656,-0.0659347,0.00197067,-0.00304482,-0.00267679,-0.000916967,0.0144888,0.0139549,-0.0178877,-0.00584743,-0.00632783,0.00891249,-0.000840375,-0.001209,-0.00150472,-0.00798643,-0.00683063,0.00201908,-0.00154967,-0.00175663,-0.000424638,-0.0112418,-0.0111436,0.0019956,0.884456,1.04204,1.22441,-0.0625293,-0.0590826,0.0277547,-0.00185613,-0.00161064,-0.0000341217,0.0115326,0.0129746,0.00167224,-0.00583183,-0.00657611,-0.00132104,0.00142831,0.00138734,0.00076902,-0.00492418,-0.00364262,0.00746482,0.00144822,0.00171487,0.00245783,-0.0197727,-0.0211083,-0.00301472,0.914182,1.0612,1.23896,-0.0817305,-0.0702737,0.0194391,-0.00580651,-0.00663656,-0.00507419,0.0149053,0.00789325,-0.00027896,-0.0066067,-0.00221568,0.00138809,0.00397613,0.00438478,0.00392274,-0.0103475,-0.00623911,0.00646839,0.00414444,0.00409898,0.00484666,-0.0169186,-0.0184488,-0.00145611,0.917067,1.06043,1.23843,-0.0875737,-0.0686188,0.0215283,-0.00204304,0.000132502,0.0018192,-0.000783758,-0.00637015,0.00198096,0.00120953,0.00557808,0.00247258,0.00186261,0.000815349,0.000279357,-0.0122771,-0.0072431,0.00504682,-0.00190066,-0.00201501,-0.00208546,-0.0195898,-0.0154384,0.0024093,0.910365,1.04953,1.2478,-0.0873899,-0.0615893,0.0133217,0.00312886,0.00357486,-0.00111202,-0.0141456,-0.0111574,0.00910365,0.00926027,0.0075215,-0.00243689,-0.0017166,-0.00199289,0.000536269,-0.0123376,-0.00654627,0.00384822,0.00181522,0.00192011,0.00116866,-0.0249044,-0.0163138,0.000630049,0.864366,1.01498,1.24443,-0.0370838,-0.0260347,0.016537,0.00263942,0.00230974,0.00331259,-0.0276957,-0.0187866,0.0125181,0.0162517,0.0113767,-0.00445214,-0.00119605,-0.000814109,-0.00117436,-0.00625245,-0.00308726,0.00486233,-0.00186455,-0.00177291,-0.00147649,-0.00403675,-0.00280263,0.0019797,0.725074,0.876382,1.12152,-0.0470635,-0.0533894,-0.0717842,0.00832833,0.00942228,0.0130582,-0.0688837,-0.0780135,-0.105944,-0.0237157,-0.0268603,-0.0362788,-0.000101161,-0.000133728,-0.0000202226,0.00245645,0.00281908,0.00355428,0.00259516,0.00292515,0.00408413,-0.00957207,-0.0107951,-0.0150382,0.563616,0.693843,0.871043,-0.162846,-0.184249,-0.251671,0.0138529,0.0157006,0.0214091,-0.00780275,-0.00882908,-0.0120588,-0.000249881,-0.000255367,-0.000386179,0.00124164,0.00140566,0.0019189,0.00613283,0.00694291,0.00947802,0.00134433,0.00152077,0.0020776,0.00634808,0.00718118,0.00981068,0.559137,0.688776,0.864122,-0.163452,-0.184934,-0.252608,0.0105819,0.0119997,0.0163539,-0.00384389,-0.00434991,-0.00594055,0.000139135,0.000184776,0.000215026,0.000920217,0.00104199,0.00142215,0.00588196,0.00665907,0.00909031,0.0034442,0.00389662,0.00532286,0.00510713,0.00577713,0.00789285,0.554659,0.68371,0.857201,-0.163816,-0.185346,-0.25317,0.0117386,0.0133084,0.0181414,0.00118296,0.00133761,0.00182821,0.000435512,0.000520105,0.000673063,0.000988412,0.00111915,0.00152755,0.00694578,0.0078627,0.0107344,0.00250135,0.00282985,0.00386572,0.00306904,0.00347117,0.00474305,0.559137,0.688776,0.864122,-0.163533,-0.185026,-0.252733,0.0091934,0.0104287,0.014208,0.00567532,0.0064204,0.00877095,0.000641517,0.000753186,0.000991435,0.000871698,0.000987097,0.00134717,0.00660381,0.00747579,0.0102059,0.000647237,0.000732052,0.00100028,0.00469885,0.00531518,0.00726185,0.563616,0.693843,0.871043,-0.162846,-0.184249,-0.251671,0.00945511,0.0107248,0.0146124,0.0107938,0.0122116,0.0166814,0.00121155,0.00139813,0.00187239,0.000900844,0.00102007,0.00139221,0.00536173,0.00607046,0.00828631,0.000864462,0.000977826,0.00133599,0.00678481,0.00767531,0.0104856,0.751528,0.905878,1.15289,-0.0280379,-0.0321332,-0.049432,0.00375796,0.00445846,0.00847661,0.0564895,0.0642455,0.0922434,0.01685,0.0192797,0.0288311,0.00140249,0.00164738,0.00305523,0.00350978,0.00399097,0.00565992,-0.00117689,-0.00136764,-0.0023512,-0.0128261,-0.0144728,-0.0192246,0.695336,0.837426,1.08271,0.0308742,0.0368234,0.055224,0.033174,0.0375408,0.03591,-0.104026,-0.121797,-0.147061,0.0146549,0.0173656,0.0244975,-0.00727788,-0.00791685,-0.0056617,0.0120507,0.0138782,0.0153342,0.0123751,0.0140502,0.0137217,-0.0211581,-0.0245563,-0.0257718,0.877124,1.02161,1.16481,-0.0684846,-0.0650189,0.0251456,0.0096301,0.0138409,0.0262876,0.0485916,0.0610279,0.0370116,-0.0156082,-0.0177392,-0.00665419,-0.00264647,-0.00342661,-0.00611495,-0.00461286,-0.00314202,0.00624165,-0.00277253,-0.00332328,-0.00339605,-0.0155121,-0.0190861,-0.0101088,0.91486,1.06989,1.19793,-0.0851337,-0.0845644,0.02115,0.00901208,0.0133143,0.0266004,0.0243628,0.0268754,0.0128542,-0.00675792,-0.00750487,-0.00502111,-0.00406886,-0.00512902,-0.00839534,-0.00918973,-0.00858381,0.00302648,-0.00125849,-0.00137378,-0.00105449,-0.0148914,-0.0178989,-0.0092571,0.953136,1.11033,1.23406,-0.100694,-0.100172,0.0110752,-0.00527114,0.00022744,0.0167638,-0.00209644,-0.00622579,-0.0071255,0.00177008,0.00338115,0.00390325,0.00156287,0.000339934,-0.00361396,-0.0105916,-0.0105381,0.00081086,0.00647031,0.00883374,0.00597584,-0.0110174,-0.0137496,-0.00613509,0.988172,1.13728,1.26008,-0.10505,-0.0991978,0.0128321,-0.0331341,-0.0200358,0.00112783,-0.0304282,-0.036114,-0.0342535,0.00351721,0.00552477,0.00567639,0.00506319,0.000445131,-0.00444959,-0.00806675,-0.0101662,-0.000817681,0.0154816,0.0185283,0.0166877,-0.00251635,-0.00405367,0.00490305,0.944056,1.0922,1.23312,-0.0922936,-0.085015,0.0200408,-0.00899499,0.00706017,0.0239636,-0.0218138,-0.020836,-0.0000722143,0.00646877,0.00612676,0.000582521,0.000420311,-0.0051952,-0.00955475,-0.00840949,-0.012898,-0.00487024,0.00369612,0.00322544,0.000808726,-0.0113631,-0.0111548,0.00235255,0.863897,1.01873,1.2434,-0.0286589,-0.025542,0.00994951,-0.000115797,0.00755906,0.0158063,-0.0341589,-0.0281363,0.0146362,0.0148235,0.0134276,-0.00398204,-0.000603064,-0.00265636,-0.00475719,-0.00596523,-0.00733859,-0.00198121,0.000324777,-0.00308022,-0.00625096,0.00221806,0.000978004,-0.00230261,0.801064,0.957013,1.21371,0.0132136,0.0188958,0.0376622,0.0150169,0.0176719,0.0223798,-0.00692051,-0.0115019,-0.0294645,0.00280356,0.00492909,0.0129876,-0.00717696,-0.00834586,-0.0102222,0.000731553,0.00150048,0.00619813,0.00493368,0.00584414,0.00767243,0.0032895,0.00385793,0.00393073,0.912074,1.06857,1.28606,-0.0740565,-0.0690693,-0.0141793,-0.0413218,-0.0378098,-0.0217234,0.00544679,0.00495039,-0.0205431,-0.00240233,-0.00283428,0.00943565,0.0201095,0.0186916,0.0112198,0.000743638,0.00105727,0.0094167,0.000666506,0.00151681,0.00513208,-0.0151773,-0.0148513,-0.0043675,0.882884,1.03664,1.22645,-0.0514453,-0.0466198,0.0287866,-0.017649,-0.012954,0.0117156,0.0238189,0.0218652,0.00744775,-0.0111645,-0.0110208,-0.00535929,0.00724667,0.00571634,-0.00556024,-0.00638765,-0.00551473,0.00465982,-0.00572083,-0.00474701,-0.0031946,-0.00840912,-0.0101784,0.00221703,0.898186,1.05494,1.24645,-0.0676156,-0.0636747,0.0138878,-0.0196475,-0.0159528,0.00729721,0.0111818,0.010212,0.0084344,-0.00548298,-0.0045947,-0.0033445,0.0101634,0.00850275,-0.00293877,-0.00833373,-0.007559,0.00328909,-0.00347703,-0.00241568,-0.00224135,-0.0137342,-0.0147847,0.0000587122,0.907059,1.05847,1.25414,-0.0762591,-0.0665889,0.00853857,-0.0276272,-0.0183533,0.00593633,-0.00724954,-0.010019,0.00190714,0.00335538,0.00531336,0.000513299,0.0142605,0.00904357,-0.0027387,-0.00812971,-0.00883234,0.00100745,0.000631304,0.00193804,-0.000464372,-0.0170317,-0.0148846,0.00101726,0.899372,1.0509,1.25916,-0.0674725,-0.0572437,0.00680962,-0.0241002,-0.0154133,0.00027373,-0.0251604,-0.023038,-0.000284962,0.012646,0.0117727,0.0014574,0.011997,0.00680489,-0.000699143,-0.00670065,-0.00692882,0.0030167,0.00567654,0.00459235,0.00132002,-0.0140124,-0.0113872,0.0017522,0.870105,1.02548,1.2561,-0.0366427,-0.0309832,0.00887319,-0.0159666,-0.0109508,0.00201017,-0.0336542,-0.0283596,0.00338349,0.0163688,0.0140592,-0.00116871,0.00749481,0.00503139,-0.00104936,-0.00555684,-0.00525644,0.0019108,0.0065933,0.00451922,-0.0000765998,-0.00108742,-0.000951656,0.00253503,0.789868,0.949537,1.21631,-0.00911252,-0.0104758,-0.0165453,0.0241234,0.0274545,0.0392661,-0.0181919,-0.0208268,-0.0317287,-0.00366167,-0.00420053,-0.00692165,0.00528928,0.00604637,0.00908243,-0.00492692,-0.00552825,-0.00698758,0.0095642,0.0108941,0.0158683,-0.00355553,-0.00406198,-0.00605875,0.758728,0.913711,1.15937,-0.022514,-0.0260741,-0.0437304,0.0507225,0.0579777,0.0867384,-0.00370833,-0.00425517,-0.00660255,0.0000729396,0.000111922,0.000143064,0.013602,0.0156822,0.025356,-0.0112788,-0.0127476,-0.0172895,0.00181162,0.00204164,0.00268343,-0.00490572,-0.00552338,-0.00716079,0.758728,0.913711,1.15937,-0.022514,-0.0260741,-0.0437304,0.0507225,0.0579777,0.0867384,-0.00370833,-0.00425517,-0.00660255,0.0000729396,0.000111922,0.000143064,0.013602,0.0156822,0.025356,-0.0112788,-0.0127476,-0.0172895,0.00181162,0.00204164,0.00268343,-0.00490572,-0.00552338,-0.00716079,0.75425,0.908644,1.15245,-0.0228776,-0.0264855,-0.0442923,0.0518791,0.0592863,0.0885259,0.00131852,0.00143235,0.00116621,0.000369316,0.000447251,0.000601101,0.0136702,0.0157593,0.0254614,-0.010215,-0.011544,-0.0156455,0.000868765,0.000974867,0.0012263,-0.00694381,-0.00782933,-0.0103106,0.758728,0.913711,1.15937,-0.0225948,-0.0261656,-0.0438552,0.0493339,0.0564066,0.0845925,0.00581088,0.00651513,0.00810895,0.000575321,0.000680332,0.000919473,0.0135535,0.0156273,0.025281,-0.010557,-0.0119309,-0.016174,-0.000985346,-0.00112293,-0.00163915,-0.00531401,-0.00598533,-0.00779178,0.755849,0.91041,1.15562,-0.0226727,-0.0262549,-0.0439569,0.0523576,0.0598737,0.0885384,0.00719001,0.00809654,0.00990879,0.000602426,0.000711411,0.000954845,0.0136129,0.0156954,0.0253585,-0.0117495,-0.0132983,-0.0177302,-0.00203722,-0.00232907,-0.00301189,-0.00555313,-0.00625952,-0.00810385,0.796241,0.956665,1.22493,-0.0068611,-0.00796482,-0.0136065,0.0152788,0.0176076,0.027977,0.0179561,0.0205238,0.0308504,0.00392171,0.00455279,0.00737316,0.00355315,0.00412452,0.00703021,-0.000793993,-0.000942731,-0.00194683,-0.007531,-0.00862594,-0.0131979,-0.00471064,-0.00533534,-0.00734516,0.810671,0.9705,1.2309,0.00230774,0.0035619,0.0153705,0.0113564,0.0148536,0.0281815,0.0000261672,-0.00205918,-0.0186128,0.000173623,0.000707025,0.0068509,-0.00210021,-0.00274359,-0.00723294,-0.00570316,-0.00660273,-0.00598361,0.00188374,0.00311903,0.00969843,0.00160369,0.00147089,-0.000489016,0.851496,1.01076,1.23803,-0.0198486,-0.0187504,0.0171311,-0.0242301,-0.0203952,0.0170042,0.0033784,0.00334097,-0.00939571,-0.000553066,-0.000402888,0.00407701,0.00990815,0.00949257,-0.00634728,0.00348777,0.00259674,0.000215638,-0.00243173,-0.00272841,0.00258347,-0.00374276,-0.00400345,-0.000366706,0.86431,1.02369,1.24052,-0.0276295,-0.0268353,0.0135241,-0.0339443,-0.0306862,0.0153175,0.00921155,0.00821092,0.000581694,-0.0000475147,0.000412101,0.00328457,0.0148959,0.0146892,-0.00392417,0.00455744,0.00420803,0.000168181,-0.00557249,-0.00522193,-0.00288633,-0.00152255,-0.00242483,0.0000476273,0.86978,1.03018,1.24099,-0.0291664,-0.0285757,0.0132993,-0.0378841,-0.0352322,0.0148327,-0.00293681,-0.00419331,-0.00685286,0.00185436,0.00234016,0.00421894,0.0156146,0.0154856,-0.00380518,0.00512249,0.0046417,0.000163596,0.000904187,0.00149173,0.00189669,-0.000445809,-0.00102386,0.0000143418,0.875709,1.0358,1.2533,-0.0294543,-0.0285464,0.011731,-0.0469037,-0.0433947,0.00254374,-0.00681098,-0.00749945,-0.00432852,0.00260773,0.00309396,0.00391281,0.0163641,0.0159229,-0.00273635,0.0105257,0.00929809,0.00475459,0.00226914,0.00269874,0.000749171,-0.00157446,-0.00172881,0.00120342,0.86098,1.01799,1.24046,-0.0243427,-0.0226503,0.0146166,-0.0331145,-0.0262667,0.0167977,-0.0115728,-0.0113697,-0.00309225,0.00422961,0.00453422,0.00360396,0.0131573,0.0121329,-0.00502543,0.00613397,0.00346769,-0.00158971,0.00477561,0.00447611,-0.000173306,-0.00231652,-0.00242758,0.00131404,0.846173,1.0062,1.26434,-0.00969531,-0.00884849,0.00227676,-0.0166774,-0.0129655,0.00441221,-0.0224543,-0.0204405,-0.00307156,0.00536066,0.00518383,-0.0000022086,0.0044124,0.00375427,-0.00167365,-0.0004839,-0.00165263,-0.00300421,0.00981069,0.00845144,0.000377497,0.00506132,0.004663,0.00203809,0.821468,0.980117,1.24193,0.00298811,0.00602617,0.0196807,0.00225578,0.00518339,0.016166,0.0102584,0.00690256,-0.00745617,-0.00266511,-0.00151252,0.004697,-0.00296691,-0.00428599,-0.00911382,-0.00230023,-0.00194187,-0.000226552,-0.00271811,-0.00153836,0.00341521,0.00575563,0.00550131,0.00502971,0.862897,1.02408,1.26142,-0.0336285,-0.0325215,0.0021291,-0.0269994,-0.0254681,0.00132177,0.00978804,0.00880725,-0.00654088,-0.00408357,-0.0040218,0.00242431,0.0139969,0.0134724,-0.000268068,0.00034865,0.000525963,0.00160136,-0.00348023,-0.0033488,0.00262763,-0.00616212,-0.00670878,-0.000979832,0.870092,1.03275,1.26089,-0.0383655,-0.0381292,0.00428608,-0.0311363,-0.0302113,0.00244691,0.0047874,0.00629419,0.00122913,-0.00198377,-0.00244111,-0.000504493,0.015349,0.0151998,-0.00160393,0.000317928,0.000245612,0.00105968,-0.00143026,-0.00214413,0.00000493385,-0.0068378,-0.00721979,0.000273647,0.879958,1.03786,1.25926,-0.0446263,-0.0421809,0.00398593,-0.0362355,-0.0310928,0.00359163,0.00161115,0.000444121,0.00150944,-0.0000880058,0.000601692,0.0000878106,0.0176923,0.0160232,-0.00161248,-0.000228465,-0.00131053,0.00089924,-0.00173354,-0.000735432,0.000155206,-0.00618544,-0.00674788,-0.000655871,0.863949,1.02182,1.25183,-0.0358987,-0.0327076,0.00853402,-0.0245211,-0.0188141,0.011031,-0.00900985,-0.00911438,0.0017813,0.00452902,0.00479628,0.000362512,0.0133438,0.0110096,-0.00483938,-0.00179453,-0.00350896,-0.00150763,0.00261201,0.00285737,-0.000164386,-0.00652501,-0.00617361,0.000650005,0.859522,1.01651,1.25595,-0.0315602,-0.0278863,0.00589069,-0.0231244,-0.0167404,0.00749477,-0.013986,-0.0122725,0.0038006,0.0073597,0.00683745,-0.000605512,0.0122038,0.00961937,-0.00319946,-0.000699175,-0.00250754,-0.000714679,0.0045953,0.00366231,-0.00142353,-0.00565166,-0.00532555,0.00029033,0.846839,1.00918,1.2593,-0.0200197,-0.0192563,0.00376689,-0.0128674,-0.0113459,0.0053999,-0.0175228,-0.0169074,0.00323455,0.00842656,0.00827265,-0.000726324,0.00680173,0.00620661,-0.00207971,-0.00284099,-0.0032521,-0.000642953,0.00524263,0.00476047,-0.0016963,-0.000856329,-0.000812317,0.000127704]}diff --git a/fixtures/scenes/lightmap-atlas.png b/fixtures/scenes/lightmap-atlas.pngindex c80791256..d08fe4e30 100644Binary files a/fixtures/scenes/lightmap-atlas.png and b/fixtures/scenes/lightmap-atlas.png differdiff --git a/fixtures/scenes/lightmap-model.esscene b/fixtures/scenes/lightmap-model.esscenenew file mode 100644index 000000000..aeca48650--- /dev/null+++ b/fixtures/scenes/lightmap-model.esscene@@ -0,0 +1,195 @@+{+ "version": 4,+ "name": "LightmapModel",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 10+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "Sun",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 1,+ "color": {+ "r": 0,+ "g": 1,+ "b": 0,+ "a": 1+ },+ "intensity": 1,+ "direction": {+ "x": 0,+ "y": 0+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Baked",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -50,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 0.5,+ "y": 0.5,+ "z": 1+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "layer": 0,+ "enabled": true,+ "lit": true,+ "mesh": "/scenes/lightmap-quad-lit.esmesh"+ }+ },+ {+ "type": "MeshLightmap",+ "data": {+ "lightmap": "@uuid:bbbbbbbb-1111-2222-3333-555555555555",+ "scaleOffset": {+ "x": 1,+ "y": 1,+ "z": 0,+ "w": 0+ }+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Unbaked",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 50,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 0.5,+ "y": 0.5,+ "z": 1+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "layer": 0,+ "enabled": true,+ "lit": true,+ "mesh": "/scenes/lightmap-quad-lit.esmesh"+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "Sky",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 2,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "intensity": 1,+ "environment": "/scenes/studio.esenv",+ "enabled": true+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/lightmap-model.textures.json b/fixtures/scenes/lightmap-model.textures.jsonnew file mode 100644index 000000000..867ac6dd6--- /dev/null+++ b/fixtures/scenes/lightmap-model.textures.json@@ -0,0 +1,3 @@+{+ "bbbbbbbb-1111-2222-3333-555555555555": "/scenes/lightmap-atlas.png"+}\ No newline at end of filediff --git a/fixtures/scenes/lightmap-model/rough.esmaterial b/fixtures/scenes/lightmap-model/rough.esmaterialnew file mode 100644index 000000000..972e581bc--- /dev/null+++ b/fixtures/scenes/lightmap-model/rough.esmaterial@@ -0,0 +1,17 @@+{+ "version": "1.0",+ "type": "material",+ "shader": "builtin:model",+ "blendMode": 0,+ "depthTest": false,+ "properties": {+ "u_metallic": 0,+ "u_roughness": 1,+ "u_tint": {+ "r": 0.5,+ "g": 1,+ "b": 1,+ "a": 1+ }+ }+}diff --git a/fixtures/scenes/lightmap-quad-lit.esmesh b/fixtures/scenes/lightmap-quad-lit.esmeshnew file mode 100644index 000000000..7bad6194dBinary files /dev/null and b/fixtures/scenes/lightmap-quad-lit.esmesh differdiff --git a/fixtures/scenes/lightmap-sky.esscene b/fixtures/scenes/lightmap-sky.esscenenew file mode 100644index 000000000..101586b0b--- /dev/null+++ b/fixtures/scenes/lightmap-sky.esscene@@ -0,0 +1,194 @@+{+ "version": 4,+ "name": "LightmapSky",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 10+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 1,+ "orthoSize": 100,+ "isActive": true,+ "priority": 0+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "Sun",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 1,+ "color": {+ "r": 0,+ "g": 1,+ "b": 0,+ "a": 1+ },+ "intensity": 1,+ "direction": {+ "x": 0,+ "y": 0+ },+ "enabled": true+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Baked",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -50,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 0.5,+ "y": 0.5,+ "z": 1+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "layer": 0,+ "enabled": true,+ "lit": true,+ "mesh": "/scenes/lightmap-quad.esmesh"+ }+ },+ {+ "type": "MeshLightmap",+ "data": {+ "lightmap": "@uuid:bbbbbbbb-1111-2222-3333-555555555555",+ "scaleOffset": {+ "x": 1,+ "y": 1,+ "z": 0,+ "w": 0+ }+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Unbaked",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 50,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 0.5,+ "y": 0.5,+ "z": 1+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "layer": 0,+ "enabled": true,+ "lit": true,+ "mesh": "/scenes/lightmap-quad.esmesh"+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "Sky",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 2,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "intensity": 1,+ "enabled": true+ }+ }+ ]+ }+ ]+}diff --git a/fixtures/scenes/lightmap-sky.textures.json b/fixtures/scenes/lightmap-sky.textures.jsonnew file mode 100644index 000000000..867ac6dd6--- /dev/null+++ b/fixtures/scenes/lightmap-sky.textures.json@@ -0,0 +1,3 @@+{+ "bbbbbbbb-1111-2222-3333-555555555555": "/scenes/lightmap-atlas.png"+}\ No newline at end of filediff --git a/fixtures/scenes/mat-builtin-lit/lit.esshader b/fixtures/scenes/mat-builtin-lit/lit.esshaderindex 4e59fb3a1..ddb8e4223 100644--- a/fixtures/scenes/mat-builtin-lit/lit.esshader+++ b/fixtures/scenes/mat-builtin-lit/lit.esshader@@ -27,7 +27,7 @@ void main() {// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.// Regenerate after changing the GLSL stages above.// source-hash: 5330079245724fa2-// assembled-hash: 4f341ebfcf19c1f8+// assembled-hash: 759bd2a723036353struct FrameConstants {u_projection: mat4x4<f32>,u_camera: vec4<f32>,diff --git a/fixtures/scenes/mat-generated-mesh/split.esshader b/fixtures/scenes/mat-generated-mesh/split.esshaderindex 12ce2ed44..ac416c954 100644--- a/fixtures/scenes/mat-generated-mesh/split.esshader+++ b/fixtures/scenes/mat-generated-mesh/split.esshader@@ -22,7 +22,7 @@ void main() {// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.// Regenerate after changing the GLSL stages above.// source-hash: 7af6948ea05e1a30-// assembled-hash: db772a2e99ede0f9+// assembled-hash: 728932bdbc297d93struct MaterialConstants {u_tint: vec4<f32>,}diff --git a/fixtures/scenes/mat-lit-flatnormal/lit-fn.esshader b/fixtures/scenes/mat-lit-flatnormal/lit-fn.esshaderindex e419adcd4..a2226d254 100644--- a/fixtures/scenes/mat-lit-flatnormal/lit-fn.esshader+++ b/fixtures/scenes/mat-lit-flatnormal/lit-fn.esshader@@ -47,7 +47,7 @@ void main() {// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.// Regenerate after changing the GLSL stages above.// source-hash: a8853729e0f76d55-// assembled-hash: b3b46cf005738836+// assembled-hash: 908ff085bda9bd0fstruct gl_PerVertex {@builtin(position) gl_Position: vec4<f32>,gl_PointSize: f32,@@ -123,7 +123,7 @@ fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>,// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.// Regenerate after changing the GLSL stages above.// source-hash: a8853729e0f76d55-// assembled-hash: b3b46cf005738836+// assembled-hash: 908ff085bda9bd0fstruct FrameConstants {u_projection: mat4x4<f32>,u_camera: vec4<f32>,diff --git a/fixtures/scenes/mat-lit-normal/lit-normal.esshader b/fixtures/scenes/mat-lit-normal/lit-normal.esshaderindex c9e6dd081..b97f8d9c2 100644--- a/fixtures/scenes/mat-lit-normal/lit-normal.esshader+++ b/fixtures/scenes/mat-lit-normal/lit-normal.esshader@@ -47,7 +47,7 @@ void main() {// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.// Regenerate after changing the GLSL stages above.// source-hash: 577c1ff7b66006ff-// assembled-hash: 5f7a9a4e82a4b110+// assembled-hash: fc9c7d326f081ea8struct gl_PerVertex {@builtin(position) gl_Position: vec4<f32>,gl_PointSize: f32,@@ -123,7 +123,7 @@ fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>,// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.// Regenerate after changing the GLSL stages above.// source-hash: 577c1ff7b66006ff-// assembled-hash: 5f7a9a4e82a4b110+// assembled-hash: fc9c7d326f081ea8struct FrameConstants {u_projection: mat4x4<f32>,u_camera: vec4<f32>,diff --git a/fixtures/scenes/mat-lit/lit.esshader b/fixtures/scenes/mat-lit/lit.esshaderindex 2fd42f9d7..fdf3d0730 100644--- a/fixtures/scenes/mat-lit/lit.esshader+++ b/fixtures/scenes/mat-lit/lit.esshader@@ -53,7 +53,7 @@ void main() {// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.// Regenerate after changing the GLSL stages above.// source-hash: 8c118f2b442c055e-// assembled-hash: f57668e95653c702+// assembled-hash: a113166d45747bc5struct gl_PerVertex {@builtin(position) gl_Position: vec4<f32>,gl_PointSize: f32,@@ -125,7 +125,7 @@ fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>,// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.// Regenerate after changing the GLSL stages above.// source-hash: 8c118f2b442c055e-// assembled-hash: f57668e95653c702+// assembled-hash: a113166d45747bc5struct FrameConstants {u_projection: mat4x4<f32>,u_camera: vec4<f32>,diff --git a/fixtures/scenes/reflection-room_lightmap.png b/fixtures/scenes/reflection-room_lightmap.pngindex eaa81e0c9..89c8d297f 100644Binary files a/fixtures/scenes/reflection-room_lightmap.png and b/fixtures/scenes/reflection-room_lightmap.png differdiff --git a/fixtures/scenes/reflection-room_reflections.png b/fixtures/scenes/reflection-room_reflections.pngindex 952833dba..03753e82f 100644Binary files a/fixtures/scenes/reflection-room_reflections.png and b/fixtures/scenes/reflection-room_reflections.png differdiff --git a/pipeline/bin/estella.mjs b/pipeline/bin/estella.mjsindex 3a981025e..78974e6c1 100644--- a/pipeline/bin/estella.mjs+++ b/pipeline/bin/estella.mjs@@ -15,7 +15,7 @@ const REPO = path.join(PIPELINE, '..');const USAGE = `usage: node pipeline/bin/estella.mjs export <projectDir> [options]node pipeline/bin/estella.mjs import-model <file.gltf|file.glb|file.fbx> [outDir][--project <dir>] [--scale <n>]- [--specular-map color|orm]+ [--specular-map color|orm] [--lightmap-uv]node pipeline/bin/estella.mjs import-hdr <file.hdr> [outDir] [--face-size <n>]node pipeline/bin/estella.mjs bake-scene <scene.esscene> [--check]@@ -59,6 +59,8 @@ otherwise; --scale sizes the model, whose metres are world units otherwise.--specular-map orm reads an FBX's specular map as packed occlusion/roughness/metalness (Falcor-era scenes such as Bistro); the source's own \`.meta\` settingis used when the flag is absent. DDS images are converted to PNG on the way in.+--lightmap-uv gives every mesh a lightmap UV set (Generate Lightmap UVs in the+editor), unwrapping one where the source's second set is too sparse to bake into.import-hdr bakes an equirectangular panorama into the two things a renderer asksan environment for: nine irradiance coefficients (in the \`.esenv\`) and one@@ -91,6 +93,7 @@ function parseArgs(argv) {const scale = rest.indexOf('--scale');const faceSize = rest.indexOf('--face-size');const specular = rest.indexOf('--specular-map');+ const lightmapUV = rest.includes('--lightmap-uv');const out = rest[0] && !rest[0].startsWith('--') ? path.resolve(rest[0]) : null;return {command, out, source: path.resolve(projectDir),@@ -98,6 +101,7 @@ function parseArgs(argv) {scale: scale >= 0 ? Number(rest[scale + 1]) || 1 : 1,faceSize: faceSize >= 0 ? Number(rest[faceSize + 1]) || undefined : undefined,specularMap: specular >= 0 ? rest[specular + 1] : undefined,+ lightmapUV,};}if (command !== 'export' || !projectDir) {@@ -274,6 +278,8 @@ async function bakeScene(baker, meta, sceneFile, check) {const body = bakeComponent(entity, 'RigidBody3D');const textureRef = typeof mesh.data?.texture === 'string' ? mesh.data.texture : '';const textureFile = resolveRef(textureRef);+ const materialRef = typeof mesh.data?.material === 'string' ? mesh.data.material : '';+ const materialFile = resolveRef(materialRef);const transform = bakeTransformOf(baker, entity);const holdsStill = baker.bakeHoldsStill({characterController: !!bakeComponent(entity, 'CharacterController3D'),@@ -283,10 +289,15 @@ async function bakeScene(baker, meta, sceneFile, check) {surfaces.push({entity: entity.id, label: entity.name ?? String(entity.id),meshFile: file, builtinRef: builtin, transform,- baseColor: albedo, holdsStill,+ baseColor: albedo, holdsStill, realtimeDirect: mesh.data?.lit === true,+ twoSided: mesh.data?.cullBackfaces === false,+ material: materialFile && existsSync(materialFile) ? materialFile : undefined,baseColorTexture: textureFile && existsSync(textureFile) ? textureFile : undefined,});- fingerprintSurfaces.push({ mesh: ref, transform, albedo, texture: textureRef, holdsStill });+ fingerprintSurfaces.push({ mesh: ref, transform, albedo, texture: textureRef, holdsStill,+ realtimeDirect: mesh.data?.lit === true,+ twoSided: mesh.data?.cullBackfaces === false,+ material: materialRef || undefined });}}const reflection = bakeComponent(entity, 'ReflectionProbe');@@ -299,6 +310,7 @@ async function bakeScene(baker, meta, sceneFile, check) {if (!environment && typeof light.data?.environment === 'string'&& light.data.environment !== '') {environment = readEnvironment(light.data.environment);+ if (environment) environment.rotation = light.data.environmentRotation ?? 0;}const p = bakeVec(tf.position, BAKE_ZERO);const made = baker.bakeLightOf(light.data, [p.x, p.y, p.z],@@ -571,6 +583,16 @@ function specularMapFor(opts) {}}+/** The flag, else the source's own `.meta` import setting — the editor's door reads the same one. */+function lightmapUVFor(opts) {+ if (opts.lightmapUV) return true;+ try {+ return JSON.parse(readFileSync(`${opts.source}.meta`, 'utf8')).importer?.lightmapUV === true;+ } catch {+ return false;+ }+}+function findProjectRoot(from) {for (let dir = from, prev = ''; dir !== prev; prev = dir, dir = path.dirname(dir)) {if (PROJECT_FILES.some((name) => existsSync(path.join(dir, name)))) return dir;@@ -648,6 +670,7 @@ if (opts.command === 'import-model' || opts.command === 'import-gltf') {specularMap: specularMapFor(opts),},);+ if (lightmapUVFor(opts)) warnings.push(...importer.applyLightmapUV(meshes));for (const w of warnings) console.warn(` ! ${w}`);if (!root && meshes.length > 0) {console.warn(' ! no project found above the source — refs are bare file names'diff --git a/pipeline/src/assets/lightmapBake.ts b/pipeline/src/assets/lightmapBake.tsindex 85e2f5ec5..32f59a0be 100644--- a/pipeline/src/assets/lightmapBake.ts+++ b/pipeline/src/assets/lightmapBake.ts@@ -14,7 +14,7 @@ import { bakeLightmap, decodeMesh, unwrapLightmapUV, builtinMeshTemplate, MeshChtype MeshData, type BakeSurface, type BakeLight, type BakeOptions,type CapturedPanorama, type ProbeGrid } from 'esengine';import { encodeRgbaPng } from './png';-import { bakeSceneReflections, bakeSky, type BakeEnvironment,+import { bakeSceneReflections, bakeSky, irradianceSky, type BakeEnvironment,type ReflectionBakeResult } from './reflectionBake';// What a collector needs to describe a surface, re-exported so the CLI reaches@@ -48,6 +48,14 @@ export interface SceneBakeSurface {* takes a probe volume's light instead of an atlas patch, because a bake* writes light into a place and this one will not be there. Absent = yes. */holdsStill?: boolean;+ /** True where the renderer is `lit`: the frame adds the lamps to it, so its+ * patch holds only the indirect light. */+ realtimeDirect?: boolean;+ /** The renderer draws both faces (`cullBackfaces` off). */+ twoSided?: boolean;+ /** Absolute path of the `.esmaterial` it draws with, whose alpha cutoff says+ * how much of it a ray finds there. */+ material?: string;}/** One box of probes to solve, as the editor's world describes it. */@@ -155,18 +163,48 @@ function toLinear(v: number): number {return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;}-/** A texture's mean colour in linear light, or null when it cannot be read. */-function averageOf(file: string): [number, number, number] | null {+/** A texture as a bake reads it: its mean colour in linear light, and the share+ * of it a cutout keeps. */+interface TextureStats {+ mean: [number, number, number];+ coverage: number;+}++/**+ * The texels past `cutoff` (all of them without one), averaged — the holes of a+ * cutout are not a colour the surface has — and how many of them there are.+ */+function statsOf(file: string, cutoff: number): TextureStats | null {const png = PNG.sync.read(readFileSync(file));- let r = 0, g = 0, b = 0;+ let r = 0, g = 0, b = 0, kept = 0;const pixels = png.width * png.height;if (pixels === 0) return null;+ const floor = cutoff > 0 ? cutoff * 255 : -1;for (let i = 0; i < pixels; i++) {+ if (png.data[i * 4 + 3] < floor) continue;r += toLinear(png.data[i * 4]);g += toLinear(png.data[i * 4 + 1]);b += toLinear(png.data[i * 4 + 2]);+ kept++;+ }+ if (kept === 0) return { mean: [0, 0, 0], coverage: 0 };+ return { mean: [r / kept, g / kept, b / kept], coverage: kept / pixels };+}++/** The alpha cutoff a material document states, or 0. */+function cutoffOf(materialFile: string | undefined, cache: Map<string, number>): number {+ if (!materialFile) return 0;+ if (!cache.has(materialFile)) {+ let cutoff = 0;+ try {+ const doc = JSON.parse(readFileSync(materialFile, 'utf8')) as+ { properties?: { u_alphaCutoff?: unknown } };+ const v = doc.properties?.u_alphaCutoff;+ if (typeof v === 'number' && v > 0) cutoff = v;+ } catch { /* a material this cannot read cuts nothing */ }+ cache.set(materialFile, cutoff);}- return [r / pixels, g / pixels, b / pixels];+ return cache.get(materialFile)!;}/**@@ -176,28 +214,30 @@ function averageOf(file: string): [number, number, number] | null {* bounce that used only one would drop the colour whenever the other held it.* A surface with neither reflects a neutral grey, which is a guess, so it says so.*/-function albedoOf(s: SceneBakeSurface, cache: Map<string, [number, number, number] | null>,- warnings: string[]): [number, number, number] | undefined {+function albedoOf(s: SceneBakeSurface, cutoff: number, cache: Map<string, TextureStats | null>,+ warnings: string[]): { albedo?: [number, number, number]; coverage: number } {const factor = s.baseColor;if (!s.baseColorTexture) {if (!factor) {warnings.push(`${s.label}: no base colour, so light bounces off it as neutral grey`);}- return factor;+ return { albedo: factor, coverage: 1 };}- if (!cache.has(s.baseColorTexture)) {+ const key = `${s.baseColorTexture}|${cutoff}`;+ if (!cache.has(key)) {try {- cache.set(s.baseColorTexture, averageOf(s.baseColorTexture));+ cache.set(key, statsOf(s.baseColorTexture, cutoff));} catch {- cache.set(s.baseColorTexture, null);+ cache.set(key, null);warnings.push(`${s.label}: its base colour texture could not be read, so light`+ ' bounces off it by its colour factor alone');}}- const mean = cache.get(s.baseColorTexture) ?? null;- if (!mean) return factor;+ const stats = cache.get(key) ?? null;+ if (!stats) return { albedo: factor, coverage: 1 };const f = factor ?? [1, 1, 1];- return [mean[0] * f[0], mean[1] * f[1], mean[2] * f[2]];+ return { albedo: [stats.mean[0] * f[0], stats.mean[1] * f[1], stats.mean[2] * f[2]],+ coverage: cutoff > 0 ? stats.coverage : 1 };}/**@@ -214,7 +254,8 @@ export function bakeSceneLightmap(input: SceneBakeInput): SceneBakeResult {let moving = 0;// One decode per texture however many objects share it: a bake reads these// once and a scene reuses the same few across most of its surfaces.- const averages = new Map<string, [number, number, number] | null>();+ const averages = new Map<string, TextureStats | null>();+ const cutoffs = new Map<string, number>();// Stock geometry is rebuilt from code every run, so its lightmap UVs are// DERIVED here rather than being an asset: unwrapping an imported mesh// rewrites a file the scene already references, and this rewrites nothing.@@ -244,7 +285,9 @@ export function bakeSceneLightmap(input: SceneBakeInput): SceneBakeResult {continue;}slot.push(i);- surfaces.push({ mesh, transform: s.transform, albedo: albedoOf(s, averages, warnings) });+ const { albedo, coverage } = albedoOf(s, cutoffOf(s.material, cutoffs), averages, warnings);+ surfaces.push({ mesh, transform: s.transform, albedo, coverage, label: s.label,+ realtimeDirect: s.realtimeDirect, twoSided: s.twoSided });}// The volumes, turned from what an author asked for into the grids a solve@@ -283,6 +326,7 @@ export function bakeSceneLightmap(input: SceneBakeInput): SceneBakeResult {const reflectionOptions = {reflectionProbes: reflectionProbes.map((p) => p.center),reflectionSky: bakeSky(input.environment, ambient),+ sky: irradianceSky(input.environment, ambient),};const packReflections = (panoramas: CapturedPanorama[]): ReflectionBakeResult | null => {if (reflectionProbes.length === 0) return null;@@ -314,6 +358,14 @@ export function bakeSceneLightmap(input: SceneBakeInput): SceneBakeResult {const result = bakeLightmap(surfaces, input.lights,{ ...input.options, probeGrids: grids, ...reflectionOptions });+ result.shared.forEach((share, k) => {+ if (share > 0.25) {+ warnings.push(`${surfaces[k]!.label ?? `surface ${k}`}: its lightmap UVs lay`+ + ` ${Math.round(share * 100)}% of its texels over one another, so those parts share`+ + ' one texel\'s light — turn on Generate Lightmap UVs in its model\'s import settings'+ + ' and reimport');+ }+ });const scaleOffset: Array<[number, number, number, number] | null> =input.surfaces.map(() => null);slot.forEach((at, k) => { scaleOffset[at] = result.scaleOffset[k]; });diff --git a/pipeline/src/assets/modelImport.ts b/pipeline/src/assets/modelImport.tsindex d8b8db0c2..12cb425d7 100644--- a/pipeline/src/assets/modelImport.ts+++ b/pipeline/src/assets/modelImport.ts@@ -16,6 +16,7 @@ import {type MeshData, type MaterialAssetData, type PrefabData, type PrefabEntityData,type PrefabComponentData as ComponentData,} from 'esengine';+import { SPARSE_LIGHTMAP_UV, OVERLAPPING_LIGHTMAP_UV } from '../../../sdk/src/lightmap/atlas';/** One primitive's worth of geometry, named for the file it will be written to. */export interface ImportedMesh {@@ -326,11 +327,51 @@ export function animationProductName(stem: string, name: string): string {/* -- Products ----------------------------------------------------------- */+/** Cells per side of the grid a lightmap UV set is judged on. */+const LAYOUT_GRID = 256;++/**+ * How a mesh's TexCoord1 triangles sit in their square: the share of it they+ * cover, and how many layers deep they lie on themselves (1 = none overlap).+ * Counted on one grid for both, so a sliver that misses every cell centre+ * weighs on neither. Zero coverage without the channel.+ */+export function lightmapUVLayout(data: ImportedMesh['data']): { coverage: number; overlap: number } {+ const channel = data.channels.find((c) => c.semantic === MeshChannel.TexCoord1);+ if (!channel) return { coverage: 0, overlap: 1 };+ const view = new DataView(data.vertices.buffer, data.vertices.byteOffset, data.vertices.byteLength);+ const G = LAYOUT_GRID;+ const u = (v: number) => view.getFloat32(v * data.vertexStride + channel.offset, true) * G;+ const w = (v: number) => view.getFloat32(v * data.vertexStride + channel.offset + 4, true) * G;+ const cells = new Uint8Array(G * G);+ let hits = 0, covered = 0;+ const idx = data.indices;+ for (let i = 0; i + 2 < idx.length; i += 3) {+ const x = [u(idx[i]!), u(idx[i + 1]!), u(idx[i + 2]!)];+ const y = [w(idx[i]!), w(idx[i + 1]!), w(idx[i + 2]!)];+ const area = (x[1]! - x[0]!) * (y[2]! - y[0]!) - (x[2]! - x[0]!) * (y[1]! - y[0]!);+ if (Math.abs(area) < 1e-12) continue;+ const x0 = Math.max(0, Math.floor(Math.min(...x))), x1 = Math.min(G - 1, Math.ceil(Math.max(...x)));+ const y0 = Math.max(0, Math.floor(Math.min(...y))), y1 = Math.min(G - 1, Math.ceil(Math.max(...y)));+ for (let cy = y0; cy <= y1; cy++) {+ for (let cx = x0; cx <= x1; cx++) {+ const px = cx + 0.5, py = cy + 0.5;+ const w0 = ((x[1]! - px) * (y[2]! - py) - (x[2]! - px) * (y[1]! - py)) / area;+ const w1 = ((x[2]! - px) * (y[0]! - py) - (x[0]! - px) * (y[2]! - py)) / area;+ if (w0 < 0 || w1 < 0 || w0 + w1 > 1) continue;+ hits++;+ if (cells[cy * G + cx] === 0) { cells[cy * G + cx] = 1; covered++; }+ }+ }+ }+ return { coverage: covered / (G * G), overlap: covered > 0 ? hits / covered : 1 };+}+/*** Gives every mesh a bake can be read on a lightmap UV set, and says who it* skipped. Mutates in place: the caller holds the products it is about to write.* Skinned is skipped because bones move it and a bake cannot follow; one that- * already carries the channel keeps a layout its art may be painted against.+ * already carries a usable layout keeps it, since its art may be painted against it.*/export function applyLightmapUV(meshes: ImportedMesh[]): string[] {const warnings: string[] = [];@@ -341,8 +382,17 @@ export function applyLightmapUV(meshes: ImportedMesh[]): string[] {continue;}if (mesh.data.channels.some((c) => c.semantic === MeshChannel.TexCoord1)) {- warnings.push(`${mesh.name}: already carries a second UV set, which is kept`);- continue;+ const { coverage, overlap } = lightmapUVLayout(mesh.data);+ if (overlap > OVERLAPPING_LIGHTMAP_UV) {+ warnings.push(`${mesh.name}: its second UV set lies ${overlap.toFixed(1)} layers deep on`+ + ' itself, so parts of it would share light — a lightmap UV is unwrapped in its place');+ } else if (coverage < SPARSE_LIGHTMAP_UV) {+ warnings.push(`${mesh.name}: its second UV set covers ${(coverage * 100).toFixed(1)}% of its`+ + ' square, too little to bake into — a lightmap UV is unwrapped in its place');+ } else {+ warnings.push(`${mesh.name}: already carries a second UV set, which is kept`);+ continue;+ }}try {const { mesh: unwrapped, charts, coverage } = unwrapLightmapUV(mesh.data);diff --git a/pipeline/src/assets/reflectionBake.ts b/pipeline/src/assets/reflectionBake.tsindex 6234f1c8a..3b5af75ad 100644--- a/pipeline/src/assets/reflectionBake.ts+++ b/pipeline/src/assets/reflectionBake.ts@@ -13,7 +13,7 @@* carries which column an object reflects as a number per instance, and* a hundred shiny things in a room still merge into one draw.*/-import { type CapturedPanorama, flatSky, type SkyRadiance } from 'esengine';+import { type CapturedPanorama, flatSky, evalIrradianceSH, SH_COSINE_BAND, type SkyRadiance } from 'esengine';import { atlasLayout, decodeRgbm, mipCountFor, octEncode, prefilterOctahedral,type EnvironmentAssetData } from './environmentImport';import { encodeRgbaPng } from './png';@@ -25,6 +25,8 @@ export interface BakeEnvironment {document: EnvironmentAssetData;/** The atlas PNG it names. */atlasPng: Uint8Array;+ /** The ambient light's `environmentRotation`, in degrees about +Y. */+ rotation?: number;}export interface ReflectionBakeInput {@@ -85,6 +87,26 @@ export function environmentSky(environment: BakeEnvironment): SkyRadiance | null};}+/**+ * The sky a lumel or a probe gathers: radiance whose cosine-weighted mean over an+ * open hemisphere is the environment's irradiance as the frame reads it. Not the+ * reflection atlas, which clips the HDR sun that is most of a sunny sky.+ */+export function irradianceSky(environment: BakeEnvironment | null | undefined,+ ambient: readonly [number, number, number]): SkyRadiance {+ const sh = environment?.document.irradiance;+ if (!environment || !Array.isArray(sh) || sh.length < 27) return flatSky(ambient);+ const radiance = Float32Array.from(sh.slice(0, 27), (v, i) => v / SH_COSINE_BAND[Math.floor(i / 3)]!);+ const yaw = -((environment.rotation ?? 0) * Math.PI) / 180;+ const c = Math.cos(yaw), s = Math.sin(yaw);+ return (dx, dy, dz, out, at) => {+ const [r, g, b] = evalIrradianceSH(radiance, c * dx + s * dz, dy, -s * dx + c * dz);+ out[at] = Math.max(0, r) * ambient[0];+ out[at + 1] = Math.max(0, g) * ambient[1];+ out[at + 2] = Math.max(0, b) * ambient[2];+ };+}+/** The sky a capture should use: the environment's own where there is one. */export function bakeSky(environment: BakeEnvironment | null | undefined,ambient: readonly [number, number, number]): SkyRadiance {diff --git a/pipeline/tests/lightmap-bake.test.ts b/pipeline/tests/lightmap-bake.test.tsindex 83f457d40..cff482c80 100644--- a/pipeline/tests/lightmap-bake.test.ts+++ b/pipeline/tests/lightmap-bake.test.ts@@ -11,10 +11,11 @@ import { describe, it, expect, beforeAll, afterAll } from 'vitest';import { mkdtemp, rm, writeFile } from 'node:fs/promises';import { tmpdir } from 'node:os';import path from 'node:path';-import { encodeMesh, unwrapLightmapUV, MeshChannel, MeshChannelType,+import { encodeMesh, unwrapLightmapUV, decodeLightmap, MeshChannel, MeshChannelType,type MeshData, type BakeLight } from 'esengine';import { bakeSceneLightmap, type SceneBakeSurface } from '../src/assets/lightmapBake';import { encodeRgbaPng } from '../src/assets/png';+import { decodeRgbaPng } from '../src/assets/tilesetExtrude';let dir = '';@@ -57,6 +58,25 @@ beforeAll(async () => {const half = new Uint8Array(4 * 4 * 4).fill(255);for (let i = 8; i < 16; i++) { half[i * 4] = 0; half[i * 4 + 1] = 0; half[i * 4 + 2] = 0; }await writeFile(path.join(dir, 'half.png'), encodeRgbaPng(4, 4, half));+ // Half of it there and half a hole, as a leaf card is.+ const holes = new Uint8Array(4 * 4 * 4).fill(255);+ for (let i = 8; i < 16; i++) holes[i * 4 + 3] = 0;+ await writeFile(path.join(dir, 'holes.png'), encodeRgbaPng(4, 4, holes));+ await writeFile(path.join(dir, 'roof.esmesh'), encodeMesh(unwrapLightmapUV(floor(1)).mesh));+ // The same quad twice over, the second copy laid on the first's lightmap UVs.+ const one = unwrapLightmapUV(floor(2)).mesh;+ const doubled = new Uint8Array(one.vertices.length * 2);+ doubled.set(one.vertices, 0);+ doubled.set(one.vertices, one.vertices.length);+ const dv = new DataView(doubled.buffer);+ const pos = one.channels.find((c) => c.semantic === MeshChannel.Position)!;+ for (let i = one.vertexCount; i < one.vertexCount * 2; i++) {+ dv.setFloat32(i * one.vertexStride + pos.offset, dv.getFloat32(i * one.vertexStride + pos.offset, true) + 10, true);+ }+ await writeFile(path.join(dir, 'stacked.esmesh'), encodeMesh({ ...one, vertices: doubled, vertexCount: one.vertexCount * 2,+ indices: Uint32Array.from([...one.indices, ...Array.from(one.indices, (v) => v + one.vertexCount)]) }));+ await writeFile(path.join(dir, 'cutout.esmaterial'), JSON.stringify(+ { version: '1.0', type: 'material', shader: 'builtin:model', properties: { u_alphaCutoff: 0.5 } }));});afterAll(async () => {@@ -171,6 +191,46 @@ describe('baking a scene', () => {expect(result.warnings.join(' ')).toContain('neutral grey');});+ it('lets the sky through a cutout by the share of it that is a hole', () => {+ // The floor's patch as a whole, under a roof that is solid, half holes, or+ // gone: a leaf card is the second, and baked as the first it walls in+ // everything under it.+ const under = (roof: Partial<SceneBakeSurface> | null): number => {+ const result = bakeSceneLightmap({+ surfaces: [surface('unwrapped.esmesh', 'Floor'),+ ...(roof ? [{ ...surface('roof.esmesh', 'Roof'),+ transform: [...IDENTITY.slice(0, 12), 0, 0.5, 0, 1],+ baseColorTexture: path.join(dir, 'holes.png'), ...roof }] : [])],+ lights: [], options: { ...SMALL, samples: 128, ambient: [1, 1, 1] },+ });+ const image = decodeRgbaPng(result.atlasBytes);+ const [su, sv, ou, ov] = result.scaleOffset[0]!;+ let sum = 0;+ for (let y = Math.floor(ov * image.width); y < Math.ceil((ov + sv) * image.width); y++) {+ for (let x = Math.floor(ou * image.width); x < Math.ceil((ou + su) * image.width); x++) {+ sum += decodeLightmap(image.rgba, y * image.width + x)[0];+ }+ }+ return sum;+ };+ const solid = under({});+ const cut = under({ material: path.join(dir, 'cutout.esmaterial') });+ const open = under(null);+ expect(solid).toBeLessThan(open * 0.95);+ expect(cut).toBeGreaterThan(solid + (open - solid) * 0.3);+ expect(cut).toBeLessThan(solid + (open - solid) * 0.7);+ });++ it('names a surface whose lightmap UVs lie on themselves', () => {+ const result = bakeSceneLightmap({+ surfaces: [surface('unwrapped.esmesh', 'Floor'), surface('stacked.esmesh', 'Curb', 20)],+ lights: LAMP, options: SMALL,+ });+ expect(result.warnings.filter((w) => w.includes('over one another'))).toEqual([+ expect.stringMatching(/^Curb: its lightmap UVs lay \d+% of its texels over one another/),+ ]);+ });+it('writes a PNG the editor can adopt as an asset', () => {const result = bakeSceneLightmap({surfaces: [surface('unwrapped.esmesh', 'Floor')], lights: LAMP, options: SMALL,diff --git a/pipeline/tests/lightmap-sky.test.ts b/pipeline/tests/lightmap-sky.test.tsnew file mode 100644index 000000000..cc10191fd--- /dev/null+++ b/pipeline/tests/lightmap-sky.test.ts@@ -0,0 +1,91 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * The claim: where nothing stands in the way, a bake lit by an environment gives+ * a surface what the frame would have given it — the same nine coefficients,+ * turned and tinted the same way — so baking changes only what is covered.+ */+import { describe, it, expect } from 'vitest';+import { bakeLightmap, unwrapLightmapUV, decodeLightmap, evalIrradianceSH,+ MeshChannel, MeshChannelType, type MeshData } from 'esengine';+import { irradianceSky, type BakeEnvironment } from '../src/assets/reflectionBake';++const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];++/** A quad facing `n`, spanning the two axes it does not face along. */+function quad(n: [number, number, number]): MeshData {+ const axis = n.findIndex((v) => v !== 0);+ const [u, v] = [0, 1, 2].filter((k) => k !== axis);+ const corners = [[-1, -1], [1, -1], [1, 1], [-1, 1]];+ const stride = 24;+ const vertices = new Uint8Array(4 * stride);+ const view = new DataView(vertices.buffer);+ corners.forEach(([a, b], i) => {+ const p = [0, 0, 0];+ p[u] = a; p[v] = b;+ for (let k = 0; k < 3; k++) {+ view.setFloat32(i * stride + k * 4, p[k], true);+ view.setFloat32(i * stride + 12 + k * 4, n[k], true);+ }+ });+ // Wound so the face's own normal agrees with the declared one.+ const cross = (u + 1) % 3 === v ? n[axis] > 0 : n[axis] < 0;+ return unwrapLightmapUV({+ channels: [+ { semantic: MeshChannel.Position, components: 3, type: MeshChannelType.Float32, offset: 0 },+ { semantic: MeshChannel.Normal, components: 3, type: MeshChannelType.Float32, offset: 12 },+ ],+ vertexStride: stride, vertexCount: 4, vertices,+ indices: Uint32Array.from(cross ? [0, 1, 2, 0, 2, 3] : [0, 2, 1, 0, 3, 2]),+ aabbMin: [-1, -1, -1], aabbMax: [1, 1, 1],+ }).mesh;+}++/** Brighter overhead and toward +X, and positive everywhere so no clamp bends it. */+const IRRADIANCE = [+ 2.0, 1.8, 1.5,+ 0.4, 0.4, 0.4,+ 0, 0, 0,+ 0.3, 0.2, 0.1,+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+];+const TINT: [number, number, number] = [1.2, 1, 0.8];++function environment(rotation: number): BakeEnvironment {+ return {+ document: { version: 1, irradiance: IRRADIANCE } as BakeEnvironment['document'],+ atlasPng: new Uint8Array(), rotation,+ };+}++/** What the frame's shader reads at world normal `n`: envDirection, then shIrradiance. */+function frameReads(n: [number, number, number], rotation: number): number[] {+ const a = -(rotation * Math.PI) / 180;+ const c = Math.cos(a), s = Math.sin(a);+ const d = [c * n[0] + s * n[2], n[1], -s * n[0] + c * n[2]];+ return evalIrradianceSH(IRRADIANCE, d[0]!, d[1]!, d[2]!).map((v, k) => v * TINT[k]!);+}++function baked(n: [number, number, number], rotation: number): number[] {+ const result = bakeLightmap([{ mesh: quad(n), transform: IDENTITY }], [], {+ atlasSize: 64, texelsPerUnit: 8, bounces: 0, samples: 256, dilate: 0,+ sky: irradianceSky(environment(rotation), TINT),+ });+ const [su, sv, ou, ov] = result.scaleOffset[0]!;+ const x = Math.floor((ou + su / 2) * result.size);+ const y = Math.floor((ov + sv / 2) * result.size);+ return decodeLightmap(result.pixels, y * result.size + x);+}++describe('an environment, baked', () => {+ for (const [name, n] of [['a floor', [0, 1, 0]], ['a wall facing +X', [1, 0, 0]],+ ['a wall facing -Z', [0, 0, -1]]] as const) {+ for (const rotation of [0, 90]) {+ it(`gives ${name} what the frame reads there, turned ${rotation} degrees`, () => {+ const want = frameReads(n as [number, number, number], rotation);+ const got = baked(n as [number, number, number], rotation);+ for (let k = 0; k < 3; k++) expect(got[k]).toBeCloseTo(want[k]!, 1);+ });+ }+ }+});diff --git a/pipeline/tests/lightmap-uv.test.ts b/pipeline/tests/lightmap-uv.test.tsnew file mode 100644index 000000000..97a08319d--- /dev/null+++ b/pipeline/tests/lightmap-uv.test.ts@@ -0,0 +1,76 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file A model's own second UV set is kept as its lightmap layout only where a+ * bake could use it.+ */+import { describe, it, expect } from 'vitest';+import { MeshChannel, MeshChannelType, unwrapLightmapUV, type MeshData } from 'esengine';+import { applyLightmapUV, lightmapUVLayout, type ImportedMesh } from '../src/assets/modelImport';++function floor(half: number): MeshData {+ const p = [[-half, 0, -half], [half, 0, -half], [half, 0, half], [-half, 0, half]];+ const vertices = new Uint8Array(p.length * 12);+ const view = new DataView(vertices.buffer);+ p.forEach((q, i) => q.forEach((v, k) => view.setFloat32(i * 12 + k * 4, v, true)));+ return {+ channels: [{ semantic: MeshChannel.Position, components: 3, type: MeshChannelType.Float32, offset: 0 }],+ vertexStride: 12, vertexCount: 4, vertices,+ indices: Uint32Array.from([0, 2, 1, 0, 3, 2]),+ aabbMin: [-half, 0, -half], aabbMax: [half, 0, half],+ };+}++/** A mesh whose second UV set sits in a sliver of its square, as ORCA Bistro's road does. */+function sparse(): MeshData {+ const mesh = unwrapLightmapUV(floor(10)).mesh;+ const uv1 = mesh.channels.find((c) => c.semantic === MeshChannel.TexCoord1)!;+ const view = new DataView(mesh.vertices.buffer, mesh.vertices.byteOffset);+ for (let i = 0; i < mesh.vertexCount; i++) {+ for (let k = 0; k < 2; k++) {+ const at = i * mesh.vertexStride + uv1.offset + k * 4;+ view.setFloat32(at, view.getFloat32(at, true) * 0.1, true);+ }+ }+ return mesh;+}++/** Two quads laid over the same UVs, as a curb repeated along a street shares one strip. */+function stacked(): MeshData {+ const one = unwrapLightmapUV(floor(10)).mesh;+ const vertices = new Uint8Array(one.vertices.length * 2);+ vertices.set(one.vertices, 0);+ vertices.set(one.vertices, one.vertices.length);+ const view = new DataView(vertices.buffer);+ const pos = one.channels.find((c) => c.semantic === MeshChannel.Position)!;+ for (let i = one.vertexCount; i < one.vertexCount * 2; i++) {+ const at = i * one.vertexStride + pos.offset;+ view.setFloat32(at, view.getFloat32(at, true) + 30, true);+ }+ const indices = Uint32Array.from([...one.indices, ...Array.from(one.indices, (v) => v + one.vertexCount)]);+ return { ...one, vertices, vertexCount: one.vertexCount * 2, indices };+}++const imported = (name: string, data: MeshData): ImportedMesh =>+ ({ name, data, vertexCount: data.vertexCount, triangleCount: data.indices.length / 3 });++describe('a source\'s own lightmap UVs', () => {+ it('are kept where they cover their square, and unwrapped over where they do not', () => {+ const good = imported('Square', unwrapLightmapUV(floor(10)).mesh);+ const road = imported('Road', sparse());+ expect(lightmapUVLayout(road.data).coverage).toBeLessThan(0.05);++ const warnings = applyLightmapUV([good, road]);+ expect(warnings).toContain('Square: already carries a second UV set, which is kept');+ expect(warnings.find((w) => w.startsWith('Road:'))).toMatch(/covers \d\.\d% of its square.*unwrapped in its place/);+ expect(lightmapUVLayout(road.data).coverage).toBeGreaterThan(0.05);+ });++ it('are unwrapped over where they lie on themselves', () => {+ const curb = imported('Curb', stacked());+ expect(lightmapUVLayout(curb.data).overlap).toBeGreaterThan(1.9);+ const warnings = applyLightmapUV([curb]);+ expect(warnings.find((w) => w.startsWith('Curb:'))).toMatch(/2\.0 layers deep.*unwrapped in its place/);+ expect(lightmapUVLayout(curb.data).overlap).toBeLessThan(1.1);+ });+});diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex def1cf5bd..b2f06af46 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -1,7 +1,7 @@# API surface — esengine/index<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 91 beta · 1513 experimental · 3 deprecated+Symbols: 115 public · 91 beta · 1516 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -1390,7 +1390,7 @@ ambient: readonly [number, number, number] | undefinedlights: readonly BakeLight[]options: BakeOptions | undefinedreflections: readonly (readonly [number, number, number])[] | undefined-surfaces: readonly { mesh: string; transform: ArrayLike<number>; albedo?: readonly [number, number, number]; texture?: string; holdsStill?: boolean; }[]+surfaces: readonly { mesh: string; transform: ArrayLike<number>; albedo?: readonly [number, number, number]; texture?: string; holdsStill?: boolean; realtimeDirect?: boolean; twoSided?: boolean; material?: string; }[]volumes: readonly { center: readonly [number, number, number]; halfExtents: readonly [number, number, number]; spacing: number; }[]```@@ -1430,6 +1430,7 @@ reflectionProbes: readonly (readonly [number, number, number])[] | undefinedreflectionSky: SkyRadiance | undefinedreflectionWidth: number | undefinedsamples: number | undefined+sky: SkyRadiance | undefinedtexelsPerUnit: number | undefined```@@ -1440,14 +1441,19 @@ pixels: Uint8Array<ArrayBufferLike>probes: Float32Array<ArrayBufferLike>[]reflections: CapturedPanorama[]scaleOffset: [number, number, number, number][]+shared: Float32Array<ArrayBufferLike>size: number```## BakeSurface — interface @experimental```albedo: readonly [number, number, number] | undefined+coverage: number | undefined+label: string | undefinedmesh: MeshData+realtimeDirect: boolean | undefinedtransform: ArrayLike<number>+twoSided: boolean | undefined```## BakedLighting — const @experimental@@ -4414,6 +4420,11 @@ static new (opts?: KineticScrollOptions): KineticScrollstatic prototype: KineticScroll```+## LIGHTMAP_RANGE — const @experimental+```+8+```+## LIGHT_FORWARD — const @experimental```Readonly<Vec3>@@ -10516,6 +10527,11 @@ Plugin(src: ImageBitmapSource): Promise<DecodedPixels>```+## decodeLightmap — function @experimental+```+(pixels: ArrayLike<number>, i: number): [number, number, number]+```+## decodeMesh — function @experimental```(bytes: Uint8Array): MeshData@@ -10741,6 +10757,11 @@ DragPlugin(channels: MeshChannelDesc[]): Uint8Array```+## encodeLightmap — function @experimental+```+(rgb: Float32Array, count: number): Uint8Array+```+## encodeMesh — function @experimental```(data: MeshData): Uint8Arraydiff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 9f4955f38..a9b99503e 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.native<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 96 beta · 1532 experimental · 3 deprecated+Symbols: 115 public · 96 beta · 1535 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -1390,7 +1390,7 @@ ambient: readonly [number, number, number] | undefinedlights: readonly BakeLight[]options: BakeOptions | undefinedreflections: readonly (readonly [number, number, number])[] | undefined-surfaces: readonly { mesh: string; transform: ArrayLike<number>; albedo?: readonly [number, number, number]; texture?: string; holdsStill?: boolean; }[]+surfaces: readonly { mesh: string; transform: ArrayLike<number>; albedo?: readonly [number, number, number]; texture?: string; holdsStill?: boolean; realtimeDirect?: boolean; twoSided?: boolean; material?: string; }[]volumes: readonly { center: readonly [number, number, number]; halfExtents: readonly [number, number, number]; spacing: number; }[]```@@ -1430,6 +1430,7 @@ reflectionProbes: readonly (readonly [number, number, number])[] | undefinedreflectionSky: SkyRadiance | undefinedreflectionWidth: number | undefinedsamples: number | undefined+sky: SkyRadiance | undefinedtexelsPerUnit: number | undefined```@@ -1440,14 +1441,19 @@ pixels: Uint8Array<ArrayBufferLike>probes: Float32Array<ArrayBufferLike>[]reflections: CapturedPanorama[]scaleOffset: [number, number, number, number][]+shared: Float32Array<ArrayBufferLike>size: number```## BakeSurface — interface @experimental```albedo: readonly [number, number, number] | undefined+coverage: number | undefined+label: string | undefinedmesh: MeshData+realtimeDirect: boolean | undefinedtransform: ArrayLike<number>+twoSided: boolean | undefined```## BakedLighting — const @experimental@@ -4422,6 +4428,11 @@ static new (opts?: KineticScrollOptions): KineticScrollstatic prototype: KineticScroll```+## LIGHTMAP_RANGE — const @experimental+```+8+```+## LIGHT_FORWARD — const @experimental```Readonly<Vec3>@@ -10757,6 +10768,11 @@ Plugin(src: ImageBitmapSource): Promise<DecodedPixels>```+## decodeLightmap — function @experimental+```+(pixels: ArrayLike<number>, i: number): [number, number, number]+```+## decodeMesh — function @experimental```(bytes: Uint8Array): MeshData@@ -10982,6 +10998,11 @@ DragPlugin(channels: MeshChannelDesc[]): Uint8Array```+## encodeLightmap — function @experimental+```+(rgb: Float32Array, count: number): Uint8Array+```+## encodeMesh — function @experimental```(data: MeshData): Uint8Arraydiff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex aa870af26..b47fd1038 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.node<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 93 beta · 1512 experimental · 3 deprecated+Symbols: 115 public · 93 beta · 1515 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -1385,7 +1385,7 @@ ambient: readonly [number, number, number] | undefinedlights: readonly BakeLight[]options: BakeOptions | undefinedreflections: readonly (readonly [number, number, number])[] | undefined-surfaces: readonly { mesh: string; transform: ArrayLike<number>; albedo?: readonly [number, number, number]; texture?: string; holdsStill?: boolean; }[]+surfaces: readonly { mesh: string; transform: ArrayLike<number>; albedo?: readonly [number, number, number]; texture?: string; holdsStill?: boolean; realtimeDirect?: boolean; twoSided?: boolean; material?: string; }[]volumes: readonly { center: readonly [number, number, number]; halfExtents: readonly [number, number, number]; spacing: number; }[]```@@ -1425,6 +1425,7 @@ reflectionProbes: readonly (readonly [number, number, number])[] | undefinedreflectionSky: SkyRadiance | undefinedreflectionWidth: number | undefinedsamples: number | undefined+sky: SkyRadiance | undefinedtexelsPerUnit: number | undefined```@@ -1435,14 +1436,19 @@ pixels: Uint8Array<ArrayBufferLike>probes: Float32Array<ArrayBufferLike>[]reflections: CapturedPanorama[]scaleOffset: [number, number, number, number][]+shared: Float32Array<ArrayBufferLike>size: number```## BakeSurface — interface @experimental```albedo: readonly [number, number, number] | undefined+coverage: number | undefined+label: string | undefinedmesh: MeshData+realtimeDirect: boolean | undefinedtransform: ArrayLike<number>+twoSided: boolean | undefined```## BakedLighting — const @experimental@@ -4409,6 +4415,11 @@ static new (opts?: KineticScrollOptions): KineticScrollstatic prototype: KineticScroll```+## LIGHTMAP_RANGE — const @experimental+```+8+```+## LIGHT_FORWARD — const @experimental```Readonly<Vec3>@@ -10511,6 +10522,11 @@ Plugin(src: ImageBitmapSource): Promise<DecodedPixels>```+## decodeLightmap — function @experimental+```+(pixels: ArrayLike<number>, i: number): [number, number, number]+```+## decodeMesh — function @experimental```(bytes: Uint8Array): MeshData@@ -10736,6 +10752,11 @@ DragPlugin(channels: MeshChannelDesc[]): Uint8Array```+## encodeLightmap — function @experimental+```+(rgb: Float32Array, count: number): Uint8Array+```+## encodeMesh — function @experimental```(data: MeshData): Uint8Arraydiff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex 1b8157ef5..24c8eee3b 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -1,7 +1,7 @@# API surface — esengine/minigame<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 91 beta · 1534 experimental · 3 deprecated+Symbols: 115 public · 91 beta · 1537 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -1385,7 +1385,7 @@ ambient: readonly [number, number, number] | undefinedlights: readonly BakeLight[]options: BakeOptions | undefinedreflections: readonly (readonly [number, number, number])[] | undefined-surfaces: readonly { mesh: string; transform: ArrayLike<number>; albedo?: readonly [number, number, number]; texture?: string; holdsStill?: boolean; }[]+surfaces: readonly { mesh: string; transform: ArrayLike<number>; albedo?: readonly [number, number, number]; texture?: string; holdsStill?: boolean; realtimeDirect?: boolean; twoSided?: boolean; material?: string; }[]volumes: readonly { center: readonly [number, number, number]; halfExtents: readonly [number, number, number]; spacing: number; }[]```@@ -1425,6 +1425,7 @@ reflectionProbes: readonly (readonly [number, number, number])[] | undefinedreflectionSky: SkyRadiance | undefinedreflectionWidth: number | undefinedsamples: number | undefined+sky: SkyRadiance | undefinedtexelsPerUnit: number | undefined```@@ -1435,14 +1436,19 @@ pixels: Uint8Array<ArrayBufferLike>probes: Float32Array<ArrayBufferLike>[]reflections: CapturedPanorama[]scaleOffset: [number, number, number, number][]+shared: Float32Array<ArrayBufferLike>size: number```## BakeSurface — interface @experimental```albedo: readonly [number, number, number] | undefined+coverage: number | undefined+label: string | undefinedmesh: MeshData+realtimeDirect: boolean | undefinedtransform: ArrayLike<number>+twoSided: boolean | undefined```## BakedLighting — const @experimental@@ -4409,6 +4415,11 @@ static new (opts?: KineticScrollOptions): KineticScrollstatic prototype: KineticScroll```+## LIGHTMAP_RANGE — const @experimental+```+8+```+## LIGHT_FORWARD — const @experimental```Readonly<Vec3>@@ -10792,6 +10803,11 @@ Plugin(src: ImageBitmapSource): Promise<DecodedPixels>```+## decodeLightmap — function @experimental+```+(pixels: ArrayLike<number>, i: number): [number, number, number]+```+## decodeMesh — function @experimental```(bytes: Uint8Array): MeshData@@ -11017,6 +11033,11 @@ DragPlugin(channels: MeshChannelDesc[]): Uint8Array```+## encodeLightmap — function @experimental+```+(rgb: Float32Array, count: number): Uint8Array+```+## encodeMesh — function @experimental```(data: MeshData): Uint8Arraydiff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex d48f41682..e6b1b8869 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -1,7 +1,7 @@# API surface — esengine/wechat<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 91 beta · 1525 experimental · 3 deprecated+Symbols: 115 public · 91 beta · 1528 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -1385,7 +1385,7 @@ ambient: readonly [number, number, number] | undefinedlights: readonly BakeLight[]options: BakeOptions | undefinedreflections: readonly (readonly [number, number, number])[] | undefined-surfaces: readonly { mesh: string; transform: ArrayLike<number>; albedo?: readonly [number, number, number]; texture?: string; holdsStill?: boolean; }[]+surfaces: readonly { mesh: string; transform: ArrayLike<number>; albedo?: readonly [number, number, number]; texture?: string; holdsStill?: boolean; realtimeDirect?: boolean; twoSided?: boolean; material?: string; }[]volumes: readonly { center: readonly [number, number, number]; halfExtents: readonly [number, number, number]; spacing: number; }[]```@@ -1425,6 +1425,7 @@ reflectionProbes: readonly (readonly [number, number, number])[] | undefinedreflectionSky: SkyRadiance | undefinedreflectionWidth: number | undefinedsamples: number | undefined+sky: SkyRadiance | undefinedtexelsPerUnit: number | undefined```@@ -1435,14 +1436,19 @@ pixels: Uint8Array<ArrayBufferLike>probes: Float32Array<ArrayBufferLike>[]reflections: CapturedPanorama[]scaleOffset: [number, number, number, number][]+shared: Float32Array<ArrayBufferLike>size: number```## BakeSurface — interface @experimental```albedo: readonly [number, number, number] | undefined+coverage: number | undefined+label: string | undefinedmesh: MeshData+realtimeDirect: boolean | undefinedtransform: ArrayLike<number>+twoSided: boolean | undefined```## BakedLighting — const @experimental@@ -4416,6 +4422,11 @@ static new (opts?: KineticScrollOptions): KineticScrollstatic prototype: KineticScroll```+## LIGHTMAP_RANGE — const @experimental+```+8+```+## LIGHT_FORWARD — const @experimental```Readonly<Vec3>@@ -10542,6 +10553,11 @@ Plugin(src: ImageBitmapSource): Promise<DecodedPixels>```+## decodeLightmap — function @experimental+```+(pixels: ArrayLike<number>, i: number): [number, number, number]+```+## decodeMesh — function @experimental```(bytes: Uint8Array): MeshData@@ -10767,6 +10783,11 @@ DragPlugin(channels: MeshChannelDesc[]): Uint8Array```+## encodeLightmap — function @experimental+```+(rgb: Float32Array, count: number): Uint8Array+```+## encodeMesh — function @experimental```(data: MeshData): Uint8Arraydiff --git a/sdk/src/core-content.ts b/sdk/src/core-content.tsindex 55c9887ad..e5dab32d8 100644--- a/sdk/src/core-content.ts+++ b/sdk/src/core-content.ts@@ -156,6 +156,7 @@ export {bakeLightmap, type BakeOptions, type BakeResult, type BakeSurface, type BakeLight,type ProbeGrid, bakeHoldsStill, type BakeMobility, BAKE_DEFAULTS,captureReflection, flatSky, type CapturedPanorama, type SkyRadiance,+ LIGHTMAP_RANGE, encodeLightmap, decodeLightmap,} from './lightmap';/*** What a scene declares about its baked light: the knobs, and the fingerprint ofdiff --git a/sdk/src/lightmap/atlas.ts b/sdk/src/lightmap/atlas.tsindex 2f6c8ac25..6413cc147 100644--- a/sdk/src/lightmap/atlas.ts+++ b/sdk/src/lightmap/atlas.ts@@ -20,6 +20,16 @@ export interface BakeSurface {/** What fraction of each channel the surface reflects. Drives the bounce;* a surface that reflects nothing still receives light. */albedo?: readonly [number, number, number];+ /** What to call it when a bake has something to say about it. */+ label?: string;+ /** True when its draw adds the lamps itself (a lit renderer): its patch then+ * holds only what arrives indirectly, or the lamps would land twice. */+ realtimeDirect?: boolean;+ /** Drawn with both faces: a ray arriving at its back finds it lit, not black. */+ twoSided?: boolean;+ /** Share of its area that is there — for a cutout, the texels past its cutoff.+ * Rays pass the rest, so foliage shades what is under it without walling it in. */+ coverage?: number;}/** Texels of one object's patch, and where in the atlas it sits. */@@ -44,6 +54,8 @@ export interface LumelField {texel: Int32Array;/** Which surface each lumel belongs to. */surface: Int32Array;+ /** Per surface: the share of its triangles' texels another of its own already held. */+ shared: Float32Array;}const chan = (m: MeshData, s: number): MeshChannelDesc | undefined =>@@ -99,6 +111,37 @@ function areasOf(surface: BakeSurface): { world: number; uv: number } {return { world, uv };}+/**+ * Below this share of its unit square, a lightmap UV set is too sparse to bake+ * into: a patch holds the whole square, so ORCA Bistro's road, 3533 m² in 0.5%+ * of it, asked for more atlas than the rest of the town together.+ */+export const SPARSE_LIGHTMAP_UV = 0.05;++/**+ * Above this many layers of a lightmap UV set lying on itself, parts of the mesh+ * would share texels and so share light: a curb laid over its own UVs eighty+ * times over took whatever its first triangle saw, underside included.+ */+export const OVERLAPPING_LIGHTMAP_UV = 1.1;++/**+ * The patch each surface asks for, and how much of its lightmap UV square its+ * triangles cover: a patch holds the whole square, so a sparse layout pays for+ * the empty rest.+ */+export function atlasDemand(surfaces: readonly BakeSurface[], size: number,+ texelsPerUnit: number): { side: number; uvCoverage: number }[] {+ return surfaces.map((s) => {+ const { world, uv } = areasOf(s);+ if (world <= 0 || uv <= 0) return { side: 1, uvCoverage: uv };+ // The unwrap kept one ratio inside the mesh; this is what that ratio is,+ // and it says how many texels a patch needs to hit the density asked for.+ const side = texelsPerUnit / Math.sqrt(uv / world);+ return { side: Math.max(2, Math.min(size, Math.ceil(side))), uvCoverage: uv };+ });+}+/*** Gives every surface a patch of an `size`-by-`size` atlas at `texelsPerUnit`.*@@ -108,14 +151,7 @@ function areasOf(surface: BakeSurface): { world: number; uv: number } {*/export function layoutAtlas(surfaces: readonly BakeSurface[], size: number,texelsPerUnit: number): SurfacePatch[] | null {- const sides = surfaces.map((s) => {- const { world, uv } = areasOf(s);- if (world <= 0 || uv <= 0) return 1;- // The unwrap kept one ratio inside the mesh; this is what that ratio is,- // and it says how many texels a patch needs to hit the density asked for.- const side = texelsPerUnit / Math.sqrt(uv / world);- return Math.max(2, Math.min(size, Math.ceil(side)));- });+ const sides = atlasDemand(surfaces, size, texelsPerUnit).map((d) => d.side);const placed = packSkyline(sides.map((s) => [s, s] as const), size);if (!placed) return null;return sides.map((side, i) => ({@@ -141,6 +177,7 @@ export function rasterizeLumels(surfaces: readonly BakeSurface[],const texel: number[] = [];const owner: number[] = [];const seen = new Set<number>();+ const shared = new Float32Array(surfaces.length);const p = new Float32Array(9);const n = new Float32Array(9);@@ -154,6 +191,7 @@ export function rasterizeLumels(surfaces: readonly BakeSurface[],const read = reader(surface.mesh);const idx = surface.mesh.indices;const hasNormals = chan(surface.mesh, MeshChannel.Normal) !== undefined;+ let claimed = 0, taken = 0;for (let i = 0; i + 2 < idx.length; i += 3) {let ok = true;for (let k = 0; k < 3 && ok; k++) {@@ -199,7 +237,8 @@ export function rasterizeLumels(surfaces: readonly BakeSurface[],const w2 = 1 - w0 - w1;if (w0 < 0 || w1 < 0 || w2 < 0) continue;const at = y * size + x;- if (seen.has(at)) continue;+ claimed++;+ if (seen.has(at)) { taken++; continue; }seen.add(at);for (let k = 0; k < 3; k++) {position.push(w0 * wp[k] + w1 * wp[3 + k] + w2 * wp[6 + k]);@@ -215,6 +254,7 @@ export function rasterizeLumels(surfaces: readonly BakeSurface[],}}}+ shared[s] = claimed > 0 ? taken / claimed : 0;}return {@@ -223,5 +263,6 @@ export function rasterizeLumels(surfaces: readonly BakeSurface[],normal: Float32Array.from(normal),texel: Int32Array.from(texel),surface: Int32Array.from(owner),+ shared,};}diff --git a/sdk/src/lightmap/bake.ts b/sdk/src/lightmap/bake.tsindex 5bf2f3dd5..4a7c18df3 100644--- a/sdk/src/lightmap/bake.ts+++ b/sdk/src/lightmap/bake.ts@@ -11,8 +11,10 @@import { MeshChannel, MeshChannelType, type MeshData, type MeshChannelDesc } from '../asset/meshFormat';import { Bvh, type TriangleSoup } from './bvh';-import { layoutAtlas, rasterizeLumels, type BakeSurface, type SurfacePatch } from './atlas';-import { solveDirect, solveBounce, type BakeLight, type HitLookup } from './solve';+import {+ layoutAtlas, rasterizeLumels, atlasDemand, SPARSE_LIGHTMAP_UV, type BakeSurface, type SurfacePatch,+} from './atlas';+import { solveDirect, solveGather, type BakeLight, type HitLookup } from './solve';import { solveProbes, type ProbeGrid } from './probes';import { captureReflection, flatSky, type CapturedPanorama, type SkyRadiance }from './reflection';@@ -30,8 +32,12 @@ export interface BakeOptions {bounces?: number;/** Rays each lumel gathers per bounce. */samples?: number;- /** Light every surface receives from no direction in particular. */+ /** The sky's radiance where no {@link sky} is given: the same from every+ * direction, and still only reaching what can see it. */ambient?: readonly [number, number, number];+ /** What a lumel or a probe receives along a ray that escapes the scene — the+ * environment as the frame lights by it, tint and turn included. */+ sky?: SkyRadiance;/** Texels the solved edges are smeared outwards, so a bilinear tap near a* chart's border does not read the empty atlas beside it. */dilate?: number;@@ -55,13 +61,16 @@ export interface BakeOptions {}export interface BakeResult {- /** RGBA8, `atlasSize * atlasSize * 4` — what a `.png` is written from. */+ /** `atlasSize * atlasSize * 4` bytes a `.png` is written from; see+ * {@link encodeLightmap}. */pixels: Uint8Array;size: number;/** What each surface's `MeshLightmap.scaleOffset` must be set to, in order. */scaleOffset: Array<[number, number, number, number]>;/** Texels the surfaces actually cover, out of the atlas. */lumels: number;+ /** Per surface: the share of its texels its own lightmap UVs laid twice. */+ shared: Float32Array;/** Nine RGB coefficients per probe, one array per requested grid, in grid* order with x varying fastest — what a `.esprobes` carries. */probes: Float32Array[];@@ -90,7 +99,7 @@ const chan = (m: MeshData, s: number): MeshChannelDesc | undefined =>/** Every surface's triangles in world space, plus what a ray hit has to know. */function collect(surfaces: readonly BakeSurface[], patches: readonly SurfacePatch[],- size: number): { soup: TriangleSoup; lookup: HitLookup } {+ size: number, texelsPerUnit: number): { soup: TriangleSoup; lookup: HitLookup } {let total = 0;for (const s of surfaces) total += Math.floor(s.mesh.indices.length / 3);const positions = new Float32Array(total * 9);@@ -99,6 +108,8 @@ function collect(surfaces: readonly BakeSurface[], patches: readonly SurfacePatcconst patch = new Float32Array(surfaces.length * 4);const albedo = new Float32Array(surfaces.length * 3);const triNormal = new Float32Array(total * 3);+ const twoSided = new Uint8Array(surfaces.length);+ const coverage = new Float32Array(surfaces.length);let at = 0;for (let s = 0; s < surfaces.length; s++) {@@ -106,6 +117,8 @@ function collect(surfaces: readonly BakeSurface[], patches: readonly SurfacePatcconst m = surfaces[s].transform;const a = surfaces[s].albedo ?? [0.5, 0.5, 0.5];albedo.set(a, s * 3);+ twoSided[s] = surfaces[s].twoSided ? 1 : 0;+ coverage[s] = Math.min(1, Math.max(0, surfaces[s].coverage ?? 1));patch[s * 4] = patches[s].x;patch[s * 4 + 1] = patches[s].y;patch[s * 4 + 2] = patches[s].side;@@ -163,7 +176,10 @@ function collect(surfaces: readonly BakeSurface[], patches: readonly SurfacePatctriNormal[at + 1] = e1[2] * e2[0] - e1[0] * e2[2];triNormal[at + 2] = e1[0] * e2[1] - e1[1] * e2[0];}- return { soup: { positions, count: total }, lookup: { triUV, triSurface, patch, albedo, triNormal } };+ return { soup: { positions, count: total },+ lookup: { triUV, triSurface, patch, albedo, triNormal, twoSided, coverage,+ cutouts: coverage.some((c) => c < 1),+ backReach: texelsPerUnit > 0 ? 0.5 / texelsPerUnit : 0 } };}/** Smears solved texels outwards so a bilinear tap near an edge reads light@@ -195,6 +211,53 @@ function dilate(radiance: Float32Array, solved: Uint8Array, size: number, rounds}}+/**+ * The most an atlas texel holds, in units of a flat ambient of one. Stored as the+ * square root of its fraction, alpha opaque: eight plain bits stop at one, and a+ * scale in alpha does not survive a premultiplying decoder. `bakedIrradiance` reads it.+ */+export const LIGHTMAP_RANGE = 8;++/** Irradiance to atlas bytes: `sqrt(v / LIGHTMAP_RANGE)` per channel, alpha 255. */+export function encodeLightmap(rgb: Float32Array, count: number): Uint8Array {+ const out = new Uint8Array(count * 4);+ for (let i = 0; i < count; i++) {+ for (let k = 0; k < 3; k++) {+ const v = Math.min(1, Math.max(0, rgb[i * 3 + k] / LIGHTMAP_RANGE));+ out[i * 4 + k] = Math.round(Math.sqrt(v) * 255);+ }+ out[i * 4 + 3] = 255;+ }+ return out;+}++/** What {@link encodeLightmap} wrote at texel `i`. */+export function decodeLightmap(pixels: ArrayLike<number>, i: number): [number, number, number] {+ const d = (b: number): number => (b / 255) * (b / 255) * LIGHTMAP_RANGE;+ return [d(pixels[i * 4]), d(pixels[i * 4 + 1]), d(pixels[i * 4 + 2])];+}++/**+ * Why the surfaces do not fit, naming the ones that take the most room: a+ * second UV set that leaves most of its square empty cannot be fixed by a+ * bigger atlas, only by unwrapping the mesh.+ */+function refusal(surfaces: readonly BakeSurface[], size: number, texelsPerUnit: number): string {+ const demand = atlasDemand(surfaces, size, texelsPerUnit)+ .map((d, i) => ({ ...d, name: surfaces[i]?.label ?? `surface ${i}` }))+ .sort((a, b) => b.side - a.side)+ .slice(0, 3);+ const named = demand.map((d) => `${d.name} (${d.side}x${d.side}, its lightmap UVs cover`+ + ` ${(d.uvCoverage * 100).toFixed(1)}%)`).join(', ');+ const sparse = demand.some((d) => d.uvCoverage < SPARSE_LIGHTMAP_UV)+ ? '; one whose lightmap UVs cover little of their square wastes the rest, which'+ + ' Generate Lightmap UVs on its model unwraps away'+ : '';+ return `bakeLightmap: ${surfaces.length} surface(s) do not fit a ${size}px atlas at`+ + ` ${texelsPerUnit} texels per unit — raise the atlas or lower the density.`+ + ` The largest: ${named}${sparse}`;+}+/*** Bakes `lights` into an atlas the surfaces can be read through.*@@ -207,74 +270,67 @@ export function bakeLightmap(surfaces: readonly BakeSurface[], lights: readonlyconst opts = { ...BAKE_DEFAULTS, ...options };const size = opts.atlasSize;const patches = layoutAtlas(surfaces, size, opts.texelsPerUnit);- if (!patches) {- throw new Error(`bakeLightmap: ${surfaces.length} surface(s) do not fit a ${size}px atlas at`- + ` ${opts.texelsPerUnit} texels per unit — raise the atlas or lower the density`);- }+ if (!patches) throw new Error(refusal(surfaces, size, opts.texelsPerUnit));const lumels = rasterizeLumels(surfaces, patches, size);- const { soup, lookup } = collect(surfaces, patches, size);+ const { soup, lookup } = collect(surfaces, patches, size, opts.texelsPerUnit);const bvh = new Bvh(soup);const direct = new Float32Array(lumels.count * 3);- solveDirect(lumels, bvh, lights, opts.ambient, direct);+ solveDirect(lumels, bvh, lookup, lights, direct);- // The atlas as each pass leaves it, so the next reads what the last wrote —- // which is what carries light one more surface along.- const radiance = new Float32Array(size * size * 3);- const solved = new Uint8Array(size * size);- const total = new Float32Array(lumels.count * 3);- total.set(direct);- let emitted = direct;- for (let bounce = 0; bounce < opts.bounces; bounce++) {- radiance.fill(0);- for (let i = 0; i < lumels.count; i++) {- const at = lumels.texel[i] * 3;- radiance[at] = emitted[i * 3];- radiance[at + 1] = emitted[i * 3 + 1];- radiance[at + 2] = emitted[i * 3 + 2];+ // Each pass gathers against what every texel gave off after the pass before,+ // so pass n carries light n surfaces along. With no bounce the surfaces give+ // off nothing and the pass is the sky alone, still shadowed by them.+ const sky = options.sky ?? flatSky(opts.ambient);+ const outgoing = new Float32Array(size * size * 3);+ const indirect = new Float32Array(lumels.count * 3);+ for (let pass = 0; pass < Math.max(1, opts.bounces); pass++) {+ if (opts.bounces > 0) {+ for (let i = 0; i < lumels.count; i++) {+ const at = lumels.texel[i] * 3;+ for (let k = 0; k < 3; k++) outgoing[at + k] = direct[i * 3 + k] + indirect[i * 3 + k];+ }}- const gathered = new Float32Array(lumels.count * 3);- solveBounce(lumels, bvh, lookup, radiance, size, opts.samples, gathered);- for (let i = 0; i < gathered.length; i++) total[i] += gathered[i];- emitted = gathered;+ solveGather(lumels, bvh, lookup, outgoing, size, opts.samples, sky, indirect);}- radiance.fill(0);- solved.fill(0);+ // Two fields: what each texel gives off, which probes and captures read, and+ // what its surface is to add — less the lamps where the draw adds them itself.+ const radiance = new Float32Array(size * size * 3);+ const stored = new Float32Array(size * size * 3);+ const solved = new Uint8Array(size * size);for (let i = 0; i < lumels.count; i++) {const at = lumels.texel[i] * 3;- radiance[at] = total[i * 3];- radiance[at + 1] = total[i * 3 + 1];- radiance[at + 2] = total[i * 3 + 2];- solved[lumels.texel[i]] = 1;- }- dilate(radiance, solved, size, opts.dilate);-- const pixels = new Uint8Array(size * size * 4);- for (let i = 0; i < size * size; i++) {+ const lampsLive = surfaces[lumels.surface[i]]?.realtimeDirect === true;for (let k = 0; k < 3; k++) {- pixels[i * 4 + k] = Math.max(0, Math.min(255, Math.round(radiance[i * 3 + k] * 255)));+ radiance[at + k] = direct[i * 3 + k] + indirect[i * 3 + k];+ stored[at + k] = (lampsLive ? 0 : direct[i * 3 + k]) + indirect[i * 3 + k];}- pixels[i * 4 + 3] = 255;+ solved[lumels.texel[i]] = 1;}+ const solvedStored = solved.slice();+ dilate(radiance, solved, size, opts.dilate);+ dilate(stored, solvedStored, size, opts.dilate);+ const pixels = encodeLightmap(stored, size * size);- // The probes read the atlas as a bounce does — after it holds everything the+ // The probes read the atlas as a gather does — after it holds everything the// surfaces ended up giving off, and before it is quantised to eight bits.const probes = opts.probeGrids.map((grid) =>- solveProbes(grid, bvh, lookup, radiance, size, opts.probeSamples, opts.ambient));+ solveProbes(grid, bvh, lookup, radiance, size, opts.probeSamples, sky));// Captured from the same field, after the same bounces: a reflection of a// wall and the light that wall casts are then the same number.const width = Math.max(8, opts.reflectionWidth);- const sky = options.reflectionSky ?? flatSky(opts.ambient);+ const captured = options.reflectionSky ?? flatSky(opts.ambient);const reflections = opts.reflectionProbes.map((at) =>- captureReflection(at, bvh, lookup, radiance, size, width, Math.max(4, width >> 1), sky));+ captureReflection(at, bvh, lookup, radiance, size, width, Math.max(4, width >> 1), captured));return {pixels,size,scaleOffset: patches.map((p) => p.scaleOffset),lumels: lumels.count,+ shared: lumels.shared,probes,reflections,};diff --git a/sdk/src/lightmap/fingerprint.ts b/sdk/src/lightmap/fingerprint.tsindex d7cf2a622..7046bd59f 100644--- a/sdk/src/lightmap/fingerprint.ts+++ b/sdk/src/lightmap/fingerprint.ts@@ -27,6 +27,12 @@ export interface BakeInputs {texture?: string;/** False where the simulation moves it. */holdsStill?: boolean;+ /** True where the frame adds the lamps to it, leaving the bake its indirect half. */+ realtimeDirect?: boolean;+ /** Drawn with both faces. */+ twoSided?: boolean;+ /** The material's project path, whose cutoff says how much of it stops a ray. */+ material?: string;}>;lights: readonly BakeLight[];volumes: ReadonlyArray<{@@ -67,7 +73,8 @@ export function bakeFingerprint(inputs: BakeInputs): string {const lines: string[] = [];for (const s of inputs.surfaces) {lines.push(`s|${s.mesh}|${nums(s.transform)}|${nums(s.albedo)}|${s.texture ?? ''}`- + `|${s.holdsStill === false ? 0 : 1}`);+ + `|${s.holdsStill === false ? 0 : 1}${s.realtimeDirect ? '|d' : ''}`+ + `${s.twoSided ? '|2' : ''}${s.material ? `|m${s.material}` : ''}`);}for (const l of inputs.lights) {lines.push(`l|${l.kind}|${nums(l.position)}|${nums(l.direction)}|${nums(l.color)}`diff --git a/sdk/src/lightmap/index.ts b/sdk/src/lightmap/index.tsindex e2d5d2e83..63a6634d2 100644--- a/sdk/src/lightmap/index.ts+++ b/sdk/src/lightmap/index.ts@@ -1,7 +1,7 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Teamexport { unwrapLightmapUV, type UnwrapOptions, type UnwrapResult } from './unwrap';-export { bakeLightmap, type BakeOptions, type BakeResult } from './bake';+export { bakeLightmap, LIGHTMAP_RANGE, encodeLightmap, decodeLightmap, type BakeOptions, type BakeResult } from './bake';export type { BakeSurface } from './atlas';export type { BakeLight } from './solve';export { solveProbes, probeAt, type ProbeGrid } from './probes';diff --git a/sdk/src/lightmap/probes.ts b/sdk/src/lightmap/probes.tsindex 5351990ce..912b60c61 100644--- a/sdk/src/lightmap/probes.ts+++ b/sdk/src/lightmap/probes.ts@@ -12,6 +12,7 @@import type { Bvh } from './bvh';import { rayRadiance, type HitLookup } from './solve';+import type { SkyRadiance } from './reflection';import { shBasis, convolveCosine } from './sh';/** Where one grid of probes sits, and how many. */@@ -59,11 +60,11 @@ export function probeAt(min: number, max: number, i: number, n: number): number** `atlas` is the solved light field indexed by texel — what a surface gives off,* before its own albedo. A ray that hits geometry with no place in the atlas- * returns black rather than the ambient: something is there, and it is unlit.+ * returns black rather than the sky: something is there, and it is unlit.*/export function solveProbes(grid: ProbeGrid, bvh: Bvh, lookup: HitLookup,atlas: Float32Array, atlasSize: number, samples: number,- ambient: readonly [number, number, number]): Float32Array {+ sky: SkyRadiance): Float32Array {const [nx, ny, nz] = grid.resolution;const count = Math.max(0, nx) * Math.max(0, ny) * Math.max(0, nz);const out = new Float32Array(count * 27);@@ -85,8 +86,8 @@ export function solveProbes(grid: ProbeGrid, bvh: Bvh, lookup: HitLookup,for (let s = 0; s < samples; s++) {const dx = dirs[s * 3]!, dy = dirs[s * 3 + 1]!, dz = dirs[s * 3 + 2]!;if (!rayRadiance(bvh, lookup, atlas, atlasSize, px, py, pz, dx, dy, dz,- seen)) {- seen[0] = ambient[0]; seen[1] = ambient[1]; seen[2] = ambient[2];+ seen, 0, at * samples + s)) {+ sky(dx, dy, dz, seen, 0);}const r = seen[0]!, g = seen[1]!, b = seen[2]!;shBasis(dx, dy, dz, basis);diff --git a/sdk/src/lightmap/reflection.ts b/sdk/src/lightmap/reflection.tsindex 182caf787..ce092c785 100644--- a/sdk/src/lightmap/reflection.ts+++ b/sdk/src/lightmap/reflection.ts@@ -56,7 +56,7 @@ export function captureReflection(at: readonly [number, number, number],const dz = sinTheta * Math.cos(phi);const to = (y * width + x) * 3;if (!rayRadiance(bvh, lookup, atlas, atlasSize, at[0], at[1], at[2], dx, dy, dz,- rgb, to)) {+ rgb, to, to)) {sky(dx, dy, dz, rgb, to);}}diff --git a/sdk/src/lightmap/solve.ts b/sdk/src/lightmap/solve.tsindex ba633f09c..87b4bed60 100644--- a/sdk/src/lightmap/solve.ts+++ b/sdk/src/lightmap/solve.ts@@ -2,9 +2,9 @@// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team/*** @file solve.ts- * @brief How much light reaches each texel — direct, then what bounced.+ * @brief How much light reaches each texel — direct, then what arrives indirectly.*- * The bounce reads the atlas the pass before it wrote, so a second round costs+ * The gather reads the atlas the pass before it wrote, so a second round costs* what the first did and carries light one surface further. That is the whole* reason a bake is worth having: it is the term a real-time renderer here has* no way to compute at all.@@ -12,6 +12,7 @@import type { Bvh } from './bvh';import type { LumelField } from './atlas';+import type { SkyRadiance } from './reflection';/** A light as a bake sees one: no shadow maps, no cap on how many. */export interface BakeLight {@@ -42,16 +43,72 @@ export interface HitLookup {/** Which way each triangle FACES, three floats each. A surface gives off* light on one side; a ray arriving at the other finds an unlit back. */triNormal: Float32Array;+ /** Per surface: 1 where both faces are drawn, so both give off light. */+ twoSided: Uint8Array;+ /** Per surface: the share of rays it stops. Below one only for a cutout. */+ coverage: Float32Array;+ /** Whether any surface lets rays through, which costs a nearest-hit walk. */+ cutouts: boolean;+ /** How far a surface's back may sit and still be passed: half a lumel. A layer+ * that close above a surface (a decal, a wet sheen, a duplicate) is finer than+ * the atlas can say anything about, and stopping at its back walls the surface+ * under it off from the sky. */+ backReach: number;}/** Whether a ray travelling `d` arrived at triangle `tri`'s lit side. */export function facesRay(lookup: HitLookup, tri: number,dx: number, dy: number, dz: number): boolean {+ if (lookup.twoSided[lookup.triSurface[tri]]) return true;const at = tri * 3;return lookup.triNormal[at] * dx + lookup.triNormal[at + 1] * dy+ lookup.triNormal[at + 2] * dz < 0;}+/** A well-mixed 32-bit hash, so which rays a cutout lets by is fixed per input. */+function mix32(x: number): number {+ x = Math.imul(x ^ (x >>> 16), 0x7feb352d);+ x = Math.imul(x ^ (x >>> 15), 0x846ca68b);+ return (x ^ (x >>> 16)) >>> 0;+}++/**+ * The first triangle along a ray that stops it, or -1; `bvh.hitU/hitV` describe+ * it. A cutout stops a ray with the probability of its coverage, decided by a+ * hash of `seed` and not by chance: a bake that answers differently twice cannot+ * be told from one that answers wrongly once.+ */+export function firstHit(bvh: Bvh, lookup: HitLookup,+ ox: number, oy: number, oz: number,+ dx: number, dy: number, dz: number,+ far: number, epsilon: number, seed: number, backReach = 0): number {+ let travelled = 0;+ for (let step = 0; step < 16; step++) {+ // Past a cutout the walk starts ON it, so it must look beyond its own plane.+ const tri = bvh.hit(ox, oy, oz, dx, dy, dz, far - travelled,+ step === 0 ? epsilon : Math.max(epsilon, SHADOW_EPSILON));+ if (tri < 0) return -1;+ const near = travelled + bvh.hitDistance < backReach && !facesRay(lookup, tri, dx, dy, dz);+ const keep = lookup.coverage[lookup.triSurface[tri]];+ if (!near && (keep >= 1 || mix32(seed ^ Math.imul(step + 1, 0x9e3779b9)) / 4294967296 < keep)) {+ return tri;+ }+ const t = bvh.hitDistance;+ ox += dx * t; oy += dy * t; oz += dz * t;+ travelled += t;+ }+ return -1;+}++/** Whether anything stops the segment, honouring cutouts the way {@link firstHit} does. */+function blocked(bvh: Bvh, lookup: HitLookup, ox: number, oy: number, oz: number,+ dx: number, dy: number, dz: number, far: number, seed: number): boolean {+ if (!lookup.cutouts && !(lookup.backReach > 0)) {+ return bvh.occluded(ox, oy, oz, dx, dy, dz, far, SHADOW_EPSILON);+ }+ return firstHit(bvh, lookup, ox, oy, oz, dx, dy, dz, far, SHADOW_EPSILON, seed, lookup.backReach) >= 0;+}+export const SHADOW_EPSILON = 1e-3;/** Cosine-weighted directions over a hemisphere, as a fixed low-discrepancy set.@@ -91,17 +148,18 @@ function frame(nx: number, ny: number, nz: number, out: Float32Array): void {* What every light delivers straight to each lumel, with nothing between.** Writes irradiance, not colour: the surface's own albedo is applied where the- * bake is read, so one atlas serves a mesh whose texture changes.+ * bake is read, so one atlas serves a mesh whose texture changes. The sky is not+ * here: it reaches a lumel past whatever stands in the way, so it is gathered.*/-export function solveDirect(lumels: LumelField, bvh: Bvh, lights: readonly BakeLight[],- ambient: readonly [number, number, number],- out: Float32Array): void {+export function solveDirect(lumels: LumelField, bvh: Bvh, lookup: HitLookup,+ lights: readonly BakeLight[], out: Float32Array): void {out.fill(0);for (let i = 0; i < lumels.count; i++) {const px = lumels.position[i * 3], py = lumels.position[i * 3 + 1], pz = lumels.position[i * 3 + 2];const nx = lumels.normal[i * 3], ny = lumels.normal[i * 3 + 1], nz = lumels.normal[i * 3 + 2];- let r = ambient[0], g = ambient[1], b = ambient[2];- for (const light of lights) {+ let r = 0, g = 0, b = 0;+ for (let li = 0; li < lights.length; li++) {+ const light = lights[li];let lx: number, ly: number, lz: number, distance: number, falloff = 1;if (light.kind === 'directional') {const d = light.direction ?? [0, 0, -1];@@ -133,8 +191,8 @@ export function solveDirect(lumels: LumelField, bvh: Bvh, lights: readonly BakeLconst lambert = nx * lx + ny * ly + nz * lz;if (lambert <= 0) continue;const far = distance === Infinity ? 1e7 : distance - SHADOW_EPSILON;- if (bvh.occluded(px + nx * SHADOW_EPSILON, py + ny * SHADOW_EPSILON, pz + nz * SHADOW_EPSILON,- lx, ly, lz, far, SHADOW_EPSILON)) continue;+ if (blocked(bvh, lookup, px + nx * SHADOW_EPSILON, py + ny * SHADOW_EPSILON,+ pz + nz * SHADOW_EPSILON, lx, ly, lz, far, Math.imul(i, 31) ^ li)) continue;const w = lambert * falloff * light.intensity;r += light.color[0] * w; g += light.color[1] * w; b += light.color[2] * w;}@@ -143,17 +201,16 @@ export function solveDirect(lumels: LumelField, bvh: Bvh, lights: readonly BakeL}/**- * One bounce: every lumel gathers what the surfaces it can see are giving off.- *- * `previous` is the atlas as the pass before left it, indexed by texel — which- * is why a ray has to be turned back into a texel to be worth anything, and what- * {@link HitLookup} is for.+ * What reaches each lumel indirectly: the sky where a ray escapes, what the surface+ * it meets gives off where one does not. `atlas` is that off each texel, before its+ * albedo, as the pass before left it. Overwrites `out`.*/-export function solveBounce(lumels: LumelField, bvh: Bvh, lookup: HitLookup,- previous: Float32Array, atlasSize: number, samples: number,- accumulate: Float32Array): void {+export function solveGather(lumels: LumelField, bvh: Bvh, lookup: HitLookup,+ atlas: Float32Array, atlasSize: number, samples: number,+ sky: SkyRadiance, out: Float32Array): void {const dirs = hemisphere(samples);const basis = new Float32Array(6);+ const seen = new Float32Array(3);const far = 1e7;for (let i = 0; i < lumels.count; i++) {const px = lumels.position[i * 3], py = lumels.position[i * 3 + 1], pz = lumels.position[i * 3 + 2];@@ -165,21 +222,27 @@ export function solveBounce(lumels: LumelField, bvh: Bvh, lookup: HitLookup,const dx = basis[0] * a + basis[3] * c + nx * d;const dy = basis[1] * a + basis[4] * c + ny * d;const dz = basis[2] * a + basis[5] * c + nz * d;- const tri = bvh.hit(px + nx * SHADOW_EPSILON, py + ny * SHADOW_EPSILON, pz + nz * SHADOW_EPSILON,- dx, dy, dz, far, SHADOW_EPSILON);- if (tri < 0 || !facesRay(lookup, tri, dx, dy, dz)) continue;+ const tri = firstHit(bvh, lookup, px + nx * SHADOW_EPSILON, py + ny * SHADOW_EPSILON,+ pz + nz * SHADOW_EPSILON, dx, dy, dz, far, SHADOW_EPSILON,+ Math.imul(i, samples) + s, lookup.backReach);+ if (tri < 0) {+ sky(dx, dy, dz, seen, 0);+ r += seen[0]; g += seen[1]; b += seen[2];+ continue;+ }+ if (!facesRay(lookup, tri, dx, dy, dz)) continue;const texel = texelOf(lookup, tri, bvh.hitU, bvh.hitV, atlasSize);if (texel < 0) continue;const surface = lookup.triSurface[tri];- r += previous[texel * 3] * lookup.albedo[surface * 3];- g += previous[texel * 3 + 1] * lookup.albedo[surface * 3 + 1];- b += previous[texel * 3 + 2] * lookup.albedo[surface * 3 + 2];+ r += atlas[texel * 3] * lookup.albedo[surface * 3];+ g += atlas[texel * 3 + 1] * lookup.albedo[surface * 3 + 1];+ b += atlas[texel * 3 + 2] * lookup.albedo[surface * 3 + 2];}// Cosine-weighted sampling already carries the projected-area term, so// the estimator is the plain mean of what came back.- accumulate[i * 3] += r / samples;- accumulate[i * 3 + 1] += g / samples;- accumulate[i * 3 + 2] += b / samples;+ out[i * 3] = r / samples;+ out[i * 3 + 1] = g / samples;+ out[i * 3 + 2] = b / samples;}}@@ -194,8 +257,8 @@ export function solveBounce(lumels: LumelField, bvh: Bvh, lookup: HitLookup,export function rayRadiance(bvh: Bvh, lookup: HitLookup, atlas: Float32Array, atlasSize: number,fromX: number, fromY: number, fromZ: number,dx: number, dy: number, dz: number,- out: Float32Array, at = 0): boolean {- const tri = bvh.hit(fromX, fromY, fromZ, dx, dy, dz, 1e7, 0);+ out: Float32Array, at = 0, seed = 0): boolean {+ const tri = firstHit(bvh, lookup, fromX, fromY, fromZ, dx, dy, dz, 1e7, 0, seed);if (tri < 0) return false;// Geometry with no place in the atlas is black rather than sky: something is// there, and it is unlit.diff --git a/sdk/src/render/builtinShaders.ts b/sdk/src/render/builtinShaders.tsindex c0a2a132b..cb3cc73cf 100644--- a/sdk/src/render/builtinShaders.ts+++ b/sdk/src/render/builtinShaders.ts@@ -374,7 +374,10 @@ in highp vec3 v_worldNormal;in highp vec3 v_worldXYZ;#endif-uniform sampler2D u_textures[8];+// One, not the batch stream's eight: a sampler array counts whole against the+// sixteen units a stage may use, and this stage also takes four maps, four the+// engine injects and a bake.+uniform sampler2D u_textures[1];out vec4 fragColor;@@ -425,6 +428,9 @@ void main() {// run its GLSL twin reads straight off one. Without this every material-shaded// draw read instance 0's indirect light — one probe volume for the lot.g_probeSlot = v.v_probeSlot;+#ifdef MESH_LIGHTMAP+ g_lightmap = v.v_lightmap;+#endiflet base = textureSampleGrad(t0, s0, v.v_texCoord, duvx, duvy) * v.v_color * mc.u_tint;// Before any discard: a derivative needs every fragment of its quad.let edge = max(fwidth(base.a), 1e-4);diff --git a/sdk/tests/lightmap-bake.test.ts b/sdk/tests/lightmap-bake.test.tsindex d9033066e..a7dea849c 100644--- a/sdk/tests/lightmap-bake.test.ts+++ b/sdk/tests/lightmap-bake.test.ts@@ -7,7 +7,12 @@* result worth reading rather than a flat wash.*/import { describe, it, expect } from 'vitest';-import { unwrapLightmapUV, bakeLightmap, type BakeSurface, type BakeLight } from '../src/lightmap';+import { readFileSync } from 'node:fs';+import path from 'node:path';+import {+ unwrapLightmapUV, bakeLightmap, decodeLightmap, flatSky, LIGHTMAP_RANGE,+ type BakeSurface, type BakeLight,+} from '../src/lightmap';import { MeshChannel, MeshChannelType, type MeshData } from '../src/asset/meshFormat';const IDENTITY = Float32Array.from([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);@@ -87,8 +92,8 @@ function brightnessAt(result: ReturnType<typeof bakeLightmap>, surface: number,const [su, sv, ou, ov] = result.scaleOffset[surface];const x = Math.floor((ou + u * su) * result.size);const y = Math.floor((ov + v * sv) * result.size);- const at = (y * result.size + x) * 4;- return (result.pixels[at] + result.pixels[at + 1] + result.pixels[at + 2]) / 3;+ const [r, g, b] = decodeLightmap(result.pixels, y * result.size + x);+ return (r + g + b) / 3;}/**@@ -156,7 +161,7 @@ describe('a baked lightmap', () => {const x = -18 + 36 * ((i + 0.5) / 20);const uv = uvAtWorld(ground, x, 0, 0);expect(uv).not.toBeNull();- if (brightnessAt(result, 0, uv![0], uv![1]) > 20) brightSpots++;+ if (brightnessAt(result, 0, uv![0], uv![1]) > 0.08) brightSpots++;}expect(brightSpots).toBe(20);});@@ -173,7 +178,7 @@ describe('a baked lightmap', () => {// front is in shadow and the floor behind is not.const lightSide = sampleFloor(result, ground, -4);const shadowed = sampleFloor(result, ground, 4);- expect(lightSide).toBeGreaterThan(20);+ expect(lightSide).toBeGreaterThan(0.08);expect(shadowed).toBeLessThan(lightSide / 3);});@@ -215,8 +220,8 @@ describe('a baked lightmap', () => {const [rr, rg] = under([1, 0.1, 0.1]);const [wr, wg] = under([1, 1, 1]);expect(rr).toBeGreaterThan(0);- expect(rr / Math.max(rg, 1)).toBeGreaterThan(3);- expect(wr / Math.max(wg, 1)).toBeLessThan(1.2);+ expect(rr / Math.max(rg, 1e-3)).toBeGreaterThan(3);+ expect(wr / Math.max(wg, 1e-3)).toBeLessThan(1.2);});it('gives each object its own patch of the atlas', () => {@@ -251,6 +256,114 @@ describe('a baked lightmap', () => {});});+describe('the indirect half of a bake', () => {+ it('lets the sky in only where it can see the sky', () => {+ // A roof half a unit over the middle of an open floor, and no lamp: what+ // the floor gets is the sky, and under the roof most of it is hidden.+ const ground = baked(floor(8));+ const roof = baked(ceiling(1));+ const result = bakeLightmap(+ [{ mesh: ground, transform: IDENTITY }, { mesh: roof, transform: translated(0, 0.5, 0) }],+ [], { ...LIT, samples: 256, ambient: [1, 1, 1] },+ );+ const open = sampleFloor(result, ground, 7);+ const covered = sampleFloor(result, ground, 0);+ expect(open).toBeGreaterThan(0.9);+ expect(covered).toBeLessThan(open * 0.5);+ });++ it('reads the sky by direction', () => {+ // Bright only straight up: a floor facing it is lit and a wall facing+ // sideways gets half its hemisphere's worth at most.+ const ground = baked(floor(8));+ const up = flatSky([0, 0, 0]);+ const zenith = (dx: number, dy: number, dz: number, out: Float32Array, at: number): void => {+ up(dx, dy, dz, out, at);+ const v = dy > 0 ? 2 : 0;+ out[at] = v; out[at + 1] = v; out[at + 2] = v;+ };+ const result = bakeLightmap([{ mesh: ground, transform: IDENTITY }], [],+ { ...LIT, samples: 64, sky: zenith });+ expect(sampleFloor(result, ground, 0)).toBeCloseTo(2, 1);+ });++ it('leaves the lamps out of a surface the frame lights itself, and still bounces them', () => {+ const ground = baked(floor(8));+ const panel = baked(ceiling(2));+ const lamp: BakeLight[] = [+ { kind: 'point', position: [0, 6, 0], color: [1, 1, 1], intensity: 8, radius: 40 },+ ];+ const bake = (realtimeDirect: boolean) => bakeLightmap([+ { mesh: ground, transform: IDENTITY, albedo: [1, 1, 1], realtimeDirect },+ { mesh: panel, transform: translated(0, 3, 0), albedo: [1, 1, 1] },+ ], lamp, { ...LIT, bounces: 1, samples: 64 });+ const whole = bake(false);+ const indirect = bake(true);+ // The floor's own patch drops the lamp it faces; what it sends up does not.+ expect(sampleFloor(whole, ground, 6)).toBeGreaterThan(0.1);+ expect(sampleFloor(indirect, ground, 6)).toBeLessThan(sampleFloor(whole, ground, 6) * 0.2);+ expect(brightestOf(indirect, 1)).toBeCloseTo(brightestOf(whole, 1), 5);+ expect(brightestOf(indirect, 1)).toBeGreaterThan(0);+ });++ it('keeps light brighter than one', () => {+ const ground = baked(floor(4));+ const result = bakeLightmap([{ mesh: ground, transform: IDENTITY }],+ [{ kind: 'directional', direction: [0, -1, 0], color: [1, 1, 1], intensity: 7 }], LIT);+ expect(sampleFloor(result, ground, 0)).toBeCloseTo(7, 1);+ });++ it('is decoded by the shader with the range it was encoded with', () => {+ const src = readFileSync(path.resolve(__dirname, '../../src/esengine/resource/ShaderParser.cpp'), 'utf8');+ const ranges = [...src.matchAll(/return c \* c \* ([\d.]+);/g)].map((m) => Number(m[1]));+ expect(ranges).toHaveLength(2);+ for (const r of ranges) expect(r).toBe(LIGHTMAP_RANGE);+ });+});++describe('what a bake lets through', () => {+ it('lets a cutout pass the share of the sky it does not cover', () => {+ const ground = baked(floor(8));+ const roof = baked(ceiling(1));+ const under = (coverage: number): number => sampleFloor(bakeLightmap(+ [{ mesh: ground, transform: IDENTITY }, { mesh: roof, transform: translated(0, 0.5, 0), coverage }],+ [], { ...LIT, samples: 256, ambient: [1, 1, 1] }), ground, 0);+ const solid = under(1), half = under(0.5), none = under(0);+ expect(none).toBeGreaterThan(0.9);+ expect(solid).toBeLessThan(none * 0.5);+ expect(half).toBeGreaterThan(solid + (none - solid) * 0.35);+ expect(half).toBeLessThan(solid + (none - solid) * 0.65);+ });++ it('passes the back of a layer lying a hair above a surface', () => {+ // A second floor two centimetres over the first, facing up as a decal or a+ // wet sheen does: finer than a lumel, so the floor under it keeps its sky.+ // A roof half a unit up (above) still hides it — that is resolvable.+ const ground = baked(floor(8));+ const layer = baked(floor(8));+ const result = bakeLightmap(+ [{ mesh: ground, transform: IDENTITY }, { mesh: layer, transform: translated(0, 0.02, 0) }],+ [], { ...LIT, samples: 64, ambient: [1, 1, 1] });+ expect(sampleFloor(result, ground, 0)).toBeGreaterThan(0.9);+ });++ it('reads the back of a two-sided surface as lit', () => {+ // A lit panel over the floor, facing the lamp: the floor under it sees only+ // the panel's back, which a one-sided panel does not give off light from.+ const ground = baked(floor(8));+ const panel = baked(floor(2));+ const lamp: BakeLight[] = [+ { kind: 'point', position: [0, 6, 0], color: [1, 1, 1], intensity: 8, radius: 40 },+ ];+ const under = (twoSided: boolean): number => sampleFloor(bakeLightmap([+ { mesh: ground, transform: IDENTITY, albedo: [1, 1, 1] },+ { mesh: panel, transform: translated(0, 3, 0), albedo: [1, 1, 1], twoSided },+ ], lamp, { ...LIT, bounces: 1, samples: 64 }), ground, 0);+ expect(under(false)).toBeLessThan(0.01);+ expect(under(true)).toBeGreaterThan(0.05);+ });+});+/** Brightest texel in one surface's patch of the atlas. */function brightestOf(result: ReturnType<typeof bakeLightmap>, surface: number): number {const [su, sv, ou, ov] = result.scaleOffset[surface];@@ -259,8 +372,8 @@ function brightestOf(result: ReturnType<typeof bakeLightmap>, surface: number):const y0 = Math.floor(ov * result.size), y1 = Math.ceil((ov + sv) * result.size);for (let y = y0; y < y1; y++) {for (let x = x0; x < x1; x++) {- const at = (y * result.size + x) * 4;- best = Math.max(best, (result.pixels[at] + result.pixels[at + 1] + result.pixels[at + 2]) / 3);+ const [r, g, b] = decodeLightmap(result.pixels, y * result.size + x);+ best = Math.max(best, (r + g + b) / 3);}}return best;@@ -276,11 +389,11 @@ function brightestChannels(result: ReturnType<typeof bakeLightmap>,const y0 = Math.floor(ov * result.size), y1 = Math.ceil((ov + sv) * result.size);for (let y = y0; y < y1; y++) {for (let x = x0; x < x1; x++) {- const at = (y * result.size + x) * 4;- const sum = result.pixels[at] + result.pixels[at + 1] + result.pixels[at + 2];+ const rgb = decodeLightmap(result.pixels, y * result.size + x);+ const sum = rgb[0] + rgb[1] + rgb[2];if (sum > best) {best = sum;- out = [result.pixels[at], result.pixels[at + 1], result.pixels[at + 2]];+ out = rgb;}}}@@ -293,3 +406,31 @@ function sampleFloor(result: ReturnType<typeof bakeLightmap>, mesh: MeshData, z:if (!uv) throw new Error(`no floor triangle at z=${z}`);return brightnessAt(result, 0, uv[0], uv[1]);}++/** The same mesh with its lightmap UVs squeezed into a corner of their square. */+function squeezed(mesh: MeshData, by: number): MeshData {+ const uv1 = mesh.channels.find((c) => c.semantic === MeshChannel.TexCoord1)!;+ const vertices = mesh.vertices.slice();+ const view = new DataView(vertices.buffer);+ for (let i = 0; i < mesh.vertexCount; i++) {+ for (let k = 0; k < 2; k++) {+ const at = i * mesh.vertexStride + uv1.offset + k * 4;+ view.setFloat32(at, view.getFloat32(at, true) * by, true);+ }+ }+ return { ...mesh, vertices };+}++describe('a bake that does not fit', () => {+ it('names the surfaces taking the most room, and says a sparse lightmap UV set is why', () => {+ const surfaces: BakeSurface[] = [+ { mesh: squeezed(baked(floor(10)), 0.1), transform: IDENTITY, label: 'Road' },+ { mesh: baked(floor(10)), transform: translated(30, 0, 0), label: 'Square' },+ ];+ expect(() => bakeLightmap(surfaces, [], { atlasSize: 256, texelsPerUnit: 2 }))+ .toThrow(/The largest: Road \(256x256, its lightmap UVs cover \d\.\d%\).*Generate Lightmap UVs/);+ // Without the squeeze the same two fit.+ expect(() => bakeLightmap([{ ...surfaces[0]!, mesh: baked(floor(10)) }, surfaces[1]!], [],+ { atlasSize: 256, texelsPerUnit: 2, bounces: 0 })).not.toThrow();+ });+});diff --git a/src/esengine/data/shaders/mesh.esshader b/src/esengine/data/shaders/mesh.esshaderindex cf18f9a7b..535e03197 100644--- a/src/esengine/data/shaders/mesh.esshader+++ b/src/esengine/data/shaders/mesh.esshader@@ -184,9 +184,6 @@ precision mediump float;in vec2 v_texCoord;in vec4 v_color;-#ifdef MESH_LIGHTMAP-in highp vec3 v_lightmap;-#endif#ifdef LITin highp vec3 v_worldNormal;in highp vec3 v_worldPos;@@ -199,9 +196,6 @@ uniform sampler2D u_texture;#ifdef NORMAL_MAPuniform sampler2D u_normalMap;#endif-#ifdef MESH_LIGHTMAP-uniform sampler2D u_lightmap;-#endifout vec4 fragColor;@@ -214,9 +208,6 @@ void main() {0.0, 1.0)), 1.0);#elsevec4 base = texture(u_texture, v_texCoord) * v_color;-#ifdef MESH_LIGHTMAP- vec3 baked = texture(u_lightmap, v_lightmap.xy).rgb;-#endif#ifdef LIThighp vec3 N = normalize(v_worldNormal);#ifdef NORMAL_MAP@@ -228,21 +219,17 @@ void main() {// point in space, and xy is not one. Specular stays ON — switching it off is// not a cheaper PBR, it is a different surface, and a mesh whose material// says nothing must still be lit the way the same mesh out of a glTF is.+ // A bake arrives through indirectIrradiance, in place of the sky: the lamps+ // stay the frame's, and the bake holds what reached this point off everything else.vec3 shaded = applyLightingPBR(base.rgb, N, v_worldPos, viewDirection(v_worldPos),0.0, 1.0, 1.0, 1.0);-#ifdef MESH_LIGHTMAP- // The INDIRECT term. A real-time light says what reaches this point straight- // from a source, and the bake says what reached it off everything else — so- // the two are added, and a surface that has both is not lit twice.- shaded += base.rgb * baked * v_lightmap.z;-#endiffragColor = vec4(shaded, base.a);#else#ifdef MESH_LIGHTMAP// Unlit AND lightmapped: the bake is the whole of this surface's light, not// an addition to a direct term it has none of. This is the case a bake is// FOR — a scene whose lights all went into the atlas pays for none of them.- fragColor = vec4(base.rgb * mix(vec3(1.0), baked, v_lightmap.z), base.a);+ fragColor = vec4(base.rgb * mix(vec3(1.0), bakedIrradiance(), v_lightmap.z), base.a);#elsefragColor = base;#endif@@ -422,6 +409,9 @@ struct VSOut {// WGSL has no module varying: the entry point hands the injected header the// slot its GLSL twin reads straight off one.g_probeSlot = v.v_probeSlot;+#ifdef MESH_LIGHTMAP+ g_lightmap = v.v_lightmap;+#endif#ifdef SHADOW_DEPTH// The expression the receiver evaluates on u_shadowMatrix, evaluated here on the// same matrix and at the same point: whatever each backend's clip z means, both@@ -430,9 +420,6 @@ struct VSOut {0.0, 1.0)), 1.0);#elselet base = textureSampleLevel(t0, s0, v.v_texCoord, 0.0) * v.v_color;-#ifdef MESH_LIGHTMAP- let baked = textureSampleLevel(t5, s5, v.v_lightmap.xy, 0.0).rgb;-#endif#ifdef LITvar N = normalize(v.v_worldNormal);#ifdef NORMAL_MAP@@ -443,17 +430,13 @@ struct VSOut {// point in space, and xy is not one. Specular stays ON — switching it off is// not a cheaper PBR, it is a different surface, and a mesh whose material// says nothing must still be lit the way the same mesh out of a glTF is.- var shaded = applyLightingPBR(base.rgb, N, v.v_worldPos, viewDirection(v.v_worldPos),+ let shaded = applyLightingPBR(base.rgb, N, v.v_worldPos, viewDirection(v.v_worldPos),0.0, 1.0, 1.0, 1.0);-#ifdef MESH_LIGHTMAP- // The INDIRECT term — see the GLSL twin.- shaded = shaded + base.rgb * baked * v.v_lightmap.z;-#endifreturn vec4f(shaded, base.a);#else#ifdef MESH_LIGHTMAP// Unlit AND lightmapped: the bake is the whole of this surface's light.- return vec4f(base.rgb * mix(vec3f(1.0), baked, vec3f(v.v_lightmap.z)), base.a);+ return vec4f(base.rgb * mix(vec3f(1.0), bakedIrradiance(), vec3f(v.v_lightmap.z)), base.a);#elsereturn base;#endifdiff --git a/src/esengine/renderer/RenderTypePlugin.hpp b/src/esengine/renderer/RenderTypePlugin.hppindex 0b5348863..da39a0ee3 100644--- a/src/esengine/renderer/RenderTypePlugin.hpp+++ b/src/esengine/renderer/RenderTypePlugin.hpp@@ -166,8 +166,9 @@ struct RenderPrewarmResult {std::vector<u64> materialKeys;/** @brief What a material program is asked for, as one comparable value. */- static u64 materialKey(u32 materialId, bool normals, bool skinned, bool envMapped) {- return (static_cast<u64>(materialId) << 3) | (normals ? 4u : 0u)+ static u64 materialKey(u32 materialId, bool normals, bool skinned, bool envMapped,+ bool lightmapped) {+ return (static_cast<u64>(materialId) << 4) | (lightmapped ? 8u : 0u) | (normals ? 4u : 0u)| (skinned ? 2u : 0u) | (envMapped ? 1u : 0u);}diff --git a/src/esengine/renderer/plugins/MeshPlugin.cpp b/src/esengine/renderer/plugins/MeshPlugin.cppindex 4b4a99ca4..0d5478ece 100644--- a/src/esengine/renderer/plugins/MeshPlugin.cpp+++ b/src/esengine/renderer/plugins/MeshPlugin.cpp@@ -416,9 +416,10 @@ RenderPrewarmResult MeshPlugin::prewarmFacts(RenderFrameContext& ctx,if (facts[i].materialId != 0 && ctx.materials) {++out.materialAsks;out.addMaterialKey(RenderPrewarmResult::materialKey(- facts[i].materialId, facts[i].hasNormals, facts[i].skinned, envMapped));+ facts[i].materialId, facts[i].hasNormals, facts[i].skinned, envMapped,+ facts[i].lightmapped));ctx.materials->meshProgram(facts[i].materialId, ctx.resources, facts[i].hasNormals,- facts[i].skinned, envMapped);+ facts[i].skinned, envMapped, facts[i].lightmapped);}}if (ctx.materials) {@@ -742,7 +743,8 @@ void MeshPlugin::collect(RenderCollectContext& collect_ctx) {if (key.materialId != 0 && ctx.materials) {materialProgram = ctx.materials->meshProgram(key.materialId, ctx.resources,resident->hasNormals, skinned,- key.envTextureId != 0);+ key.envTextureId != 0,+ resident->hasLightmapUV);if (materialProgram == 0) {if (!warned_material_) {warned_material_ = true;diff --git a/src/esengine/renderer/rhi/ShaderEmbeds.generated.hpp b/src/esengine/renderer/rhi/ShaderEmbeds.generated.hppindex 45520ac47..3630a7b84 100644--- a/src/esengine/renderer/rhi/ShaderEmbeds.generated.hpp+++ b/src/esengine/renderer/rhi/ShaderEmbeds.generated.hpp@@ -535,9 +535,6 @@ precision mediump float;in vec2 v_texCoord;in vec4 v_color;-#ifdef MESH_LIGHTMAP-in highp vec3 v_lightmap;-#endif#ifdef LITin highp vec3 v_worldNormal;in highp vec3 v_worldPos;@@ -550,9 +547,6 @@ uniform sampler2D u_texture;#ifdef NORMAL_MAPuniform sampler2D u_normalMap;#endif-#ifdef MESH_LIGHTMAP-uniform sampler2D u_lightmap;-#endifout vec4 fragColor;@@ -565,9 +559,6 @@ void main() {0.0, 1.0)), 1.0);#elsevec4 base = texture(u_texture, v_texCoord) * v_color;-#ifdef MESH_LIGHTMAP- vec3 baked = texture(u_lightmap, v_lightmap.xy).rgb;-#endif#ifdef LIThighp vec3 N = normalize(v_worldNormal);#ifdef NORMAL_MAP@@ -579,21 +570,17 @@ void main() {- vec3 shaded = applyLightingPBR(base.rgb, N, v_worldPos, viewDirection(v_worldPos),- 0.0, 1.0, 1.0, 1.0);-#ifdef MESH_LIGHTMAP-- shaded += base.rgb * baked * v_lightmap.z;-#endif+ vec3 shaded = applyLightingPBR(base.rgb, N, v_worldPos, viewDirection(v_worldPos),+ 0.0, 1.0, 1.0, 1.0);fragColor = vec4(shaded, base.a);#else#ifdef MESH_LIGHTMAP- fragColor = vec4(base.rgb * mix(vec3(1.0), baked, v_lightmap.z), base.a);+ fragColor = vec4(base.rgb * mix(vec3(1.0), bakedIrradiance(), v_lightmap.z), base.a);#elsefragColor = base;#endif@@ -773,6 +760,9 @@ struct VSOut {g_probeSlot = v.v_probeSlot;+#ifdef MESH_LIGHTMAP+ g_lightmap = v.v_lightmap;+#endif#ifdef SHADOW_DEPTH@@ -781,9 +771,6 @@ struct VSOut {0.0, 1.0)), 1.0);#elselet base = textureSampleLevel(t0, s0, v.v_texCoord, 0.0) * v.v_color;-#ifdef MESH_LIGHTMAP- let baked = textureSampleLevel(t5, s5, v.v_lightmap.xy, 0.0).rgb;-#endif#ifdef LITvar N = normalize(v.v_worldNormal);#ifdef NORMAL_MAP@@ -794,17 +781,13 @@ struct VSOut {- var shaded = applyLightingPBR(base.rgb, N, v.v_worldPos, viewDirection(v.v_worldPos),+ let shaded = applyLightingPBR(base.rgb, N, v.v_worldPos, viewDirection(v.v_worldPos),0.0, 1.0, 1.0, 1.0);-#ifdef MESH_LIGHTMAP-- shaded = shaded + base.rgb * baked * v.v_lightmap.z;-#endifreturn vec4f(shaded, base.a);#else#ifdef MESH_LIGHTMAP- return vec4f(base.rgb * mix(vec3f(1.0), baked, vec3f(v.v_lightmap.z)), base.a);+ return vec4f(base.rgb * mix(vec3f(1.0), bakedIrradiance(), vec3f(v.v_lightmap.z)), base.a);#elsereturn base;#endifdiff --git a/src/esengine/renderer/store/MaterialStore.cpp b/src/esengine/renderer/store/MaterialStore.cppindex fe0801ab4..63161fdf5 100644--- a/src/esengine/renderer/store/MaterialStore.cpp+++ b/src/esengine/renderer/store/MaterialStore.cpp@@ -35,15 +35,18 @@ void MaterialStore::clear() {}u32 MaterialStore::meshProgram(u32 materialId, resource::ResourceManager& resources,- bool withNormals, bool skinned, bool envMapped) const {+ bool withNormals, bool skinned, bool envMapped,+ bool lightmapped) const {// Keyed by shader AND vertex shape: a layout may not declare an attribute its// shader ignores, so geometry with normals — or posed by bones — needs its own.const u64 shape = (withNormals ? (1ull << 32) : 0ull)| (skinned ? (1ull << 33) : 0ull)- | (envMapped ? (1ull << 34) : 0ull);+ | (envMapped ? (1ull << 34) : 0ull)+ | (lightmapped ? (1ull << 36) : 0ull);std::vector<std::string> features{ "MESH" };if (withNormals) features.push_back("MESH_NORMALS");if (skinned) features.push_back("SKINNED");+ if (lightmapped) features.push_back("MESH_LIGHTMAP");// Resident geometry carries the frame's shadow map on its own slot 2 and the// reflection on slot 3; the batch variant of the same material must not, which// is why these ride the mesh path.diff --git a/src/esengine/renderer/store/MaterialStore.hpp b/src/esengine/renderer/store/MaterialStore.hppindex 9b8ed5291..7f68eb537 100644--- a/src/esengine/renderer/store/MaterialStore.hpp+++ b/src/esengine/renderer/store/MaterialStore.hpp@@ -173,14 +173,12 @@ public:if (shader.isValid()) sources_[shader.id()] = { std::move(source), std::move(features) };}- /// The program that draws @p materialId on GPU-RESIDENT geometry, compiled on- /// first use and cached. @p withNormals selects the variant for geometry that- /// carries them, @p skinned the one posed by bones instead of a per-object- /// matrix. 0 when the material's source was never kept or the variant fails —- /// the caller then falls back rather than drawing it wrong.+ /// The program that draws @p materialId on resident geometry of this shape, compiled+ /// once and cached; 0 when the source was never kept or the variant fails, so the+ /// caller falls back rather than drawing it wrong.u32 meshProgram(u32 materialId, resource::ResourceManager& resources,bool withNormals = false, bool skinned = false,- bool envMapped = false) const;+ bool envMapped = false, bool lightmapped = false) const;/// The program that draws @p materialId on PARTICLE geometry — the instanced/// quad an emitter streams. Same source, same author's fragment, a differentdiff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cppindex 827c43b5f..164bbd45a 100644--- a/src/esengine/resource/ShaderParser.cpp+++ b/src/esengine/resource/ShaderParser.cpp@@ -1057,6 +1057,8 @@ struct ProbeConstants { u_probeIrradiance : array<vec4f, 1000>, u_probeTail : ve// varying, so the entry point hands it over — the GLSL twin reads the varying// straight, which is the one place the two stages differ in shape.var<private> g_probeSlot : f32 = 0.0;+// The GLSL twin's v_lightmap, handed over by the entry point like the slot above.+var<private> g_lightmap : vec3f = vec3f(0.0);fn packDepth(d : f32) -> vec3f {let enc = fract(d * vec3f(1.0, 255.0, 65025.0));return enc - enc.yzz * vec3f(1.0 / 255.0, 1.0 / 255.0, 0.0);@@ -1317,7 +1319,16 @@ fn envIrradiance(Nw : vec3f) -> vec3f {// The GLSL twin's indirectIrradiance: a volume replaces the environment, because a// surface has one indirect term and a volume already holds every light and bounce// that reached the point.+#ifdef MESH_LIGHTMAP+fn bakedIrradiance() -> vec3f {+ let c = textureSampleLevel(t5, s5, g_lightmap.xy, 0.0).rgb;+ return c * c * 8.0;+}+#endiffn indirectIrradiance(N : vec3f) -> vec3f {+#ifdef MESH_LIGHTMAP+ if (g_lightmap.z > 0.5) { return bakedIrradiance(); }+#endiflet base = clamp(i32(g_probeSlot), 0, 99) * 10;if (pc.u_probeIrradiance[base].w > 0.5) {var sh : array<vec4f, 9>;@@ -2172,7 +2183,12 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p// or a draw carrying no run at all — is the environment, which is what every// surface reflected before there were probes."highp float reflectionColumn() { return u_probeIrradiance[probeRun() + 9].x; }\n"+ // A bake outranks a volume for the same reason a volume outranks the sky:+ // it holds every light and bounce that reached this very point."highp vec3 indirectIrradiance(in highp vec3 N) {\n"+ "#ifdef MESH_LIGHTMAP\n"+ " if (v_lightmap.z > 0.5) return bakedIrradiance();\n"+ "#endif\n"" highp int base = probeRun();\n"" if (u_probeIrradiance[base].w > 0.5) {\n"" highp vec4 sh[9];\n"@@ -2401,6 +2417,23 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p"highp vec3 applyLighting2D(highp vec3 albedo, highp vec3 N, highp vec2 worldPos) {\n"" return applyLighting2DAO(albedo, N, worldPos, 1.0);\n""}\n";+ // Emitted only for a variant that has the feature, not behind an #ifdef:+ // a varying declared in dead text still reads as one to a tool that+ // pairs the stages by name, and this one has no vertex output without it.+ if (std::find(features.begin(), features.end(), "MESH_LIGHTMAP") != features.end()) {+ // The bake's atlas and where this fragment sits in it; z says whether this+ // object has a patch at all. Square-law over LIGHTMAP_RANGE, which the+ // baker encodes with.+ static const char* kLightmapHeader =+ "in highp vec3 v_lightmap;\n"+ "uniform highp sampler2D u_lightmap;\n"+ "highp vec3 bakedIrradiance() {\n"+ " highp vec3 c = textureLod(u_lightmap, v_lightmap.xy, 0.0).rgb;\n"+ " return c * c * 8.0;\n"+ "}\n";+ assembled << kLightmapHeader;+ headerLines += countNewlines(kLightmapHeader);+ }assembled << kLitHeader;headerLines += countNewlines(kLitHeader);}diff --git a/tools/check-shader-blocks.mjs b/tools/check-shader-blocks.mjsindex 453601e55..d1c1d6b57 100644--- a/tools/check-shader-blocks.mjs+++ b/tools/check-shader-blocks.mjs@@ -39,7 +39,7 @@ const parser = readFileSync(path.join(ROOT, PARSER), 'utf8');* shader rather than a face both backends present, and pulling those in would* ask a vertex entry point to have a GLSL twin.*/-const HEADERS = ['kColorHelpers', 'kFrameHeader', 'kTimeHeader', 'kLitHeader'];+const HEADERS = ['kColorHelpers', 'kFrameHeader', 'kTimeHeader', 'kLitHeader', 'kLightmapHeader'];/*** One header's text as the shader receives it: raw strings taken whole,diff --git a/tools/gen-shader-twins.mjs b/tools/gen-shader-twins.mjsindex fc0c071f4..a9291b5c6 100644--- a/tools/gen-shader-twins.mjs+++ b/tools/gen-shader-twins.mjs@@ -81,6 +81,7 @@ const ENGINE_SAMPLERS = [{ name: 'u_envMap', unit: 3 },{ name: 'u_shadow2D', unit: 7 },{ name: 'u_lightShape2D', unit: 6 },+ { name: 'u_lightmap', unit: 5 },// The two the VERTEX stage reads, pinned in MorphConstants.hpp and// InstanceConstants.hpp. The record sits on the TOP unit, above every unit a// material's own textures are handed (see GfxEnums MESH_INSTANCE_TEXTURE_UNIT).diff --git a/tools/make-lightmap-fixture.mjs b/tools/make-lightmap-fixture.mjsindex af010bc77..084ac82d6 100644--- a/tools/make-lightmap-fixture.mjs+++ b/tools/make-lightmap-fixture.mjs@@ -1,9 +1,9 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team/**- * Regenerate the baked-light fixture: one quad with TWO UV sets, and a four-texel- * atlas, red half then blue half. The second UV set is the TRANSPOSE of the first,- * so a bake read through the wrong channel comes out turned ninety degrees.+ * Regenerate the baked-light fixture: a quad with TWO UV sets (and a copy carrying a+ * normal) and a four-texel atlas, red half then blue half. The second UV set is the+ * TRANSPOSE of the first, so a bake read through the wrong channel turns ninety degrees.** node tools/make-lightmap-fixture.mjs*/@@ -11,10 +11,11 @@ import { writeFileSync } from 'node:fs';import { deflateSync } from 'node:zlib';import path from 'node:path';import { fileURLToPath } from 'node:url';-import { encodeMesh, packChannels, MeshChannel, MeshChannelType } from '../sdk/dist/index.node.js';+import { encodeMesh, packChannels, encodeLightmap, MeshChannel, MeshChannelType } from '../sdk/dist/index.node.js';const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');const MESH = path.join(ROOT, 'fixtures', 'scenes', 'lightmap-quad.esmesh');+const MESH_LIT = path.join(ROOT, 'fixtures', 'scenes', 'lightmap-quad-lit.esmesh');const ATLAS = path.join(ROOT, 'fixtures', 'scenes', 'lightmap-atlas.png');/** Wide enough that every gate point lands well inside the quad. */@@ -26,35 +27,45 @@ const UV0 = [[0, 0], [1, 0], [1, 1], [0, 1]];/** (u, v) -> (v, u): the atlas's left-to-right becomes the quad's bottom-to-top. */const UV1 = UV0.map(([u, v]) => [v, u]);-const { channels, vertexStride } = packChannels([- { semantic: MeshChannel.Position, components: 3, type: MeshChannelType.Float32 },- { semantic: MeshChannel.TexCoord0, components: 2, type: MeshChannelType.Float32 },- { semantic: MeshChannel.TexCoord1, components: 2, type: MeshChannelType.Float32 },- { semantic: MeshChannel.Color, components: 4, type: MeshChannelType.UNorm8 },-]);-const at = (semantic) => channels.find((c) => c.semantic === semantic).offset;+/** The quad, and the same quad carrying a normal: an imported model has one, and+ * that is a different program for every material drawn on it. */+function quad(file, withNormal) {+ const { channels, vertexStride } = packChannels([+ { semantic: MeshChannel.Position, components: 3, type: MeshChannelType.Float32 },+ ...(withNormal ? [{ semantic: MeshChannel.Normal, components: 3, type: MeshChannelType.Float32 }] : []),+ { semantic: MeshChannel.TexCoord0, components: 2, type: MeshChannelType.Float32 },+ { semantic: MeshChannel.TexCoord1, components: 2, type: MeshChannelType.Float32 },+ { semantic: MeshChannel.Color, components: 4, type: MeshChannelType.UNorm8 },+ ]);+ const at = (semantic) => channels.find((c) => c.semantic === semantic).offset;-const vertices = new Uint8Array(POSITIONS.length * vertexStride);-const view = new DataView(vertices.buffer);-POSITIONS.forEach((p, i) => {- const base = i * vertexStride;- for (let c = 0; c < 3; c++) view.setFloat32(base + at(MeshChannel.Position) + c * 4, p[c], true);- view.setFloat32(base + at(MeshChannel.TexCoord0), UV0[i][0], true);- view.setFloat32(base + at(MeshChannel.TexCoord0) + 4, UV0[i][1], true);- view.setFloat32(base + at(MeshChannel.TexCoord1), UV1[i][0], true);- view.setFloat32(base + at(MeshChannel.TexCoord1) + 4, UV1[i][1], true);- for (let c = 0; c < 4; c++) view.setUint8(base + at(MeshChannel.Color) + c, 255);-});+ const vertices = new Uint8Array(POSITIONS.length * vertexStride);+ const view = new DataView(vertices.buffer);+ POSITIONS.forEach((p, i) => {+ const base = i * vertexStride;+ for (let c = 0; c < 3; c++) view.setFloat32(base + at(MeshChannel.Position) + c * 4, p[c], true);+ if (withNormal) view.setFloat32(base + at(MeshChannel.Normal) + 8, 1, true);+ view.setFloat32(base + at(MeshChannel.TexCoord0), UV0[i][0], true);+ view.setFloat32(base + at(MeshChannel.TexCoord0) + 4, UV0[i][1], true);+ view.setFloat32(base + at(MeshChannel.TexCoord1), UV1[i][0], true);+ view.setFloat32(base + at(MeshChannel.TexCoord1) + 4, UV1[i][1], true);+ for (let c = 0; c < 4; c++) view.setUint8(base + at(MeshChannel.Color) + c, 255);+ });-writeFileSync(MESH, encodeMesh({- channels, vertexStride, vertexCount: POSITIONS.length, vertices,- indices: Uint32Array.from([0, 1, 2, 0, 2, 3]),- aabbMin: [-HALF, -HALF, 0], aabbMax: [HALF, HALF, 0],-}));+ writeFileSync(file, encodeMesh({+ channels, vertexStride, vertexCount: POSITIONS.length, vertices,+ indices: Uint32Array.from([0, 1, 2, 0, 2, 3]),+ aabbMin: [-HALF, -HALF, 0], aabbMax: [HALF, HALF, 0],+ }));+}+quad(MESH, false);+quad(MESH_LIT, true);/** Four texels, not two: every gate point then sits between two texels of ONE- * colour, so linear filtering cannot put the answer on a boundary. */-const TEXELS = [[255, 0, 0], [255, 0, 0], [0, 0, 255], [0, 0, 255]];+ * colour, so linear filtering cannot put the answer on a boundary. Irradiance,+ * encoded the way a bake writes it. */+const TEXELS = [[1, 0, 0], [1, 0, 0], [0, 0, 1], [0, 0, 1]];+const encoded = encodeLightmap(Float32Array.from(TEXELS.flat()), TEXELS.length);const crcTable = Array.from({ length: 256 }, (_, n) => {let c = n;@@ -82,7 +93,7 @@ ihdr[8] = 8; // bit depthihdr[9] = 6; // RGBAconst raw = Buffer.concat([Buffer.from([0]), // filter: none- ...TEXELS.map(([r, g, b]) => Buffer.from([r, g, b, 255])),+ Buffer.from(encoded),]);writeFileSync(ATLAS, Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),@@ -91,4 +102,4 @@ writeFileSync(ATLAS, Buffer.concat([chunk('IEND', Buffer.alloc(0)),]));-console.log(`wrote ${path.relative(ROOT, MESH)} and ${path.relative(ROOT, ATLAS)}`);+console.log(`wrote ${path.relative(ROOT, MESH)}, ${path.relative(ROOT, MESH_LIT)} and ${path.relative(ROOT, ATLAS)}`);diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 31d3904de..c27bbcb39 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -1270,6 +1270,14 @@ export const NOTED = {{ note: 'Ambient occlusion works behind another post-process effect' },'fix(render): a shipped game\'s textures are mipmapped':{ note: 'A shipped game\'s textures are sampled through mip levels' },+ 'fix(render): a shipped game samples data textures as data':+ { note: 'A shipped game samples normal maps and roughness maps as data' },+ 'fix(render): normal maps stay on up close':+ { note: 'Normal maps stay on up close' },+ 'feat(bake): the editor bakes a lit surface\'s indirect light off the main thread':+ { note: 'The editor stays responsive while it bakes' },+ 'feat(bake): baked light is a lit surface\'s indirect light':+ { note: 'Baked light is a lit surface\'s indirect light' },'fix(eht): the generator writes LF on every platform':{ internal: 'The engine header tool is a repository generator; on Windows it rewrote every generated file with CRLF, which only a contributor there ever saw.' },};diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjsindex 0bc038d43..cfbbc7c40 100644--- a/tools/renderScenes.mjs+++ b/tools/renderScenes.mjs@@ -125,9 +125,17 @@ export const SCENES = [// the wrong channel turns the halves and swaps two of these four points.{ id: "lightmap-unlit", tier: "pr", webgpu: true, env: { "ESTELLA_VERIFY_SCENE": "/scenes/lightmap-unlit.esscene", "ESTELLA_VERIFY_MANIFEST": "/scenes/lightmap-unlit.textures.json", "ESTELLA_VERIFY_W": "256", "ESTELLA_VERIFY_H": "256", "ESTELLA_VERIFY_STEPS": "2", "ESTELLA_VERIFY_EXPECT": "[{\"x\":0.3,\"y\":0.25,\"rgb\":[0,0,255],\"tol\":30},{\"x\":0.7,\"y\":0.25,\"rgb\":[0,0,255],\"tol\":30},{\"x\":0.3,\"y\":0.75,\"rgb\":[255,0,0],\"tol\":30},{\"x\":0.7,\"y\":0.75,\"rgb\":[255,0,0],\"tol\":30}]" } },// A baked object and an unbaked one in ONE lit frame. Cyan and yellow halves- // say the green sun SURVIVED, so the bake adds rather than replaces; the plain+ // say the green sun SURVIVED, so the bake joins the lamps rather than replacing them; the plain// green quad says an unbaked one is not brightened by an unbound unit's white.{ id: "lightmap-mixed", tier: "pr", webgpu: true, env: { "ESTELLA_VERIFY_SCENE": "/scenes/lightmap-mixed.esscene", "ESTELLA_VERIFY_MANIFEST": "/scenes/lightmap-mixed.textures.json", "ESTELLA_VERIFY_W": "256", "ESTELLA_VERIFY_H": "256", "ESTELLA_VERIFY_STEPS": "2", "ESTELLA_VERIFY_EXPECT": "[{\"x\":0.25,\"y\":0.4,\"rgb\":[0,255,255],\"tol\":40},{\"x\":0.25,\"y\":0.6,\"rgb\":[255,255,0],\"tol\":40},{\"x\":0.75,\"y\":0.4,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.75,\"y\":0.6,\"rgb\":[0,255,0],\"tol\":40}]" } },+ // The same frame under a white sky. A bake is the surface's WHOLE indirect term,+ // so it replaces the sky rather than joining it: the baked halves stay cyan and+ // yellow, where a bake added on top would wash them white like the unbaked quad.+ { id: "lightmap-sky", tier: "pr", webgpu: true, env: { "ESTELLA_VERIFY_SCENE": "/scenes/lightmap-sky.esscene", "ESTELLA_VERIFY_MANIFEST": "/scenes/lightmap-sky.textures.json", "ESTELLA_VERIFY_W": "256", "ESTELLA_VERIFY_H": "256", "ESTELLA_VERIFY_STEPS": "2", "ESTELLA_VERIFY_EXPECT": "[{\"x\":0.25,\"y\":0.4,\"rgb\":[0,255,255],\"tol\":40},{\"x\":0.25,\"y\":0.6,\"rgb\":[255,255,0],\"tol\":40},{\"x\":0.75,\"y\":0.4,\"rgb\":[255,255,255],\"tol\":40},{\"x\":0.75,\"y\":0.6,\"rgb\":[255,255,255],\"tol\":40}]" } },+ // The bake through an imported model's material under an environment: it replaces the+ // environment's diffuse half. The quad carries a normal and the material a tint, so a+ // program that fails to link (seventeen samplers with the batch stream's eight) shows.+ { id: "lightmap-model", tier: "pr", webgpu: true, env: { "ESTELLA_VERIFY_MESH_MATERIAL": "/scenes/lightmap-model/rough.esmaterial", "ESTELLA_VERIFY_SCENE": "/scenes/lightmap-model.esscene", "ESTELLA_VERIFY_MANIFEST": "/scenes/lightmap-model.textures.json", "ESTELLA_VERIFY_W": "256", "ESTELLA_VERIFY_H": "256", "ESTELLA_VERIFY_STEPS": "2", "ESTELLA_VERIFY_EXPECT": "[{\"x\":0.25,\"y\":0.4,\"rgb\":[0,255,255],\"tol\":20},{\"x\":0.25,\"y\":0.6,\"rgb\":[128,255,0],\"tol\":20},{\"x\":0.75,\"y\":0.4,\"rgb\":[29,255,61],\"tol\":20},{\"x\":0.75,\"y\":0.6,\"rgb\":[29,255,61],\"tol\":20}]" } },// Why the rectangle rides the per-object record: ONE mesh and ONE atlas, and// the two objects drawn from them read different halves of it. A rectangle// that belonged to the mesh would paint these two the same colour.