@sessile/core 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -373
- package/dist/contracts.d.ts +19 -0
- package/dist/entries/internal.d.ts +14 -0
- package/dist/entries/internal.js +14 -0
- package/dist/entries/legibility.d.ts +8 -0
- package/dist/entries/legibility.js +8 -0
- package/dist/entries/overlay.d.ts +9 -0
- package/dist/entries/overlay.js +8 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.js +7 -6
- package/dist/legibility.js +6 -0
- package/dist/optics.js +30 -0
- package/dist/overlayRenderer.d.ts +1 -1
- package/dist/overlayRenderer.js +326 -295
- package/dist/refractMap.d.ts +11 -1
- package/dist/refractMap.js +39 -16
- package/dist/refractProfile.d.ts +41 -2
- package/dist/refractProfile.js +69 -1
- package/dist/refractTiles.d.ts +1 -1
- package/dist/refractTiles.js +13 -9
- package/package.json +14 -1
package/dist/refractMap.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface RefractMapParams {
|
|
|
15
15
|
field: GlassFieldState;
|
|
16
16
|
bezel: number;
|
|
17
17
|
mapScale?: number;
|
|
18
|
-
/** Refraction cross-section profile (`'squircle'`, `'circle'`, `'parabolic'`, `'lip'`, or custom height fn). */
|
|
18
|
+
/** Refraction cross-section profile (`'squircle'`, `'c2-squircle'`, `'circle'`, `'parabolic'`, `'lip'`, or custom height fn). */
|
|
19
19
|
profile?: RefractionProfileSpec;
|
|
20
20
|
/** Index of refraction (`1` = air, `1.5` = glass; defaults to `1.5`). */
|
|
21
21
|
ior?: number;
|
|
@@ -40,6 +40,16 @@ export interface RefractMapBuilder {
|
|
|
40
40
|
export declare const tmpCornerGeom: Float64Array<ArrayBuffer>;
|
|
41
41
|
/** @internal */
|
|
42
42
|
export declare function ensureScanlineCapacity(needed: number): Uint8Array;
|
|
43
|
+
/**
|
|
44
|
+
* Encodes normalized bezel rim reflection weight into the displacement map's blue channel in
|
|
45
|
+
* `[128, 255]`: `255` at the outer rim (`t = 0`), smooth quadratic falloff to `128` at the
|
|
46
|
+
* plateau (`t >= 1`). Keeping outside/plateau at `128` preserves existing neutral RGBA contracts
|
|
47
|
+
* while letting SVG `feColorMatrix` extract an exact `[0, 1]` rim mask via
|
|
48
|
+
* `A = (255 / 127) * B - (128 / 127)`.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export declare function encodeRimMaskChannel(t: number): number;
|
|
43
53
|
/** @internal */
|
|
44
54
|
export declare function encodeStoredRgbaPngDataUrl(scanlines: Uint8Array, pngW: number, pngH: number): string;
|
|
45
55
|
/** @internal */
|
package/dist/refractMap.js
CHANGED
|
@@ -168,6 +168,21 @@ function ensureSoaCapacity(needed) {
|
|
|
168
168
|
rowQy = new Float64Array(nextCap);
|
|
169
169
|
rowSy = new Float64Array(nextCap);
|
|
170
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Encodes normalized bezel rim reflection weight into the displacement map's blue channel in
|
|
173
|
+
* `[128, 255]`: `255` at the outer rim (`t = 0`), smooth quadratic falloff to `128` at the
|
|
174
|
+
* plateau (`t >= 1`). Keeping outside/plateau at `128` preserves existing neutral RGBA contracts
|
|
175
|
+
* while letting SVG `feColorMatrix` extract an exact `[0, 1]` rim mask via
|
|
176
|
+
* `A = (255 / 127) * B - (128 / 127)`.
|
|
177
|
+
*
|
|
178
|
+
* @internal
|
|
179
|
+
*/
|
|
180
|
+
export function encodeRimMaskChannel(t) {
|
|
181
|
+
if (t >= 1)
|
|
182
|
+
return 128;
|
|
183
|
+
const u = t <= 0 ? 1 : 1 - t;
|
|
184
|
+
return 128 + Math.round(127 * u * u);
|
|
185
|
+
}
|
|
171
186
|
/** @internal */
|
|
172
187
|
export function encodeStoredRgbaPngDataUrl(scanlines, pngW, pngH) {
|
|
173
188
|
const rowBytes = 1 + pngW * 4;
|
|
@@ -419,11 +434,12 @@ function rasterizeSingleRectScanlines(scanlines, pngW, pngH, originX, originY, s
|
|
|
419
434
|
const edgeX = halfW - absDx;
|
|
420
435
|
if (bendCorners && edgeX < effBezel && edgeY < effBezel) {
|
|
421
436
|
computeCornerGeometry(edgeX > 0 ? edgeX : 0, edgeY > 0 ? edgeY : 0, rad, effBezel);
|
|
422
|
-
const
|
|
437
|
+
const tCorner = tmpCornerGeom[2] * invBezel;
|
|
438
|
+
const m = sampleRefractionLut(normLut, tCorner) * localScale;
|
|
423
439
|
const amp = clampAmp(m * 127);
|
|
424
440
|
scanlines[offset++] = clampChannel(Math.round(128 - sx * tmpCornerGeom[0] * amp));
|
|
425
441
|
scanlines[offset++] = clampChannel(Math.round(128 - sy * tmpCornerGeom[1] * amp));
|
|
426
|
-
scanlines[offset++] =
|
|
442
|
+
scanlines[offset++] = encodeRimMaskChannel(tCorner);
|
|
427
443
|
scanlines[offset++] = alpha;
|
|
428
444
|
}
|
|
429
445
|
else if (distIn >= effBezel) {
|
|
@@ -433,11 +449,12 @@ function rasterizeSingleRectScanlines(scanlines, pngW, pngH, originX, originY, s
|
|
|
433
449
|
scanlines[offset++] = alpha;
|
|
434
450
|
}
|
|
435
451
|
else {
|
|
436
|
-
const
|
|
452
|
+
const tEdge = distIn * invBezel;
|
|
453
|
+
const m = sampleRefractionLut(normLut, tEdge) * localScale;
|
|
437
454
|
const amp = clampAmp(m * 127);
|
|
438
455
|
scanlines[offset++] = clampChannel(Math.round(128 - gx * amp));
|
|
439
456
|
scanlines[offset++] = clampChannel(Math.round(128 - gy * amp));
|
|
440
|
-
scanlines[offset++] =
|
|
457
|
+
scanlines[offset++] = encodeRimMaskChannel(tEdge);
|
|
441
458
|
scanlines[offset++] = alpha;
|
|
442
459
|
}
|
|
443
460
|
}
|
|
@@ -643,11 +660,12 @@ function rasterizeDualShapeScanlines(scanlines, pngW, pngH, originX, originY, st
|
|
|
643
660
|
const winSy = winIsA ? pSy : dSy;
|
|
644
661
|
if (winRad > 0 && winRad < winBezel && winEdgeX < winBezel && winEdgeY < winBezel) {
|
|
645
662
|
computeCornerGeometry(winEdgeX > 0 ? winEdgeX : 0, winEdgeY > 0 ? winEdgeY : 0, winRad, winBezel);
|
|
646
|
-
const
|
|
663
|
+
const tCorner = tmpCornerGeom[2] * winInvBezel;
|
|
664
|
+
const m = sampleRefractionLut(normLut, tCorner) * winScale;
|
|
647
665
|
const amp = clampAmp(m * 127);
|
|
648
666
|
scanlines[offset++] = clampChannel(Math.round(128 - winSx * tmpCornerGeom[0] * amp));
|
|
649
667
|
scanlines[offset++] = clampChannel(Math.round(128 - winSy * tmpCornerGeom[1] * amp));
|
|
650
|
-
scanlines[offset++] =
|
|
668
|
+
scanlines[offset++] = encodeRimMaskChannel(tCorner);
|
|
651
669
|
scanlines[offset++] = alpha;
|
|
652
670
|
}
|
|
653
671
|
else if (distIn >= winBezel) {
|
|
@@ -657,11 +675,12 @@ function rasterizeDualShapeScanlines(scanlines, pngW, pngH, originX, originY, st
|
|
|
657
675
|
scanlines[offset++] = alpha;
|
|
658
676
|
}
|
|
659
677
|
else {
|
|
660
|
-
const
|
|
678
|
+
const tEdge = distIn * winInvBezel;
|
|
679
|
+
const m = sampleRefractionLut(normLut, tEdge) * winScale;
|
|
661
680
|
const amp = clampAmp(m * 127);
|
|
662
681
|
scanlines[offset++] = clampChannel(Math.round(128 - gx * amp));
|
|
663
682
|
scanlines[offset++] = clampChannel(Math.round(128 - gy * amp));
|
|
664
|
-
scanlines[offset++] =
|
|
683
|
+
scanlines[offset++] = encodeRimMaskChannel(tEdge);
|
|
665
684
|
scanlines[offset++] = alpha;
|
|
666
685
|
}
|
|
667
686
|
}
|
|
@@ -680,11 +699,12 @@ function rasterizeDualShapeScanlines(scanlines, pngW, pngH, originX, originY, st
|
|
|
680
699
|
const nx = gx * invG;
|
|
681
700
|
const ny = gy * invG;
|
|
682
701
|
const blendScale = blendBezel * invSafeBezel;
|
|
683
|
-
const
|
|
702
|
+
const tBlend = distIn / blendBezel;
|
|
703
|
+
const m = sampleRefractionLut(normLut, tBlend) * blendScale;
|
|
684
704
|
const amp = clampAmp(m * 127);
|
|
685
705
|
scanlines[offset++] = clampChannel(Math.round(128 + nx * amp));
|
|
686
706
|
scanlines[offset++] = clampChannel(Math.round(128 + ny * amp));
|
|
687
|
-
scanlines[offset++] =
|
|
707
|
+
scanlines[offset++] = encodeRimMaskChannel(tBlend);
|
|
688
708
|
scanlines[offset++] = alpha;
|
|
689
709
|
}
|
|
690
710
|
}
|
|
@@ -950,11 +970,12 @@ function rasterizeMultiShapeScanlines(scanlines, pngW, pngH, originX, originY, s
|
|
|
950
970
|
const winEdgeY = soaHalfH[winIdx] - rowAbsDy[winIdx];
|
|
951
971
|
if (winRad > 0 && winRad < winBezel && winEdgeX < winBezel && winEdgeY < winBezel) {
|
|
952
972
|
computeCornerGeometry(winEdgeX > 0 ? winEdgeX : 0, winEdgeY > 0 ? winEdgeY : 0, winRad, winBezel);
|
|
953
|
-
const
|
|
973
|
+
const tCorner = tmpCornerGeom[2] * soaInvBezel[winIdx];
|
|
974
|
+
const m = sampleRefractionLut(normLut, tCorner) * winScale;
|
|
954
975
|
const amp = clampAmp(m * 127);
|
|
955
976
|
scanlines[offset++] = clampChannel(Math.round(128 - winSx * tmpCornerGeom[0] * amp));
|
|
956
977
|
scanlines[offset++] = clampChannel(Math.round(128 - rowSy[winIdx] * tmpCornerGeom[1] * amp));
|
|
957
|
-
scanlines[offset++] =
|
|
978
|
+
scanlines[offset++] = encodeRimMaskChannel(tCorner);
|
|
958
979
|
scanlines[offset++] = alpha;
|
|
959
980
|
}
|
|
960
981
|
else if (distIn >= winBezel) {
|
|
@@ -964,11 +985,12 @@ function rasterizeMultiShapeScanlines(scanlines, pngW, pngH, originX, originY, s
|
|
|
964
985
|
scanlines[offset++] = alpha;
|
|
965
986
|
}
|
|
966
987
|
else {
|
|
967
|
-
const
|
|
988
|
+
const tEdge = distIn * soaInvBezel[winIdx];
|
|
989
|
+
const m = sampleRefractionLut(normLut, tEdge) * winScale;
|
|
968
990
|
const amp = clampAmp(m * 127);
|
|
969
991
|
scanlines[offset++] = clampChannel(Math.round(128 - accGx * amp));
|
|
970
992
|
scanlines[offset++] = clampChannel(Math.round(128 - accGy * amp));
|
|
971
|
-
scanlines[offset++] =
|
|
993
|
+
scanlines[offset++] = encodeRimMaskChannel(tEdge);
|
|
972
994
|
scanlines[offset++] = alpha;
|
|
973
995
|
}
|
|
974
996
|
}
|
|
@@ -985,11 +1007,12 @@ function rasterizeMultiShapeScanlines(scanlines, pngW, pngH, originX, originY, s
|
|
|
985
1007
|
const nx = accGx * invG;
|
|
986
1008
|
const ny = accGy * invG;
|
|
987
1009
|
const blendScale = accBezel * invSafeBezel;
|
|
988
|
-
const
|
|
1010
|
+
const tBlend = distIn / accBezel;
|
|
1011
|
+
const m = sampleRefractionLut(normLut, tBlend) * blendScale;
|
|
989
1012
|
const amp = clampAmp(m * 127);
|
|
990
1013
|
scanlines[offset++] = clampChannel(Math.round(128 + nx * amp));
|
|
991
1014
|
scanlines[offset++] = clampChannel(Math.round(128 + ny * amp));
|
|
992
|
-
scanlines[offset++] =
|
|
1015
|
+
scanlines[offset++] = encodeRimMaskChannel(tBlend);
|
|
993
1016
|
scanlines[offset++] = alpha;
|
|
994
1017
|
}
|
|
995
1018
|
}
|
package/dist/refractProfile.d.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* Geometric-optics 1D bezel refraction profile LUT (Snell's law + anti-caustic fold clamping).
|
|
3
3
|
*
|
|
4
4
|
* Precomputes 256-sample `Float32Array` lookup tables for named bezel cross-sections
|
|
5
|
-
* (`squircle`, `circle`, `parabolic`, `lip`) or custom height functions, allowing per-pixel
|
|
5
|
+
* (`squircle`, `c2-squircle`, `circle`, `parabolic`, `lip`) or custom height functions, allowing per-pixel
|
|
6
6
|
* displacement map rasterizers to evaluate physical ray refraction via cheap linear
|
|
7
7
|
* interpolation with zero runtime dependencies or per-frame GC churn.
|
|
8
8
|
*
|
|
9
9
|
* SPDX-License-Identifier: MPL-2.0
|
|
10
10
|
*/
|
|
11
|
-
export type RefractionProfileName = 'squircle' | 'circle' | 'parabolic' | 'lip';
|
|
11
|
+
export type RefractionProfileName = 'squircle' | 'c2-squircle' | 'circle' | 'parabolic' | 'lip';
|
|
12
12
|
export type BezelHeightProfileName = RefractionProfileName;
|
|
13
13
|
/** Normalized bezel height function `f(t)` in `[0, 1]` from outer edge (`t=0`) to plateau (`t=1`). */
|
|
14
14
|
export type BezelHeightFn = (t: number) => number;
|
|
@@ -58,8 +58,34 @@ export interface BezelRayTrace {
|
|
|
58
58
|
/** Inward horizontal displacement where the refracted ray lands, in CSS px. */
|
|
59
59
|
shift: number;
|
|
60
60
|
}
|
|
61
|
+
/** Per-channel refractive indices `(nR, nG, nB)` derived from Cauchy's dispersion model. */
|
|
62
|
+
export interface CauchyChannelIor {
|
|
63
|
+
r: number;
|
|
64
|
+
g: number;
|
|
65
|
+
b: number;
|
|
66
|
+
}
|
|
67
|
+
/** Per-channel displacement scales `(scaleR, scaleG, scaleB)` in CSS px. */
|
|
68
|
+
export interface CauchyChannelScales {
|
|
69
|
+
r: number;
|
|
70
|
+
g: number;
|
|
71
|
+
b: number;
|
|
72
|
+
}
|
|
73
|
+
export interface CauchyDispersionScaleOptions {
|
|
74
|
+
/** Base green-channel (`d`-line) displacement scale in CSS px. */
|
|
75
|
+
baseScale: number;
|
|
76
|
+
/** Base refractive index (`n_d`, defaults to `1.5`). */
|
|
77
|
+
ior?: number;
|
|
78
|
+
/** Abbe number `V_d = (n_d - 1) / (n_F - n_C)`; lower values disperse more strongly (`<= 0` disables). */
|
|
79
|
+
abbeNumber: number;
|
|
80
|
+
}
|
|
61
81
|
export declare const DEFAULT_REFRACTION_SAMPLES = 256;
|
|
62
82
|
export declare const DEFAULT_REFRACTION_IOR = 1.5;
|
|
83
|
+
/** Fraunhofer C (656.3 nm), d (587.6 nm), and F (486.1 nm) wavelengths in micrometers. */
|
|
84
|
+
export declare const FRAUNHOFER_WAVELENGTHS_UM: {
|
|
85
|
+
readonly r: 0.6563;
|
|
86
|
+
readonly g: 0.5876;
|
|
87
|
+
readonly b: 0.4861;
|
|
88
|
+
};
|
|
63
89
|
/** Maximum inward displacement decrease per px (`-d(shift)/du < 1`) to keep mapping injective. */
|
|
64
90
|
export declare const CAUSTIC_FOLD_LIMIT = 0.85;
|
|
65
91
|
/** Lower bound on blended SDF gradient norm in `smin` necks to avoid 180-degree saddle flips. */
|
|
@@ -82,3 +108,16 @@ export declare function resolveRefractionProfileLut(options?: RefractionProfileO
|
|
|
82
108
|
export declare function sampleRefractionLut(table: Float32Array, t: number): number;
|
|
83
109
|
/** Traces a vertical view ray through the bezel at `d` px inward from the outline. */
|
|
84
110
|
export declare function traceBezelRay(input: BezelRayTraceInput, d: number): BezelRayTrace;
|
|
111
|
+
/**
|
|
112
|
+
* Computes per-channel RGB refractive indices `(n_C, n_d, n_F)` from a base index `ior` (`n_d`)
|
|
113
|
+
* and Abbe number `abbeNumber` (`V_d`) using the 2-term Cauchy dispersion relation
|
|
114
|
+
* `n(lambda) = A + B / lambda^2`.
|
|
115
|
+
*/
|
|
116
|
+
export declare function computeCauchyIor(ior: number, abbeNumber: number): CauchyChannelIor;
|
|
117
|
+
/**
|
|
118
|
+
* Derives physical per-channel RGB displacement scales from paraxial Snell's law
|
|
119
|
+
* (`deviation(n) / deviation(n_d) = (1 - 1 / n) / (1 - 1 / n_d)`) combined with the
|
|
120
|
+
* 2-term Cauchy dispersion model (`computeCauchyIor`). Runs in O(1) with zero allocations
|
|
121
|
+
* and remains well-behaved even when the bezel LUT is anti-caustic clamped.
|
|
122
|
+
*/
|
|
123
|
+
export declare function computeCauchyDispersionScales(options: CauchyDispersionScaleOptions): CauchyChannelScales;
|
package/dist/refractProfile.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Geometric-optics 1D bezel refraction profile LUT (Snell's law + anti-caustic fold clamping).
|
|
3
3
|
*
|
|
4
4
|
* Precomputes 256-sample `Float32Array` lookup tables for named bezel cross-sections
|
|
5
|
-
* (`squircle`, `circle`, `parabolic`, `lip`) or custom height functions, allowing per-pixel
|
|
5
|
+
* (`squircle`, `c2-squircle`, `circle`, `parabolic`, `lip`) or custom height functions, allowing per-pixel
|
|
6
6
|
* displacement map rasterizers to evaluate physical ray refraction via cheap linear
|
|
7
7
|
* interpolation with zero runtime dependencies or per-frame GC churn.
|
|
8
8
|
*
|
|
@@ -10,15 +10,40 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export const DEFAULT_REFRACTION_SAMPLES = 256;
|
|
12
12
|
export const DEFAULT_REFRACTION_IOR = 1.5;
|
|
13
|
+
/** Fraunhofer C (656.3 nm), d (587.6 nm), and F (486.1 nm) wavelengths in micrometers. */
|
|
14
|
+
export const FRAUNHOFER_WAVELENGTHS_UM = {
|
|
15
|
+
r: 0.6563,
|
|
16
|
+
g: 0.5876,
|
|
17
|
+
b: 0.4861,
|
|
18
|
+
};
|
|
19
|
+
// Normalized 2-term Cauchy offsets `(lambda^-2 - lambda_d^-2) / (lambda_F^-2 - lambda_C^-2)`.
|
|
20
|
+
// By construction `CAUCHY_B_FRAC - CAUCHY_R_FRAC === 1`, preserving `n_F - n_C = (n_d - 1) / V_d`
|
|
21
|
+
// while capturing the physical ~2.3x stronger short-wavelength (blue) bending relative to green.
|
|
22
|
+
const INV_C2 = 1 / (FRAUNHOFER_WAVELENGTHS_UM.r * FRAUNHOFER_WAVELENGTHS_UM.r);
|
|
23
|
+
const INV_D2 = 1 / (FRAUNHOFER_WAVELENGTHS_UM.g * FRAUNHOFER_WAVELENGTHS_UM.g);
|
|
24
|
+
const INV_F2 = 1 / (FRAUNHOFER_WAVELENGTHS_UM.b * FRAUNHOFER_WAVELENGTHS_UM.b);
|
|
25
|
+
const CAUCHY_R_FRAC = (INV_C2 - INV_D2) / (INV_F2 - INV_C2);
|
|
26
|
+
const CAUCHY_B_FRAC = (INV_F2 - INV_D2) / (INV_F2 - INV_C2);
|
|
13
27
|
/** Maximum inward displacement decrease per px (`-d(shift)/du < 1`) to keep mapping injective. */
|
|
14
28
|
export const CAUSTIC_FOLD_LIMIT = 0.85;
|
|
15
29
|
/** Lower bound on blended SDF gradient norm in `smin` necks to avoid 180-degree saddle flips. */
|
|
16
30
|
export const NORMAL_FLOOR = 0.25;
|
|
17
31
|
const MAX_LUT_CACHE_ENTRIES = 64;
|
|
18
32
|
const squircleHeight = (t) => Math.pow(Math.max(0, 1 - Math.pow(Math.max(0, 1 - t), 4)), 0.25);
|
|
33
|
+
/**
|
|
34
|
+
* C2-continuous quartic bezel cross-section (`1 - (1 - t)^4`): finite slope at the outer rim
|
|
35
|
+
* (`f'(0) = 4`) and vanishing first and second derivatives at the plateau (`f'(1) = f''(1) = 0`),
|
|
36
|
+
* eliminating the curvature jump where circular/parabolic bezels meet the flat center.
|
|
37
|
+
*/
|
|
38
|
+
const c2SquircleHeight = (t) => {
|
|
39
|
+
const u = Math.min(1, Math.max(0, 1 - t));
|
|
40
|
+
const u2 = u * u;
|
|
41
|
+
return 1 - u2 * u2;
|
|
42
|
+
};
|
|
19
43
|
/** Built-in physical bezel cross-section height functions (`t = 0` outer rim, `t = 1` plateau). */
|
|
20
44
|
export const BEZEL_HEIGHT_PROFILES = {
|
|
21
45
|
squircle: squircleHeight,
|
|
46
|
+
'c2-squircle': c2SquircleHeight,
|
|
22
47
|
circle: (t) => Math.sqrt(Math.max(0, 1 - (1 - t) * (1 - t))),
|
|
23
48
|
parabolic: (t) => 1 - (1 - t) * (1 - t),
|
|
24
49
|
lip: (t) => squircleHeight(t) + 0.14 * Math.pow(Math.sin(Math.PI * t), 2),
|
|
@@ -187,3 +212,46 @@ export function traceBezelRay(input, d) {
|
|
|
187
212
|
shift: ior <= 1 + 1e-6 || thickness <= 0 ? 0 : height * Math.tan(deviation),
|
|
188
213
|
};
|
|
189
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Computes per-channel RGB refractive indices `(n_C, n_d, n_F)` from a base index `ior` (`n_d`)
|
|
217
|
+
* and Abbe number `abbeNumber` (`V_d`) using the 2-term Cauchy dispersion relation
|
|
218
|
+
* `n(lambda) = A + B / lambda^2`.
|
|
219
|
+
*/
|
|
220
|
+
export function computeCauchyIor(ior, abbeNumber) {
|
|
221
|
+
const safeIor = Math.max(1, Number.isFinite(ior) ? ior : DEFAULT_REFRACTION_IOR);
|
|
222
|
+
if (safeIor <= 1 + 1e-6 || !Number.isFinite(abbeNumber) || abbeNumber <= 0) {
|
|
223
|
+
return { r: safeIor, g: safeIor, b: safeIor };
|
|
224
|
+
}
|
|
225
|
+
const deltaN = (safeIor - 1) / abbeNumber;
|
|
226
|
+
return {
|
|
227
|
+
r: Math.max(1, safeIor + CAUCHY_R_FRAC * deltaN),
|
|
228
|
+
g: safeIor,
|
|
229
|
+
b: safeIor + CAUCHY_B_FRAC * deltaN,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Derives physical per-channel RGB displacement scales from paraxial Snell's law
|
|
234
|
+
* (`deviation(n) / deviation(n_d) = (1 - 1 / n) / (1 - 1 / n_d)`) combined with the
|
|
235
|
+
* 2-term Cauchy dispersion model (`computeCauchyIor`). Runs in O(1) with zero allocations
|
|
236
|
+
* and remains well-behaved even when the bezel LUT is anti-caustic clamped.
|
|
237
|
+
*/
|
|
238
|
+
export function computeCauchyDispersionScales(options) {
|
|
239
|
+
const baseScale = Number.isFinite(options.baseScale) && options.baseScale > 0 ? options.baseScale : 0;
|
|
240
|
+
if (baseScale <= 0) {
|
|
241
|
+
return { r: 0, g: 0, b: 0 };
|
|
242
|
+
}
|
|
243
|
+
const rawIor = options.ior;
|
|
244
|
+
const safeIor = Math.max(1, rawIor !== undefined && Number.isFinite(rawIor) ? rawIor : DEFAULT_REFRACTION_IOR);
|
|
245
|
+
if (safeIor <= 1 + 1e-6 || !Number.isFinite(options.abbeNumber) || options.abbeNumber <= 0) {
|
|
246
|
+
return { r: baseScale, g: baseScale, b: baseScale };
|
|
247
|
+
}
|
|
248
|
+
const ch = computeCauchyIor(safeIor, options.abbeNumber);
|
|
249
|
+
const refFactor = 1 - 1 / ch.g;
|
|
250
|
+
const rRatio = (1 - 1 / ch.r) / refFactor;
|
|
251
|
+
const bRatio = (1 - 1 / ch.b) / refFactor;
|
|
252
|
+
return {
|
|
253
|
+
r: Math.max(0, baseScale * rRatio),
|
|
254
|
+
g: baseScale,
|
|
255
|
+
b: Math.max(0, baseScale * bRatio),
|
|
256
|
+
};
|
|
257
|
+
}
|
package/dist/refractTiles.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface RefractTileParams {
|
|
|
19
19
|
bezel: number;
|
|
20
20
|
/** Optional logical CSS corner tile size; defaults to `ceil(max(radius, bezel))`. */
|
|
21
21
|
slice?: number;
|
|
22
|
-
/** Refraction cross-section profile (`'squircle'`, `'circle'`, `'parabolic'`, `'lip'`, or custom height fn). */
|
|
22
|
+
/** Refraction cross-section profile (`'squircle'`, `'c2-squircle'`, `'circle'`, `'parabolic'`, `'lip'`, or custom height fn). */
|
|
23
23
|
profile?: RefractionProfileSpec;
|
|
24
24
|
/** Index of refraction (`1` = air, `1.5` = glass; defaults to `1.5`). */
|
|
25
25
|
ior?: number;
|
package/dist/refractTiles.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* SPDX-License-Identifier: MPL-2.0
|
|
12
12
|
*/
|
|
13
|
-
import { clampAmp, clampChannel, computeCornerGeometry, encodeStoredRgbaPngDataUrl, ensureScanlineCapacity, tmpCornerGeom, } from "./refractMap.js";
|
|
13
|
+
import { clampAmp, clampChannel, computeCornerGeometry, encodeRimMaskChannel, encodeStoredRgbaPngDataUrl, ensureScanlineCapacity, tmpCornerGeom, } from "./refractMap.js";
|
|
14
14
|
import { DEFAULT_REFRACTION_IOR, getRefractionProfileKey, resolveRefractionProfileLut, sampleRefractionLut, } from "./refractProfile.js";
|
|
15
15
|
export const MAX_REFRACT_TILE_PX = 128;
|
|
16
16
|
const DEFAULT_THICKNESS_RATIO = 1;
|
|
@@ -88,10 +88,11 @@ function encodeCornerTile(slice, tilePx, rad, effBezel, invBezel, interiorGate,
|
|
|
88
88
|
}
|
|
89
89
|
if (bendCorners && edgeX < effBezel && edgeY < effBezel) {
|
|
90
90
|
computeCornerGeometry(edgeX > 0 ? edgeX : 0, edgeY > 0 ? edgeY : 0, rad, effBezel);
|
|
91
|
-
const
|
|
91
|
+
const tCorner = tmpCornerGeom[2] * invBezel;
|
|
92
|
+
const amp = clampAmp(sampleRefractionLut(normLut, tCorner) * 127);
|
|
92
93
|
scanlines[offset++] = clampChannel(Math.round(128 - sx * tmpCornerGeom[0] * amp));
|
|
93
94
|
scanlines[offset++] = clampChannel(Math.round(128 - sy * tmpCornerGeom[1] * amp));
|
|
94
|
-
scanlines[offset++] =
|
|
95
|
+
scanlines[offset++] = encodeRimMaskChannel(tCorner);
|
|
95
96
|
scanlines[offset++] = alpha;
|
|
96
97
|
}
|
|
97
98
|
else if (distIn >= effBezel) {
|
|
@@ -101,10 +102,11 @@ function encodeCornerTile(slice, tilePx, rad, effBezel, invBezel, interiorGate,
|
|
|
101
102
|
scanlines[offset++] = alpha;
|
|
102
103
|
}
|
|
103
104
|
else {
|
|
104
|
-
const
|
|
105
|
+
const tEdge = distIn * invBezel;
|
|
106
|
+
const amp = clampAmp(sampleRefractionLut(normLut, tEdge) * 127);
|
|
105
107
|
scanlines[offset++] = clampChannel(Math.round(128 - gx * amp));
|
|
106
108
|
scanlines[offset++] = clampChannel(Math.round(128 - gy * amp));
|
|
107
|
-
scanlines[offset++] =
|
|
109
|
+
scanlines[offset++] = encodeRimMaskChannel(tEdge);
|
|
108
110
|
scanlines[offset++] = alpha;
|
|
109
111
|
}
|
|
110
112
|
}
|
|
@@ -130,10 +132,11 @@ function encodeHorizontalEdgeStrip(slice, tilePx, effBezel, invBezel, normLut, h
|
|
|
130
132
|
scanlines[offset++] = alpha;
|
|
131
133
|
}
|
|
132
134
|
else {
|
|
133
|
-
const
|
|
135
|
+
const tEdge = edgeY * invBezel;
|
|
136
|
+
const amp = clampAmp(sampleRefractionLut(normLut, tEdge) * 127);
|
|
134
137
|
scanlines[offset++] = 128;
|
|
135
138
|
scanlines[offset++] = clampChannel(Math.round(128 - sy * amp));
|
|
136
|
-
scanlines[offset++] =
|
|
139
|
+
scanlines[offset++] = encodeRimMaskChannel(tEdge);
|
|
137
140
|
scanlines[offset++] = alpha;
|
|
138
141
|
}
|
|
139
142
|
}
|
|
@@ -157,10 +160,11 @@ function encodeVerticalEdgeStrip(slice, tilePx, effBezel, invBezel, normLut, has
|
|
|
157
160
|
scanlines[offset++] = alpha;
|
|
158
161
|
}
|
|
159
162
|
else {
|
|
160
|
-
const
|
|
163
|
+
const tEdge = edgeX * invBezel;
|
|
164
|
+
const amp = clampAmp(sampleRefractionLut(normLut, tEdge) * 127);
|
|
161
165
|
scanlines[offset++] = clampChannel(Math.round(128 - sx * amp));
|
|
162
166
|
scanlines[offset++] = 128;
|
|
163
|
-
scanlines[offset++] =
|
|
167
|
+
scanlines[offset++] = encodeRimMaskChannel(tEdge);
|
|
164
168
|
scanlines[offset++] = alpha;
|
|
165
169
|
}
|
|
166
170
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sessile/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"description": "Zero-dependency pure TypeScript kernel for live-DOM continuous glass morphing.",
|
|
@@ -17,11 +17,24 @@
|
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
19
|
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./overlay": {
|
|
22
|
+
"types": "./dist/entries/overlay.d.ts",
|
|
23
|
+
"default": "./dist/entries/overlay.js"
|
|
24
|
+
},
|
|
25
|
+
"./legibility": {
|
|
26
|
+
"types": "./dist/entries/legibility.d.ts",
|
|
27
|
+
"default": "./dist/entries/legibility.js"
|
|
28
|
+
},
|
|
29
|
+
"./internal": {
|
|
30
|
+
"types": "./dist/entries/internal.d.ts",
|
|
31
|
+
"default": "./dist/entries/internal.js"
|
|
20
32
|
}
|
|
21
33
|
},
|
|
22
34
|
"files": [
|
|
23
35
|
"dist"
|
|
24
36
|
],
|
|
37
|
+
"sideEffects": false,
|
|
25
38
|
"publishConfig": {
|
|
26
39
|
"access": "public"
|
|
27
40
|
},
|