Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop-gpui): weight the glass colour fit as intended and pin the grey axis to Apple's

Richie McIlroy9c73afa305a2
diff --git a/apps/desktop-gpui/glass/presets.json b/apps/desktop-gpui/glass/presets.json
index 40789a0ce..b5b872eb0 100644
--- a/apps/desktop-gpui/glass/presets.json
+++ b/apps/desktop-gpui/glass/presets.json
@@ -1,130 +1,138 @@
{
"clear-dark": {
- "bend": -2.366746425628662,
- "blur_k": 0.17999997735023499,
+ "bend": -2.412919521331787,
+ "blur_k": 0.18000054359436035,
"blur_max": 20.0,
- "glow": -0.00915201473981142,
- "glow_width": 0.5,
+ "glow": -9.978866728488356e-6,
+ "glow_width": 39.30601119995117,
"hairline": [
- 0.5046544075012207, -0.002066596643999219, 1.037916898727417,
- -0.004036169033497572
+ 0.5050199031829834, -0.002001264365389943, 1.0410776138305664,
+ -0.00509136077016592
],
- "lens_curve": 0.3376707434654236,
- "light_angle": 10.696141242980957,
- "line": 0.009427699260413647,
- "line_lit": -0.00020453354227356613,
- "line_width": 0.9371033906936646,
+ "lens_curve": 0.3599303960800171,
+ "light_angle": 2.3112025260925293,
+ "line": 0.0018150180112570524,
+ "line_lit": 0.0017182374140247703,
+ "line_width": 0.994491457939148,
"opacity": 0.6000000238418579,
"poly": [
- 0.9841277003288269, -0.28581157326698303, 0.06853790581226349,
- -0.10551261156797409, -0.019449958577752113, -0.06275196373462677,
- 0.12861721217632294, 0.0336744524538517, -0.02680288627743721, 0.0, 0.0,
- 0.0, 0.09590495377779007, -0.025067875161767006, 0.7507156133651733,
- -0.008180275559425354, -0.03581831976771355, -0.010394089855253696,
- -0.01718660071492195, 0.04081161320209503, 0.02539644204080105,
- -0.005516655743122101, 0.0, 0.0, 0.0, 0.09734207391738892,
- -0.07906761765480042, -0.22363290190696716, 1.016892433166504,
- -0.00731066195294261, -0.06583347171545029, -0.11654830724000931,
- 0.04832758754491806, 0.12703412771224976, 0.01597178541123867, 0.0, 0.0,
- 0.0, 0.09707652777433395
+ 0.6313937902450562, 0.7283032536506653, -0.7202409505844116,
+ 0.7613860964775085, -2.0895676612854004, 1.455474615097046,
+ 0.11192644387483597, 0.08696344494819641, -0.08549253642559052,
+ -0.5280044078826904, 1.2200205326080322, -0.8582108616828918,
+ 0.09805495291948318, -0.07880198210477829, 0.8358877301216125,
+ -0.0669502466917038, 0.0785026028752327, -0.18421262502670288,
+ 0.11133701354265213, 0.045185938477516174, 0.023230290040373802,
+ -0.010092880576848984, -0.06803300976753235, 0.10296168178319931,
+ -0.0751410573720932, 0.09795161336660385, -0.17431367933750153,
+ -0.31713956594467163, 1.1713937520980835, 0.1505192369222641,
+ 0.10798941552639008, -0.3602425456047058, 0.06854856759309769,
+ 0.10419972240924835, 0.021173598244786263, -0.08950604498386383,
+ -0.09568458050489426, 0.12689803540706635, 0.09791429340839386
],
- "rim_k": 0.3009837865829468,
- "rim_max": 26.59674072265625
+ "rim_k": 0.2883424758911133,
+ "rim_max": 24.872886657714844
},
"clear-light": {
- "bend": -2.364307403564453,
- "blur_k": 0.17999984323978424,
+ "bend": -2.4594221115112305,
+ "blur_k": 0.17999997735023499,
"blur_max": 20.0,
- "glow": -0.040041275322437286,
+ "glow": -0.0408473014831543,
"glow_width": 0.5,
"hairline": [
- 0.6467424035072327, -0.017890620976686478, 1.0234696865081787,
- 0.008217902854084969
+ 0.6450185179710388, -0.016545917838811874, 1.0230517387390137,
+ 0.008764644153416157
],
- "lens_curve": 0.33955836296081543,
- "light_angle": 8.900734901428223,
- "line": 0.013842251151800156,
- "line_lit": 0.00113571563269943,
- "line_width": 1.1170105934143066,
+ "lens_curve": 0.318873792886734,
+ "light_angle": 2.6443076133728027,
+ "line": 0.01456276886165142,
+ "line_lit": 0.0015534033300355077,
+ "line_width": 1.097947359085083,
"opacity": 0.6000000238418579,
"poly": [
- 0.8068393468856812, -0.19063682854175568, 0.12205540388822556,
- 0.03810872882604599, 0.05950373411178589, -0.08793330937623978,
- -0.04968729987740517, 0.011197183281183243, -0.03260619565844536, 0.0,
- 0.0, 0.0, 0.27716732025146484, -0.009006494656205177, 0.6790370345115662,
- 0.013659832999110222, -0.02463696524500847, 0.033544085919857025,
- -0.016603535041213036, 0.00851691234856844, 0.0007132220198400319,
- -0.0068999179638922215, 0.0, 0.0, 0.0, 0.278425395488739,
- 0.05969604477286339, -0.09342411160469055, 0.722533643245697,
- -0.04663229361176491, -0.05806506425142288, 0.033827684819698334,
- -0.052240658551454544, 0.10449537634849548, 0.007342542987316847, 0.0,
- 0.0, 0.0, 0.2787947356700897
+ 0.2497211992740631, 0.7583296895027161, -0.36811646819114685,
+ 1.273596167564392, -1.9042826890945435, 0.8599693775177002,
+ -0.0514889694750309, 0.052962444722652435, -0.08220545202493668,
+ -0.7352914810180664, 1.1641223430633545, -0.5389814972877502,
+ 0.2785186767578125, -0.03988504037261009, 0.7219523787498474,
+ -0.007673143874853849, 0.03376581892371178, -0.050814464688301086,
+ 0.03104168362915516, 0.0132481399923563, -0.0016589678125455976,
+ -0.007338891737163067, -0.033974405378103256, 0.04808909818530083,
+ -0.028364654630422592, 0.27844366431236267, -0.0301153976470232,
+ 0.1788342148065567, 0.5316532850265503, 0.18545162677764893,
+ -0.6017318367958069, 0.36461755633354187, -0.07064586132764816,
+ 0.13311389088630676, -0.007584464270621538, -0.13774992525577545,
+ 0.3131157159805298, -0.1805034577846527, 0.2784975469112396
],
- "rim_k": 0.2935454249382019,
- "rim_max": 27.180828094482422
+ "rim_k": 0.2952793836593628,
+ "rim_max": 26.819894790649414
},
"regular-dark": {
- "bend": -1.0383737087249756,
- "blur_k": 0.1399989128112793,
+ "bend": -1.6669726371765137,
+ "blur_k": 0.14000000059604645,
"blur_max": 12.0,
- "glow": 0.023018531501293182,
- "glow_width": 47.50996780395508,
+ "glow": 0.024336621165275574,
+ "glow_width": 51.54517364501953,
"hairline": [
- 0.265051931142807, 0.09913472086191177, 0.5498596429824829,
- 0.042205967009067535
+ 0.2600359320640564, 0.103030264377594, 0.5471664667129517,
+ 0.04482661187648773
],
- "lens_curve": 0.6115574836730957,
- "light_angle": 3.5436832904815674,
- "line": 0.013988529331982136,
- "line_lit": -5.383496682043187e-5,
- "line_width": 0.516719400882721,
+ "lens_curve": 0.5919271111488342,
+ "light_angle": -2.782675266265869,
+ "line": 0.011403294280171394,
+ "line_lit": 0.011242559179663658,
+ "line_width": 0.3977275788784027,
"opacity": 0.6000000238418579,
"poly": [
- 1.1429176330566406, -0.10875950753688812, 0.033222246915102005,
- -0.08781613409519196, -0.13997182250022888, -0.032387249171733856,
- -0.3350599706172943, 0.02284449338912964, -0.0969463512301445, 0.0, 0.0,
- 0.0, 0.06109626591205597, -0.14081989228725433, 1.3113867044448853,
- -0.13325585424900055, 0.012389129027724266, -0.6814408302307129,
- 0.0769672617316246, 0.005131110083311796, -0.11113206297159195,
- 0.055657077580690384, 0.0, 0.0, 0.0, 0.06288916617631912,
- -0.14669793844223022, -0.0684649795293808, 1.239702582359314,
- 0.011958428658545017, -0.1758630871772766, -0.09301606565713882,
- 0.12923042476177216, -0.4333122670650482, -0.0655086413025856, 0.0, 0.0,
- 0.0, 0.06273098289966583
+ 1.1208113431930542, 0.769611120223999, -0.9219794273376465,
+ 0.1965949982404709, -1.9167686700820923, 1.746425747871399,
+ -0.3972877562046051, 0.10475105792284012, -0.1348458230495453,
+ -0.213811457157135, 1.0382335186004639, -1.0049047470092773,
+ 0.06521148979663849, -0.11392313241958618, 1.4205176830291748,
+ -0.28513824939727783, 0.0018862647702917457, -0.9691377878189087,
+ 0.4069260358810425, 0.0062097590416669846, -0.0784282386302948,
+ 0.034528374671936035, -0.00854511745274067, 0.1753605753183365,
+ -0.20346999168395996, 0.06513476371765137, -0.15799254179000854,
+ -0.39501243829727173, 1.5855051279067993, -0.05833205580711365,
+ 0.4637044072151184, -0.6609259247779846, 0.17491891980171204,
+ -0.48810815811157227, -0.048988454043865204, 0.038651589304208755,
+ -0.36601346731185913, 0.29942595958709717, 0.06502226740121841
],
- "rim_k": 0.0955091044306755,
- "rim_max": 43.95122528076172
+ "rim_k": 0.21779286861419678,
+ "rim_max": 17.012699127197266
},
"regular-light": {
- "bend": -1.6921217441558838,
+ "bend": -1.6906808614730835,
"blur_k": 0.14000000059604645,
"blur_max": 12.0,
- "glow": -0.06775760650634766,
+ "glow": -0.06975674629211426,
"glow_width": 0.5,
"hairline": [
- 0.6670563817024231, 0.017260314896702766, 0.7883668541908264,
- 0.007549159694463015
+ 0.6683441400527954, 0.015820689499378204, 0.7885841131210327,
+ 0.007480344735085964
],
- "lens_curve": 0.576151967048645,
- "light_angle": 2.86551833152771,
- "line": 0.012727930210530758,
- "line_lit": 0.0012256903573870659,
- "line_width": 1.5420403480529785,
+ "lens_curve": 0.5981463193893433,
+ "light_angle": 5.205510139465332,
+ "line": 0.01358448900282383,
+ "line_lit": -0.0012929972726851702,
+ "line_width": 1.5013341903686523,
"opacity": 0.6000000238418579,
"poly": [
- 0.7772780656814575, -0.45734652876853943, 0.2029036283493042,
- -0.1445373296737671, 0.028123168274760246, -0.15287674963474274,
- 0.20918069779872894, 0.03389207646250725, -0.0789894387125969, 0.0, 0.0,
- 0.0, 0.5196360945701599, -0.05892333388328552, 0.5539849996566772,
- -0.04516340047121048, -0.038535263389348984, -0.03162488341331482,
- 0.007563223596662283, 0.03239148110151291, -0.00026807302492670715,
- 0.0019051238195970654, 0.0, 0.0, 0.0, 0.5209547877311707,
- 0.16917257010936737, -0.3096109628677368, 0.619947612285614,
- -0.12055128067731857, -0.14295552670955658, -0.1775696575641632,
- -0.13636651635169983, 0.48980438709259033, 0.027854571118950844, 0.0, 0.0,
- 0.0, 0.5214924812316895
+ -0.138549342751503, 0.7256880402565002, -0.1833912432193756,
+ 1.8144844770431519, -2.4605472087860107, 0.6123811602592468,
+ 0.23255813121795654, 0.05579162761569023, -0.12572336196899414,
+ -1.1628233194351196, 1.4883190393447876, -0.43835973739624023,
+ 0.5214229226112366, -0.0343957282602787, 0.4276241362094879,
+ 0.04451335221529007, -0.1150304526090622, 0.21809197962284088,
+ -0.13724924623966217, 0.03976645693182945, -0.017057476565241814,
+ 0.0032571046613156796, 0.050204869359731674, -0.13996750116348267,
+ 0.0802760049700737, 0.5213379263877869, 0.10205833613872528,
+ 0.3425259590148926, -0.017469502985477448, 0.12757959961891174,
+ -1.446061372756958, 0.9996414184570312, -0.17898792028427124,
+ 0.5396572947502136, -0.002463854616507888, -0.1542862057685852,
+ 0.762222409248352, -0.6541531682014465, 0.5215706825256348
],
- "rim_k": 0.21131862699985504,
- "rim_max": 16.063199996948242
+ "rim_k": 0.2092672884464264,
+ "rim_max": 15.961286544799805
}
}
diff --git a/apps/desktop-gpui/glass/src/bin/glass-fit.rs b/apps/desktop-gpui/glass/src/bin/glass-fit.rs
index e9ca249f1..0ea2d0b9a 100644
--- a/apps/desktop-gpui/glass/src/bin/glass-fit.rs
+++ b/apps/desktop-gpui/glass/src/bin/glass-fit.rs
@@ -47,6 +47,9 @@ struct Sample {
const PAD: f32 = 110.;
+/// How much more the black, grey and white scenes count in the colour fit.
+const NEUTRAL_WEIGHT: f64 = 12.;
+
fn main() {
let args: Vec<String> = std::env::args().collect();
let reference = PathBuf::from(&args[1]);
@@ -99,6 +102,14 @@ fn main() {
.as_ref()
.and_then(|all| serde_json::from_value::<GlassMaterial>(all.get(&preset)?.clone()).ok())
{
+ // `GLASS_RESOLVE=1`: keep the given blur, lensing and lighting but
+ // solve the colour transform again.
+ Some(material) if std::env::var_os("GLASS_RESOLVE").is_some() => {
+ prepare(&mut samples, &shapes, &material);
+ let (loss, material) = evaluate(&material, &shapes, &samples);
+ eprintln!("{preset}: re-solved colour, loss {loss:.2}");
+ material
+ }
Some(material) => material,
None => fit(&preset, &mut samples, &shapes),
};
@@ -358,7 +369,15 @@ fn normal_equations(material: &GlassMaterial, shapes: &[Shape], samples: &[Sampl
.map(|sample| {
scope.spawn(move || {
let mut normal = Normal::new();
+ // Flat backdrops pin the grey axis, where any error shows
+ // most; a handful of colourful scenes would otherwise
+ // outvote them.
+ let neutral = ["white-", "black-", "gray-"]
+ .iter()
+ .any(|prefix| sample.name.starts_with(prefix));
+ let scene_weight = if neutral { NEUTRAL_WEIGHT } else { 1. };
for_each_glass_pixel(material, shapes, sample, true, |glass, _, x, y, weight| {
+ let weight = weight * scene_weight;
let under = sample.backdrop.get(x, y);
let under = model::under_with_hairline(
glass,
@@ -374,9 +393,9 @@ fn normal_equations(material: &GlassMaterial, shapes: &[Shape], samples: &[Sampl
return;
}
let features = model::poly_features(glass.source);
- let weight = (glass.coverage * glass.scale) as f64;
+ let scale = (glass.coverage * glass.scale) as f64;
let row: [f64; POLY_TERMS] =
- std::array::from_fn(|i| features[i] as f64 * weight);
+ std::array::from_fn(|i| features[i] as f64 * scale);
for i in 0..POLY_TERMS {
for j in i..POLY_TERMS {
normal.ata[i][j] += weight * row[i] * row[j];