@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/contracts.d.ts
CHANGED
|
@@ -87,6 +87,25 @@ export interface OpticalMaterial {
|
|
|
87
87
|
lightElevation?: number;
|
|
88
88
|
/** Optional grazing blue-black rim shade strength in `[0, 1]` for `rimMode === 'physical'` (defaults to `0.32`). */
|
|
89
89
|
rimShade?: number;
|
|
90
|
+
/** Optional opposite-side internal back-bounce reflection strength in `[0, 1.5]` for `rimMode === 'physical'` (defaults to `0.45`). */
|
|
91
|
+
rimBackBounce?: number;
|
|
92
|
+
/** Optional warm bottom/opposite-side internal caustic glow strength in `[0, 1]` for `rimMode === 'physical'` (defaults to `0.28`). */
|
|
93
|
+
rimCaustic?: number;
|
|
94
|
+
/** Optional crisp 1.2px diagonal bezel catchlight strength in `[0, 1]` for `rimMode === 'physical'` (defaults to `0.38`). */
|
|
95
|
+
bezelShine?: number;
|
|
96
|
+
/** Optional ambient colored rim-bounce RGBA `[r, g, b, a]` for `rimMode === 'physical'` (`a` controls tint mix in `[0, 1]`; defaults to `[1, 1, 1, 0]`). */
|
|
97
|
+
rimBounceRgba?: readonly [number, number, number, number];
|
|
98
|
+
/**
|
|
99
|
+
* Optional live surrounding-backdrop rim reflection strength in `[0, 1]` for Chromium Route B3
|
|
100
|
+
* SVG refraction (`0` or `undefined` disables the outward reflection branch).
|
|
101
|
+
*/
|
|
102
|
+
rimReflection?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Optional Abbe number (`V_d`) enabling physical Cauchy RGB dispersion (`n_F - n_C = (n_d - 1) / V_d`).
|
|
105
|
+
* Lower positive values disperse more strongly (e.g. `64` crown glass, `25` flint glass); `0` or `undefined`
|
|
106
|
+
* falls back to the linear pixel `dispersion` offset.
|
|
107
|
+
*/
|
|
108
|
+
abbeNumber?: number;
|
|
90
109
|
}
|
|
91
110
|
export declare const DEFAULT_OPTICAL_MATERIALS: {
|
|
92
111
|
readonly light: {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sessile/core/internal`: building blocks shared with the sibling `@sessile/*` packages
|
|
3
|
+
* (displacement-map encoding, refraction LUTs, tile cache, raw shader sources).
|
|
4
|
+
*
|
|
5
|
+
* Not part of the public contract: these may change in any release. Siblings depend on an
|
|
6
|
+
* exact core version, so they can rely on it; applications should not.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
9
|
+
*/
|
|
10
|
+
export { buildRefractMapDataUrl, createRefractMapBuilder, type RefractMapBuilder, type RefractMapParams, type RefractMapResult, } from '../refractMap.ts';
|
|
11
|
+
export { MAX_REFRACT_TILE_PX, clearRefractTilesCache, resolveRefractTiles, type RefractTileParams, type RefractTilesResult, } from '../refractTiles.ts';
|
|
12
|
+
export { BEZEL_HEIGHT_PROFILES, CAUSTIC_FOLD_LIMIT, DEFAULT_REFRACTION_IOR, DEFAULT_REFRACTION_SAMPLES, FRAUNHOFER_WAVELENGTHS_UM, NORMAL_FLOOR, computeCauchyDispersionScales, computeCauchyIor, computeRefractionProfileLut, getRefractionProfileKey, resolveRefractionProfileLut, sampleRefractionLut, traceBezelRay, type BezelHeightFn, type BezelRayTrace, type BezelRayTraceInput, type CauchyChannelIor, type CauchyChannelScales, type CauchyDispersionScaleOptions, type RefractionProfileLut, type RefractionProfileOptions, type RefractionProfileSpec, } from '../refractProfile.ts';
|
|
13
|
+
export { OVERLAY_FRAGMENT_SHADER, OVERLAY_VERTEX_SHADER } from '../overlayRenderer.ts';
|
|
14
|
+
export { buildCircularBevelTable, buildColorOpticsMatrix, buildContourAlphaDataUrl, type CircularBevelTable } from '../optics.ts';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sessile/core/internal`: building blocks shared with the sibling `@sessile/*` packages
|
|
3
|
+
* (displacement-map encoding, refraction LUTs, tile cache, raw shader sources).
|
|
4
|
+
*
|
|
5
|
+
* Not part of the public contract: these may change in any release. Siblings depend on an
|
|
6
|
+
* exact core version, so they can rely on it; applications should not.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
9
|
+
*/
|
|
10
|
+
export { buildRefractMapDataUrl, createRefractMapBuilder, } from "../refractMap.js";
|
|
11
|
+
export { MAX_REFRACT_TILE_PX, clearRefractTilesCache, resolveRefractTiles, } from "../refractTiles.js";
|
|
12
|
+
export { BEZEL_HEIGHT_PROFILES, CAUSTIC_FOLD_LIMIT, DEFAULT_REFRACTION_IOR, DEFAULT_REFRACTION_SAMPLES, FRAUNHOFER_WAVELENGTHS_UM, NORMAL_FLOOR, computeCauchyDispersionScales, computeCauchyIor, computeRefractionProfileLut, getRefractionProfileKey, resolveRefractionProfileLut, sampleRefractionLut, traceBezelRay, } from "../refractProfile.js";
|
|
13
|
+
export { OVERLAY_FRAGMENT_SHADER, OVERLAY_VERTEX_SHADER } from "../overlayRenderer.js";
|
|
14
|
+
export { buildCircularBevelTable, buildColorOpticsMatrix, buildContourAlphaDataUrl } from "../optics.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sessile/core/legibility`: adaptive legibility solver, backdrop telemetry and the sRGB
|
|
3
|
+
* luminance helpers it is built on. Optional: surfaces that never enable legibility do not
|
|
4
|
+
* need this module.
|
|
5
|
+
*
|
|
6
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
7
|
+
*/
|
|
8
|
+
export { LEGIBILITY_CALM_KNEE, LEGIBILITY_LIMIT_MARGIN, LEGIBILITY_POLICIES, LEGIBILITY_SMOOTHING, LEGIBILITY_STAGES, LEGIBILITY_TABLE_SIZE, TELEMETRY_STRIDE, compensateLegibilityEdges, computeBackdropRisk, contrastRatio, createAsymmetricSmoother, createLegibilityParams, createTelemetryAccumulator, linearToSrgb, measureTelemetryGrid, relativeLuminance, srgbLuma, resolveLegibilityGoal, resolveLegibilityParams, srgbToLinear, type AsymmetricSmoother, type AsymmetricSmootherOptions, type BackdropTelemetry, type BackdropTelemetryAccumulator, type BackdropTelemetryGrid, type ForegroundPolarity, type LegibilityGoal, type LegibilityParams, type LegibilityPolicy, type LegibilityRisk, type LegibilityTarget, type LegibilityTier, } from '../legibility.ts';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sessile/core/legibility`: adaptive legibility solver, backdrop telemetry and the sRGB
|
|
3
|
+
* luminance helpers it is built on. Optional: surfaces that never enable legibility do not
|
|
4
|
+
* need this module.
|
|
5
|
+
*
|
|
6
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
7
|
+
*/
|
|
8
|
+
export { LEGIBILITY_CALM_KNEE, LEGIBILITY_LIMIT_MARGIN, LEGIBILITY_POLICIES, LEGIBILITY_SMOOTHING, LEGIBILITY_STAGES, LEGIBILITY_TABLE_SIZE, TELEMETRY_STRIDE, compensateLegibilityEdges, computeBackdropRisk, contrastRatio, createAsymmetricSmoother, createLegibilityParams, createTelemetryAccumulator, linearToSrgb, measureTelemetryGrid, relativeLuminance, srgbLuma, resolveLegibilityGoal, resolveLegibilityParams, srgbToLinear, } from "../legibility.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sessile/core/overlay`: WebGL2 / 2D Canvas perimeter highlight and shadow renderer.
|
|
3
|
+
* Kept off the main entry so hosts that never draw an edge overlay skip ~1.2k lines of
|
|
4
|
+
* renderer and shader source.
|
|
5
|
+
*
|
|
6
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
7
|
+
*/
|
|
8
|
+
export type { IGlassOverlayRenderer, OverlayRenderFrame, RendererCapabilities } from '../contracts.ts';
|
|
9
|
+
export { createGlassOverlayRenderer, type GlassOverlayRendererOptions } from '../overlayRenderer.ts';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sessile/core/overlay`: WebGL2 / 2D Canvas perimeter highlight and shadow renderer.
|
|
3
|
+
* Kept off the main entry so hosts that never draw an edge overlay skip ~1.2k lines of
|
|
4
|
+
* renderer and shader source.
|
|
5
|
+
*
|
|
6
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
7
|
+
*/
|
|
8
|
+
export { createGlassOverlayRenderer } from "../overlayRenderer.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
* Public entry point for `@sessile/core`.
|
|
3
3
|
* Zero-dependency Live-DOM continuous glass morphing kernel.
|
|
4
4
|
*
|
|
5
|
+
* Only the stable surface lives here. Optional modules ship as subpaths so bundles that never
|
|
6
|
+
* import them pay nothing: `@sessile/core/overlay` (WebGL2/2D edge renderer) and
|
|
7
|
+
* `@sessile/core/legibility` (adaptive legibility solver and backdrop telemetry).
|
|
8
|
+
* `@sessile/core/internal` serves the sibling `@sessile/*` packages and carries no semver
|
|
9
|
+
* guarantee.
|
|
10
|
+
*
|
|
5
11
|
* SPDX-License-Identifier: MPL-2.0
|
|
6
12
|
*/
|
|
7
13
|
export { DEFAULT_OPTICAL_MATERIALS, DEFAULT_SPRINGS, MAX_GPU_PRIMITIVES, type EdgeInsets, type GlassFieldState, type GlassPrimitive, type IGlassOverlayRenderer, type OpticalMaterial, type OpticalPresetVariant, type OverlayRenderFrame, type Point, type Rect, type RendererCapabilities, type RimMode, type SdfSample, type Size, type SminSample, type SpringParams, type ThemeMode, } from './contracts.ts';
|
|
8
14
|
export { computeFieldBounds, computePairMergeStatus, computeRoundedBoxDistance, computeRoundedBoxSdf, computeSmin, computeSminDistance, createPreparedField, evaluateFieldDistance, evaluateFieldSdf, prepareField, type PairMergeStatus, type PreparedField, } from './sdf.ts';
|
|
9
15
|
export { extractFieldContourPath, formatRoundedRectPath, } from './contour.ts';
|
|
10
|
-
export
|
|
11
|
-
export { MAX_REFRACT_TILE_PX, clearRefractTilesCache, resolveRefractTiles, type RefractTileParams, type RefractTilesResult, } from './refractTiles.ts';
|
|
12
|
-
export { BEZEL_HEIGHT_PROFILES, CAUSTIC_FOLD_LIMIT, DEFAULT_REFRACTION_IOR, DEFAULT_REFRACTION_SAMPLES, NORMAL_FLOOR, computeRefractionProfileLut, getRefractionProfileKey, resolveRefractionProfileLut, sampleRefractionLut, traceBezelRay, type BezelHeightFn, type BezelHeightProfileName, type BezelRayTrace, type BezelRayTraceInput, type RefractionProfileLut, type RefractionProfileName, type RefractionProfileOptions, type RefractionProfileSpec, } from './refractProfile.ts';
|
|
13
|
-
export { OVERLAY_FRAGMENT_SHADER, OVERLAY_VERTEX_SHADER, createGlassOverlayRenderer, type GlassOverlayRendererOptions, } from './overlayRenderer.ts';
|
|
16
|
+
export type { BezelHeightProfileName, RefractionProfileName } from './refractProfile.ts';
|
|
14
17
|
export { clamp, computeAreaPreservingScale, createElasticPressController, createMorphTimeline, createSpringChannel, cubicBezier, deformSizePreservingArea, easeInOutCubic, easeInQuad, easeOutCubic, evaluateSpring, evaluateSpringState, lerp, riseAndFall, smoothstep, type AreaPreservingScale, type ElasticPressController, type ElasticPressOptions, type ElasticPressState, type MorphTimeline, type MorphTimelineOptions, type MorphTimelinePhase, type MorphTimelineState, type SpringChannel, type SpringChannelOptions, type SpringChannelState, type SpringSample, } from './physics.ts';
|
|
15
|
-
export {
|
|
16
|
-
export { LEGIBILITY_CALM_KNEE, LEGIBILITY_LIMIT_MARGIN, LEGIBILITY_POLICIES, LEGIBILITY_SMOOTHING, LEGIBILITY_STAGES, LEGIBILITY_TABLE_SIZE, TELEMETRY_STRIDE, compensateLegibilityEdges, computeBackdropRisk, contrastRatio, createAsymmetricSmoother, createLegibilityParams, createTelemetryAccumulator, linearToSrgb, measureTelemetryGrid, relativeLuminance, srgbLuma, resolveLegibilityGoal, resolveLegibilityParams, srgbToLinear, type AsymmetricSmoother, type AsymmetricSmootherOptions, type BackdropTelemetry, type BackdropTelemetryAccumulator, type BackdropTelemetryGrid, type ForegroundPolarity, type LegibilityGoal, type LegibilityParams, type LegibilityPolicy, type LegibilityRisk, type LegibilityTarget, type LegibilityTier, } from './legibility.ts';
|
|
18
|
+
export { interpolateCssGlassSurfaceToMaterial, interpolateOpticalMaterial, interpolateVeilOptics, parseCssBoxShadow, parseCssFilterOptics, parseCssGlassSurface, parseCssRgba, tryParseCssRgba, resolveOpticalMaterial, type BackdropVeilOptics, type ExtractedCssGlassSurface, type ParseCssGlassSurfaceInput, type ParsedBoxShadowLayer, } from './optics.ts';
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
* Public entry point for `@sessile/core`.
|
|
3
3
|
* Zero-dependency Live-DOM continuous glass morphing kernel.
|
|
4
4
|
*
|
|
5
|
+
* Only the stable surface lives here. Optional modules ship as subpaths so bundles that never
|
|
6
|
+
* import them pay nothing: `@sessile/core/overlay` (WebGL2/2D edge renderer) and
|
|
7
|
+
* `@sessile/core/legibility` (adaptive legibility solver and backdrop telemetry).
|
|
8
|
+
* `@sessile/core/internal` serves the sibling `@sessile/*` packages and carries no semver
|
|
9
|
+
* guarantee.
|
|
10
|
+
*
|
|
5
11
|
* SPDX-License-Identifier: MPL-2.0
|
|
6
12
|
*/
|
|
7
13
|
export { DEFAULT_OPTICAL_MATERIALS, DEFAULT_SPRINGS, MAX_GPU_PRIMITIVES, } from "./contracts.js";
|
|
8
14
|
export { computeFieldBounds, computePairMergeStatus, computeRoundedBoxDistance, computeRoundedBoxSdf, computeSmin, computeSminDistance, createPreparedField, evaluateFieldDistance, evaluateFieldSdf, prepareField, } from "./sdf.js";
|
|
9
15
|
export { extractFieldContourPath, formatRoundedRectPath, } from "./contour.js";
|
|
10
|
-
export { buildRefractMapDataUrl, createRefractMapBuilder, } from "./refractMap.js";
|
|
11
|
-
export { MAX_REFRACT_TILE_PX, clearRefractTilesCache, resolveRefractTiles, } from "./refractTiles.js";
|
|
12
|
-
export { BEZEL_HEIGHT_PROFILES, CAUSTIC_FOLD_LIMIT, DEFAULT_REFRACTION_IOR, DEFAULT_REFRACTION_SAMPLES, NORMAL_FLOOR, computeRefractionProfileLut, getRefractionProfileKey, resolveRefractionProfileLut, sampleRefractionLut, traceBezelRay, } from "./refractProfile.js";
|
|
13
|
-
export { OVERLAY_FRAGMENT_SHADER, OVERLAY_VERTEX_SHADER, createGlassOverlayRenderer, } from "./overlayRenderer.js";
|
|
14
16
|
export { clamp, computeAreaPreservingScale, createElasticPressController, createMorphTimeline, createSpringChannel, cubicBezier, deformSizePreservingArea, easeInOutCubic, easeInQuad, easeOutCubic, evaluateSpring, evaluateSpringState, lerp, riseAndFall, smoothstep, } from "./physics.js";
|
|
15
|
-
export {
|
|
16
|
-
export { LEGIBILITY_CALM_KNEE, LEGIBILITY_LIMIT_MARGIN, LEGIBILITY_POLICIES, LEGIBILITY_SMOOTHING, LEGIBILITY_STAGES, LEGIBILITY_TABLE_SIZE, TELEMETRY_STRIDE, compensateLegibilityEdges, computeBackdropRisk, contrastRatio, createAsymmetricSmoother, createLegibilityParams, createTelemetryAccumulator, linearToSrgb, measureTelemetryGrid, relativeLuminance, srgbLuma, resolveLegibilityGoal, resolveLegibilityParams, srgbToLinear, } from "./legibility.js";
|
|
17
|
+
export { interpolateCssGlassSurfaceToMaterial, interpolateOpticalMaterial, interpolateVeilOptics, parseCssBoxShadow, parseCssFilterOptics, parseCssGlassSurface, parseCssRgba, tryParseCssRgba, resolveOpticalMaterial, } from "./optics.js";
|
package/dist/legibility.js
CHANGED
|
@@ -286,6 +286,12 @@ export function compensateLegibilityEdges(material, params, out) {
|
|
|
286
286
|
out.lightAngle = material.lightAngle;
|
|
287
287
|
out.lightElevation = material.lightElevation;
|
|
288
288
|
out.rimShade = material.rimShade;
|
|
289
|
+
out.rimBackBounce = material.rimBackBounce;
|
|
290
|
+
out.rimCaustic = material.rimCaustic;
|
|
291
|
+
out.bezelShine = material.bezelShine;
|
|
292
|
+
out.rimBounceRgba = material.rimBounceRgba;
|
|
293
|
+
out.rimReflection = material.rimReflection;
|
|
294
|
+
out.abbeNumber = material.abbeNumber;
|
|
289
295
|
out.hairlineSideAlpha = clamp(material.hairlineSideAlpha * params.hairlineScale, 0, 1);
|
|
290
296
|
out.hairlineCornerAlpha = clamp(material.hairlineCornerAlpha * params.hairlineScale, 0, 1);
|
|
291
297
|
out.hairlineFlatAlpha = clamp(material.hairlineFlatAlpha * params.hairlineScale, 0, 1);
|
package/dist/optics.js
CHANGED
|
@@ -548,6 +548,36 @@ export function interpolateOpticalMaterial(from, to, t) {
|
|
|
548
548
|
if (from.rimShade !== undefined || to.rimShade !== undefined) {
|
|
549
549
|
result.rimShade = lerp(from.rimShade ?? 0.32, to.rimShade ?? 0.32, u);
|
|
550
550
|
}
|
|
551
|
+
if (from.rimBackBounce !== undefined || to.rimBackBounce !== undefined) {
|
|
552
|
+
result.rimBackBounce = lerp(from.rimBackBounce ?? 0.45, to.rimBackBounce ?? 0.45, u);
|
|
553
|
+
}
|
|
554
|
+
if (from.rimCaustic !== undefined || to.rimCaustic !== undefined) {
|
|
555
|
+
result.rimCaustic = lerp(from.rimCaustic ?? 0.28, to.rimCaustic ?? 0.28, u);
|
|
556
|
+
}
|
|
557
|
+
if (from.bezelShine !== undefined || to.bezelShine !== undefined) {
|
|
558
|
+
result.bezelShine = lerp(from.bezelShine ?? 0.38, to.bezelShine ?? 0.38, u);
|
|
559
|
+
}
|
|
560
|
+
if (from.rimBounceRgba !== undefined || to.rimBounceRgba !== undefined) {
|
|
561
|
+
const a = from.rimBounceRgba ?? [1, 1, 1, 0];
|
|
562
|
+
const b = to.rimBounceRgba ?? [1, 1, 1, 0];
|
|
563
|
+
result.rimBounceRgba = [
|
|
564
|
+
lerp(a[0], b[0], u),
|
|
565
|
+
lerp(a[1], b[1], u),
|
|
566
|
+
lerp(a[2], b[2], u),
|
|
567
|
+
lerp(a[3], b[3], u),
|
|
568
|
+
];
|
|
569
|
+
}
|
|
570
|
+
if (from.rimReflection !== undefined || to.rimReflection !== undefined) {
|
|
571
|
+
result.rimReflection = lerp(from.rimReflection ?? 0, to.rimReflection ?? 0, u);
|
|
572
|
+
}
|
|
573
|
+
if (from.abbeNumber !== undefined || to.abbeNumber !== undefined) {
|
|
574
|
+
// Interpolate in dispersive power (1 / V_d) so transitioning from disabled (0 / undefined)
|
|
575
|
+
// to a finite Abbe number increases dispersion monotonically instead of passing through V_d -> 0.
|
|
576
|
+
const pFrom = from.abbeNumber !== undefined && from.abbeNumber > 0 ? 1 / from.abbeNumber : 0;
|
|
577
|
+
const pTo = to.abbeNumber !== undefined && to.abbeNumber > 0 ? 1 / to.abbeNumber : 0;
|
|
578
|
+
const p = lerp(pFrom, pTo, u);
|
|
579
|
+
result.abbeNumber = p > 1e-6 ? 1 / p : 0;
|
|
580
|
+
}
|
|
551
581
|
return result;
|
|
552
582
|
}
|
|
553
583
|
/** Convenience resolver interpolating between `DEFAULT_OPTICAL_MATERIALS[theme].crisp` and `.frosted` by `styleMix`. */
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { IGlassOverlayRenderer } from './contracts.ts';
|
|
17
17
|
export declare const OVERLAY_VERTEX_SHADER = "#version 300 es\nprecision highp float;\n\nout vec2 vUv;\n\nvoid main() {\n vec2 pos = vec2(\n (gl_VertexID == 1) ? 3.0 : -1.0,\n (gl_VertexID == 2) ? 3.0 : -1.0\n );\n vUv = pos * 0.5 + 0.5;\n gl_Position = vec4(pos, 0.0, 1.0);\n}\n";
|
|
18
|
-
export declare const OVERLAY_FRAGMENT_SHADER = "#version 300 es\nprecision highp float;\n\n#define MAX_PRIMITIVES 16\n\nin vec2 vUv;\nout vec4 fragColor;\n\nuniform vec2 uViewport;\nuniform float uDpr;\nuniform int uPrimitiveCount;\nuniform vec4 uPrimitives[MAX_PRIMITIVES]; // (cx, cy, halfW, halfH) in local CSS px\nuniform float uRadii[MAX_PRIMITIVES];\nuniform float uBlendK;\nuniform float uRimOpacity;\nuniform float uStyleMix;\nuniform float uOpacity;\n\nuniform vec4 uRimParams; // (material.rimOpacity, material.rimWidth, material.rimTail, material.rimFocus)\nuniform vec4 uHairline; // (width, sideAlpha, cornerAlpha, flatAlpha)\nuniform vec3 uShadow; // (blur, offsetY, alpha)\nuniform vec4 uBorderColor; // normalized RGBA of optional uniform inner border\nuniform vec2 uBorderParams; // (borderWidthPx, rimBottomRatio)\nuniform vec4 uPhysicalLight; // (lx, ly, lz, enabled)\nuniform vec4 uPhysicalParams; // (bevelPx, specularStrength, shadeStrength, profileCode)\n\nstruct SdfSample {\n float dist;\n vec2 normal;\n};\n\nfloat safePow(float x, float y) {\n return (x <= 1e-6) ? 0.0 : pow(x, y);\n}\n\n// Box-filtered coverage of the band lo <= d <= hi over a pixel footprint of width aa. Lines thinner\n// than a pixel keep the same total alpha at every subpixel offset; a smoothstep around the band\n// centre nearly vanishes or doubles as the edge moves, which reads as shimmer while morphing.\nfloat bandCoverage(float d, float lo, float hi, float aa) {\n return clamp(min(d + 0.5 * aa, hi) - max(d - 0.5 * aa, lo), 0.0, aa) / aa;\n}\n\nfloat computeDirectionalRimWeight(vec2 normal, float focus, float bottomRatio) {\n if (focus < 0.05) {\n return 1.0;\n }\n float topBias = clamp(-normal.y, 0.0, 1.0);\n float botBias = clamp(normal.y, 0.0, 1.0);\n return safePow(max(topBias, botBias * clamp(bottomRatio, 0.0, 1.0)), max(focus, 0.25));\n}\n\nSdfSample sdRoundedBoxRefined(vec2 p, vec2 center, vec2 halfSize, float r) {\n vec2 safeHalf = max(halfSize, vec2(0.001));\n float rad = clamp(r, 0.0, min(safeHalf.x, safeHalf.y));\n vec2 rel = p - center;\n vec2 s = vec2(rel.x >= 0.0 ? 1.0 : -1.0, rel.y >= 0.0 ? 1.0 : -1.0);\n vec2 q = abs(rel) - safeHalf + rad;\n vec2 qPos = max(q, 0.0);\n\n float outside = length(qPos);\n float inside = min(max(q.x, q.y), 0.0);\n float baseDist = outside + inside - rad;\n\n vec2 baseNormal;\n if (q.x > 0.0 && q.y > 0.0) {\n baseNormal = (outside > 1e-5) ? (qPos / outside) * s : normalize(s);\n } else if (q.x > q.y) {\n baseNormal = vec2(s.x, 0.0);\n } else {\n baseNormal = vec2(0.0, s.y);\n }\n\n // Superellipse octant normal refinement within 5 CSS px of the boundary for smooth corner speculars;\n // dist stays exact baseDist for 0px alignment with the Marching Squares contour.\n float rimProximity = smoothstep(5.0, 0.0, abs(baseDist));\n vec2 normal = baseNormal;\n\n if (rimProximity > 0.001 && rad > 1.0 && q.x > 0.0 && q.y > 0.0) {\n const float pExp = 2.55;\n vec2 qn = qPos / rad;\n vec2 grad = vec2(\n safePow(qn.x, pExp - 1.0),\n safePow(qn.y, pExp - 1.0)\n );\n float gl = length(grad);\n if (gl > 1e-5) {\n vec2 superNormal = (grad / gl) * s;\n vec2 mixedN = mix(baseNormal, superNormal, rimProximity);\n float mnl = length(mixedN);\n normal = (mnl > 1e-5) ? (mixedN / mnl) : baseNormal;\n }\n }\n\n return SdfSample(baseDist, normal);\n}\n\nfloat evalBezelHeight(float t, float code) {\n float u = clamp(1.0 - t, 0.0, 1.0);\n if (code > 2.5) {\n float sq = safePow(max(0.0, 1.0 - safePow(u, 4.0)), 0.25);\n float s = sin(3.14159265 * clamp(t, 0.0, 1.0));\n return sq + 0.14 * s * s;\n }\n if (code > 1.5) {\n return 1.0 - u * u;\n }\n if (code > 0.5) {\n return sqrt(max(0.0, 1.0 - u * u));\n }\n return safePow(max(0.0, 1.0 - safePow(u, 4.0)), 0.25);\n}\n\nSdfSample evaluateGlassSdf(vec2 p) {\n if (uPrimitiveCount <= 0) {\n return SdfSample(1e6, vec2(0.0, -1.0));\n }\n\n SdfSample acc = sdRoundedBoxRefined(p, uPrimitives[0].xy, uPrimitives[0].zw, uRadii[0]);\n float d = acc.dist;\n vec2 g = acc.normal;\n for (int i = 1; i < MAX_PRIMITIVES; i++) {\n if (i >= uPrimitiveCount) break;\n SdfSample b = sdRoundedBoxRefined(p, uPrimitives[i].xy, uPrimitives[i].zw, uRadii[i]);\n if (uBlendK <= 0.001) {\n if (b.dist < d) {\n d = b.dist;\n g = b.normal;\n }\n } else {\n float h = clamp(0.5 + 0.5 * (b.dist - d) / uBlendK, 0.0, 1.0);\n d = mix(b.dist, d, h) - uBlendK * h * (1.0 - h);\n g = mix(b.normal, g, h);\n }\n }\n\n // Soften cancelling normals in smin saddle necks (NORMAL_FLOOR = 0.25) so speculars never flip 180 degrees.\n float gl = max(length(g), 0.25);\n return SdfSample(d, g / gl);\n}\n\nvoid main() {\n if (uOpacity <= 0.001 || uPrimitiveCount <= 0) {\n fragColor = vec4(0.0);\n return;\n }\n\n // Convert GL UV (bottom-left origin) to local CSS px (top-left origin).\n vec2 pCss = vec2(vUv.x * uViewport.x, (1.0 - vUv.y) * uViewport.y);\n SdfSample sdf = evaluateGlassSdf(pCss);\n float d = sdf.dist;\n vec2 normal = sdf.normal;\n\n float aa = 1.0 / max(uDpr, 1.0);\n float glassMask = clamp(0.5 - d / aa, 0.0, 1.0);\n float outsideMask = 1.0 - glassMask;\n\n // 1. Outside-only drop shadow (d > 0)\n float shadowA = 0.0;\n if (outsideMask > 0.001 && uShadow.z > 0.001) {\n SdfSample shadowSdf = evaluateGlassSdf(pCss - vec2(0.0, uShadow.y));\n float sigma = max(uShadow.x * 0.5, 1.0);\n float shadowFalloff = 1.0 / (1.0 + exp(clamp(1.65 * shadowSdf.dist / sigma, -12.0, 12.0)));\n shadowA = outsideMask * shadowFalloff * uShadow.z * uOpacity;\n }\n\n // 2. Dark outer hairline: strictly outside when a uniform CSS inner border is present (d >= 0), otherwise straddling the outer edge (d >= -0.25)\n float hw = max(uHairline.x, 0.5 / max(uDpr, 1.0));\n float hasUniformBorder = step(0.001, uBorderParams.x);\n float hairlineLo = mix(-0.25, 0.0, hasUniformBorder);\n float hairlineBand = bandCoverage(d, hairlineLo, hairlineLo + hw, aa);\n float hairA = 0.0;\n if (hairlineBand > 0.001) {\n float ax = abs(normal.x);\n float ay = abs(normal.y);\n float cornerW = safePow(clamp(2.0 * ax * ay, 0.0, 1.0), 1.5);\n float sideVsFlat = mix(uHairline.y, uHairline.w, ay * ay);\n float hairlineProfileAlpha = mix(sideVsFlat, uHairline.z, cornerW);\n hairA = hairlineBand * hairlineProfileAlpha * uOpacity;\n }\n\n // 3. Optional 1px uniform inner border + directional/soft inner rim highlight (inset < 5.0 CSS px)\n float inset = max(-d, 0.0);\n float borderMask = 0.0;\n float borderA = 0.0;\n vec3 borderRgb = vec3(0.0);\n if (hasUniformBorder > 0.5 && d < 0.5 * aa && inset < uBorderParams.x + aa) {\n borderMask = bandCoverage(d, -uBorderParams.x, 0.0, aa);\n borderA = clamp(borderMask * uBorderColor.a * uOpacity, 0.0, 1.0);\n borderRgb = uBorderColor.rgb * borderA;\n }\n\n float rimA = 0.0;\n float physLitA = 0.0;\n float physShadeA = 0.0;\n float isPhysicalRim = step(0.5, uPhysicalLight.w) * (1.0 - hasUniformBorder);\n\n if (glassMask > 0.001 && inset < 5.0 && uRimParams.x > 0.001 && isPhysicalRim < 0.5) {\n float ny = abs(normal.y);\n float wDirectional = 1.0 - clamp(uStyleMix, 0.0, 1.0);\n float wSoft = clamp(uStyleMix, 0.0, 1.0) * clamp(uRimOpacity, 0.0, 1.0);\n\n if (hasUniformBorder > 0.5) {\n // Match CSS inset box-shadow: keep inner rim inside the padding edge so the 1px border is not double-brightened\n float padInset = max(inset - uBorderParams.x, 0.0);\n float padMask = 1.0 - borderMask;\n float dirWeight = computeDirectionalRimWeight(normal, uRimParams.w, uBorderParams.y);\n float core = smoothstep(max(uRimParams.y, 0.4) + 0.6, 0.0, padInset);\n float tail = exp(-padInset / 1.8) * uRimParams.z * smoothstep(5.0, 3.2, inset);\n rimA = clamp((core + tail) * dirWeight * uRimParams.x * padMask * glassMask * uOpacity, 0.0, 1.0);\n } else {\n if (wDirectional > 0.001) {\n float dirWeight = computeDirectionalRimWeight(normal, uRimParams.w, uBorderParams.y);\n float core = smoothstep(max(uRimParams.y, 0.4) + 0.6, 0.0, inset);\n float tail = exp(-inset / 1.8) * uRimParams.z * smoothstep(5.0, 3.2, inset);\n rimA += (core + tail) * dirWeight * uRimParams.x * wDirectional;\n }\n\n if (wSoft > 0.001) {\n float bandT = clamp(inset / 5.0, 0.0, 1.0);\n float steppedT = min(floor(bandT * 9.0) / 9.0, 1.0);\n float bandCurve = mix(safePow(1.0 - bandT, 2.1), safePow(1.0 - steppedT, 2.1), 0.35);\n float rimCoreBoost = 0.65 + 0.35 * smoothstep(1.2, 0.0, inset);\n float angWeight = mix(0.015, 1.0, safePow(ny, 2.1)) * (normal.y < 0.0 ? 1.0 : 0.85);\n rimA += bandCurve * rimCoreBoost * angWeight * uRimParams.x * wSoft;\n }\n\n // Boost specular luminance to match source-over alpha blending expectations\n rimA = clamp(rimA * 1.35 * glassMask * uOpacity, 0.0, 1.0);\n }\n } else if (glassMask > 0.001 && isPhysicalRim > 0.5 && inset < uPhysicalParams.x) {\n float bezelPx = max(uPhysicalParams.x, 1.0);\n float t = clamp(inset / bezelPx, 0.0, 1.0);\n float eps = 0.015;\n float t0 = max(0.0, t - eps);\n float t1 = min(1.0, t + eps);\n float slope = (evalBezelHeight(t1, uPhysicalParams.w) - evalBezelHeight(t0, uPhysicalParams.w)) / max(t1 - t0, 1e-4);\n vec3 N = normalize(vec3(normal * slope, 1.0));\n vec3 L = uPhysicalLight.xyz;\n vec3 H = vec3(L.xy, L.z + 1.0);\n float hLen = max(length(H), 1e-4);\n const float shininess = 36.0;\n float flatBase = safePow(clamp((L.z + 1.0) / hLen, 0.0, 1.0), shininess);\n float denomBase = max(1.0 - flatBase, 1e-4);\n float hDot = clamp(dot(N, H) / hLen, 0.0, 1.0);\n float highlight = max(safePow(hDot, shininess) - flatBase, 0.0) / denomBase;\n vec3 H_bounce = vec3(-L.xy, L.z + 1.0);\n float bDot = clamp(dot(N, H_bounce) / hLen, 0.0, 1.0);\n float bounce = max(safePow(bDot, shininess) - flatBase, 0.0) / denomBase;\n vec2 planar = L.xy / max(length(L.xy), 1e-4);\n float facing = dot(normal, planar);\n float fresnel = safePow(clamp(1.0 - N.z, 0.0, 1.0), 4.0);\n float rimTerm = fresnel * (0.25 + 0.75 * max(facing, 0.0) + 0.45 * max(-facing, 0.0));\n float shadeTerm = safePow(clamp(1.0 - N.z, 0.0, 1.0), 2.5) * (0.45 + 0.55 * max(-facing, 0.0));\n float lit = clamp((uPhysicalParams.y * (highlight + 0.45 * bounce) + uRimParams.x * rimTerm) * glassMask * uOpacity, 0.0, 1.0);\n float dark = clamp(uPhysicalParams.z * shadeTerm * glassMask * uOpacity, 0.0, 1.0) * (1.0 - lit);\n physLitA = lit;\n physShadeA = dark;\n }\n\n // Keep interior strictly transparent when shadow, hairline, border, and rim are all zero\n if (shadowA <= 0.0001 && hairA <= 0.0001 && borderA <= 0.0001 && rimA <= 0.0001 && physLitA <= 0.0001 && physShadeA <= 0.0001) {\n fragColor = vec4(0.0);\n return;\n }\n\n // Premultiplied alpha composite: uniform border over inner/physical rim over hairline and shadow\n float darkA = clamp(shadowA + hairA * (1.0 - shadowA), 0.0, 1.0);\n vec3 shadeColor = vec3(0.03921569, 0.07058824, 0.10980392);\n vec3 afterRimRgb = vec3(rimA + physLitA) + shadeColor * physShadeA;\n float totalRimA = clamp(rimA + physLitA + physShadeA * (1.0 - rimA), 0.0, 1.0);\n float afterRimA = totalRimA + darkA * (1.0 - totalRimA);\n vec3 outRgb = borderRgb + afterRimRgb * (1.0 - borderA);\n float outA = clamp(borderA + afterRimA * (1.0 - borderA), 0.0, 1.0);\n fragColor = vec4(outRgb, outA);\n}\n";
|
|
18
|
+
export declare const OVERLAY_FRAGMENT_SHADER = "#version 300 es\nprecision highp float;\n\n#define MAX_PRIMITIVES 16\n\nin vec2 vUv;\nout vec4 fragColor;\n\nuniform vec2 uViewport;\nuniform float uDpr;\nuniform int uPrimitiveCount;\nuniform vec4 uPrimitives[MAX_PRIMITIVES]; // (cx, cy, halfW, halfH) in local CSS px\nuniform float uRadii[MAX_PRIMITIVES];\nuniform float uBlendK;\nuniform float uRimOpacity;\nuniform float uStyleMix;\nuniform float uOpacity;\n\nuniform vec4 uRimParams; // (material.rimOpacity, material.rimWidth, material.rimTail, material.rimFocus)\nuniform vec4 uHairline; // (width, sideAlpha, cornerAlpha, flatAlpha)\nuniform vec3 uShadow; // (blur, offsetY, alpha)\nuniform vec4 uBorderColor; // normalized RGBA of optional uniform inner border\nuniform vec2 uBorderParams; // (borderWidthPx, rimBottomRatio)\nuniform vec4 uPhysicalLight; // (lx, ly, lz, enabled)\nuniform vec4 uPhysicalParams; // (bevelPx, specularStrength, shadeStrength, profileCode)\nuniform vec4 uPhysicalOptics; // (backBounceStrength, causticStrength, bezelShineStrength, reserved)\nuniform vec4 uRimBounceColor; // normalized RGBA ambient bounce tint (a = tint mix in [0, 1])\n\nstruct SdfSample {\n float dist;\n vec2 normal;\n};\n\nfloat safePow(float x, float y) {\n return (x <= 1e-6) ? 0.0 : pow(x, y);\n}\n\n// Box-filtered coverage of the band lo <= d <= hi over a pixel footprint of width aa. Lines thinner\n// than a pixel keep the same total alpha at every subpixel offset; a smoothstep around the band\n// centre nearly vanishes or doubles as the edge moves, which reads as shimmer while morphing.\nfloat bandCoverage(float d, float lo, float hi, float aa) {\n return clamp(min(d + 0.5 * aa, hi) - max(d - 0.5 * aa, lo), 0.0, aa) / aa;\n}\n\nfloat computeDirectionalRimWeight(vec2 normal, float focus, float bottomRatio) {\n if (focus < 0.05) {\n return 1.0;\n }\n float topBias = clamp(-normal.y, 0.0, 1.0);\n float botBias = clamp(normal.y, 0.0, 1.0);\n return safePow(max(topBias, botBias * clamp(bottomRatio, 0.0, 1.0)), max(focus, 0.25));\n}\n\nSdfSample sdRoundedBoxRefined(vec2 p, vec2 center, vec2 halfSize, float r) {\n vec2 safeHalf = max(halfSize, vec2(0.001));\n float rad = clamp(r, 0.0, min(safeHalf.x, safeHalf.y));\n vec2 rel = p - center;\n vec2 s = vec2(rel.x >= 0.0 ? 1.0 : -1.0, rel.y >= 0.0 ? 1.0 : -1.0);\n vec2 q = abs(rel) - safeHalf + rad;\n vec2 qPos = max(q, 0.0);\n\n float outside = length(qPos);\n float inside = min(max(q.x, q.y), 0.0);\n float baseDist = outside + inside - rad;\n\n vec2 baseNormal;\n if (q.x > 0.0 && q.y > 0.0) {\n baseNormal = (outside > 1e-5) ? (qPos / outside) * s : normalize(s);\n } else if (q.x > q.y) {\n baseNormal = vec2(s.x, 0.0);\n } else {\n baseNormal = vec2(0.0, s.y);\n }\n\n // Superellipse octant normal refinement within 5 CSS px of the boundary for smooth corner speculars;\n // dist stays exact baseDist for 0px alignment with the Marching Squares contour.\n float rimProximity = smoothstep(5.0, 0.0, abs(baseDist));\n vec2 normal = baseNormal;\n\n if (rimProximity > 0.001 && rad > 1.0 && q.x > 0.0 && q.y > 0.0) {\n const float pExp = 2.55;\n vec2 qn = qPos / rad;\n vec2 grad = vec2(\n safePow(qn.x, pExp - 1.0),\n safePow(qn.y, pExp - 1.0)\n );\n float gl = length(grad);\n if (gl > 1e-5) {\n vec2 superNormal = (grad / gl) * s;\n vec2 mixedN = mix(baseNormal, superNormal, rimProximity);\n float mnl = length(mixedN);\n normal = (mnl > 1e-5) ? (mixedN / mnl) : baseNormal;\n }\n }\n\n return SdfSample(baseDist, normal);\n}\n\nfloat evalBezelHeight(float t, float code) {\n float u = clamp(1.0 - t, 0.0, 1.0);\n if (code > 3.5) {\n float u2 = u * u;\n return 1.0 - u2 * u2;\n }\n if (code > 2.5) {\n float sq = safePow(max(0.0, 1.0 - safePow(u, 4.0)), 0.25);\n float s = sin(3.14159265 * clamp(t, 0.0, 1.0));\n return sq + 0.14 * s * s;\n }\n if (code > 1.5) {\n return 1.0 - u * u;\n }\n if (code > 0.5) {\n return sqrt(max(0.0, 1.0 - u * u));\n }\n return safePow(max(0.0, 1.0 - safePow(u, 4.0)), 0.25);\n}\n\nSdfSample evaluateGlassSdf(vec2 p) {\n if (uPrimitiveCount <= 0) {\n return SdfSample(1e6, vec2(0.0, -1.0));\n }\n\n SdfSample acc = sdRoundedBoxRefined(p, uPrimitives[0].xy, uPrimitives[0].zw, uRadii[0]);\n float d = acc.dist;\n vec2 g = acc.normal;\n for (int i = 1; i < MAX_PRIMITIVES; i++) {\n if (i >= uPrimitiveCount) break;\n SdfSample b = sdRoundedBoxRefined(p, uPrimitives[i].xy, uPrimitives[i].zw, uRadii[i]);\n if (uBlendK <= 0.001) {\n if (b.dist < d) {\n d = b.dist;\n g = b.normal;\n }\n } else {\n float h = clamp(0.5 + 0.5 * (b.dist - d) / uBlendK, 0.0, 1.0);\n d = mix(b.dist, d, h) - uBlendK * h * (1.0 - h);\n g = mix(b.normal, g, h);\n }\n }\n\n // Soften cancelling normals in smin saddle necks (NORMAL_FLOOR = 0.25) so speculars never flip 180 degrees.\n float gl = max(length(g), 0.25);\n return SdfSample(d, g / gl);\n}\n\nvoid main() {\n if (uOpacity <= 0.001 || uPrimitiveCount <= 0) {\n fragColor = vec4(0.0);\n return;\n }\n\n // Convert GL UV (bottom-left origin) to local CSS px (top-left origin).\n vec2 pCss = vec2(vUv.x * uViewport.x, (1.0 - vUv.y) * uViewport.y);\n SdfSample sdf = evaluateGlassSdf(pCss);\n float d = sdf.dist;\n vec2 normal = sdf.normal;\n\n float aa = 1.0 / max(uDpr, 1.0);\n float glassMask = clamp(0.5 - d / aa, 0.0, 1.0);\n float outsideMask = 1.0 - glassMask;\n\n // 1. Outside-only drop shadow (d > 0)\n float shadowA = 0.0;\n if (outsideMask > 0.001 && uShadow.z > 0.001) {\n SdfSample shadowSdf = evaluateGlassSdf(pCss - vec2(0.0, uShadow.y));\n float sigma = max(uShadow.x * 0.5, 1.0);\n float shadowFalloff = 1.0 / (1.0 + exp(clamp(1.65 * shadowSdf.dist / sigma, -12.0, 12.0)));\n shadowA = outsideMask * shadowFalloff * uShadow.z * uOpacity;\n }\n\n // 2. Dark outer hairline: strictly outside when a uniform CSS inner border is present (d >= 0), otherwise straddling the outer edge (d >= -0.25)\n float hw = max(uHairline.x, 0.5 / max(uDpr, 1.0));\n float hasUniformBorder = step(0.001, uBorderParams.x);\n float hairlineLo = mix(-0.25, 0.0, hasUniformBorder);\n float hairlineBand = bandCoverage(d, hairlineLo, hairlineLo + hw, aa);\n float hairA = 0.0;\n if (hairlineBand > 0.001) {\n float ax = abs(normal.x);\n float ay = abs(normal.y);\n float cornerW = safePow(clamp(2.0 * ax * ay, 0.0, 1.0), 1.5);\n float sideVsFlat = mix(uHairline.y, uHairline.w, ay * ay);\n float hairlineProfileAlpha = mix(sideVsFlat, uHairline.z, cornerW);\n hairA = hairlineBand * hairlineProfileAlpha * uOpacity;\n }\n\n // 3. Optional 1px uniform inner border + directional/soft inner rim highlight (inset < 5.0 CSS px)\n float inset = max(-d, 0.0);\n float borderMask = 0.0;\n float borderA = 0.0;\n vec3 borderRgb = vec3(0.0);\n if (hasUniformBorder > 0.5 && d < 0.5 * aa && inset < uBorderParams.x + aa) {\n borderMask = bandCoverage(d, -uBorderParams.x, 0.0, aa);\n borderA = clamp(borderMask * uBorderColor.a * uOpacity, 0.0, 1.0);\n borderRgb = uBorderColor.rgb * borderA;\n }\n\n float rimA = 0.0;\n vec3 physLitRgb = vec3(0.0);\n float physLitA = 0.0;\n float physShadeA = 0.0;\n float isPhysicalRim = step(0.5, uPhysicalLight.w) * (1.0 - hasUniformBorder);\n\n if (glassMask > 0.001 && inset < 5.0 && uRimParams.x > 0.001 && isPhysicalRim < 0.5) {\n float ny = abs(normal.y);\n float wDirectional = 1.0 - clamp(uStyleMix, 0.0, 1.0);\n float wSoft = clamp(uStyleMix, 0.0, 1.0) * clamp(uRimOpacity, 0.0, 1.0);\n\n if (hasUniformBorder > 0.5) {\n // Match CSS inset box-shadow: keep inner rim inside the padding edge so the 1px border is not double-brightened\n float padInset = max(inset - uBorderParams.x, 0.0);\n float padMask = 1.0 - borderMask;\n float dirWeight = computeDirectionalRimWeight(normal, uRimParams.w, uBorderParams.y);\n float core = smoothstep(max(uRimParams.y, 0.4) + 0.6, 0.0, padInset);\n float tail = exp(-padInset / 1.8) * uRimParams.z * smoothstep(5.0, 3.2, inset);\n rimA = clamp((core + tail) * dirWeight * uRimParams.x * padMask * glassMask * uOpacity, 0.0, 1.0);\n } else {\n if (wDirectional > 0.001) {\n float dirWeight = computeDirectionalRimWeight(normal, uRimParams.w, uBorderParams.y);\n float core = smoothstep(max(uRimParams.y, 0.4) + 0.6, 0.0, inset);\n float tail = exp(-inset / 1.8) * uRimParams.z * smoothstep(5.0, 3.2, inset);\n rimA += (core + tail) * dirWeight * uRimParams.x * wDirectional;\n }\n\n if (wSoft > 0.001) {\n float bandT = clamp(inset / 5.0, 0.0, 1.0);\n float steppedT = min(floor(bandT * 9.0) / 9.0, 1.0);\n float bandCurve = mix(safePow(1.0 - bandT, 2.1), safePow(1.0 - steppedT, 2.1), 0.35);\n float rimCoreBoost = 0.65 + 0.35 * smoothstep(1.2, 0.0, inset);\n float angWeight = mix(0.015, 1.0, safePow(ny, 2.1)) * (normal.y < 0.0 ? 1.0 : 0.85);\n rimA += bandCurve * rimCoreBoost * angWeight * uRimParams.x * wSoft;\n }\n\n // Boost specular luminance to match source-over alpha blending expectations\n rimA = clamp(rimA * 1.35 * glassMask * uOpacity, 0.0, 1.0);\n }\n } else if (glassMask > 0.001 && isPhysicalRim > 0.5 && inset < uPhysicalParams.x) {\n float bezelPx = max(uPhysicalParams.x, 1.0);\n float t = clamp(inset / bezelPx, 0.0, 1.0);\n float eps = 0.015;\n float t0 = max(0.0, t - eps);\n float t1 = min(1.0, t + eps);\n float slope = (evalBezelHeight(t1, uPhysicalParams.w) - evalBezelHeight(t0, uPhysicalParams.w)) / max(t1 - t0, 1e-4);\n vec3 N = normalize(vec3(normal * slope, 1.0));\n vec3 L = uPhysicalLight.xyz;\n vec3 H = vec3(L.xy, L.z + 1.0);\n float hLen = max(length(H), 1e-4);\n const float shininess = 36.0;\n float flatBase = safePow(clamp((L.z + 1.0) / hLen, 0.0, 1.0), shininess);\n float denomBase = max(1.0 - flatBase, 1e-4);\n float hDot = clamp(dot(N, H) / hLen, 0.0, 1.0);\n float highlight = max(safePow(hDot, shininess) - flatBase, 0.0) / denomBase;\n vec3 H_bounce = vec3(-L.xy, L.z + 1.0);\n float bDot = clamp(dot(N, H_bounce) / hLen, 0.0, 1.0);\n float bounce = max(safePow(bDot, shininess) - flatBase, 0.0) / denomBase;\n vec2 planar = L.xy / max(length(L.xy), 1e-4);\n float facing = dot(normal, planar);\n float fresnel = safePow(clamp(1.0 - N.z, 0.0, 1.0), 4.0);\n float frontRim = fresnel * (0.25 + 0.75 * max(facing, 0.0));\n float backRim = fresnel * 0.45 * max(-facing, 0.0);\n float shineBand = bandCoverage(d, -1.2, 0.0, aa);\n float diagLobe = facing * facing;\n float bezelShine = shineBand * (0.18 + 0.82 * diagLobe * diagLobe) * uPhysicalOptics.z;\n float causticProfile = smoothstep(0.0, 0.25, t) * smoothstep(0.92, 0.18, t);\n float causticDir = max(max(-facing, 0.0), clamp(normal.y, 0.0, 1.0) * 0.65);\n float causticA = uPhysicalParams.y * causticProfile * causticDir * uPhysicalOptics.y * glassMask * uOpacity;\n float frontA = (uPhysicalParams.y * (highlight + bezelShine) + uRimParams.x * frontRim) * glassMask * uOpacity;\n float bounceA = (uPhysicalParams.y * uPhysicalOptics.x * bounce + uRimParams.x * backRim) * glassMask * uOpacity;\n vec3 bounceColor = mix(vec3(1.0), uRimBounceColor.rgb, clamp(uRimBounceColor.a, 0.0, 1.0));\n float litSum = frontA + bounceA + causticA;\n float totalLit = clamp(litSum, 0.0, 1.0);\n vec3 litRgb = vec3(frontA) + bounceColor * bounceA + vec3(1.0, 0.92, 0.86) * causticA;\n if (litSum > 1.0) {\n litRgb *= totalLit / litSum;\n }\n\n float shadeTerm = safePow(clamp(1.0 - N.z, 0.0, 1.0), 2.5) * (0.45 + 0.55 * max(-facing, 0.0));\n float dark = clamp(uPhysicalParams.z * shadeTerm * glassMask * uOpacity, 0.0, 1.0) * (1.0 - totalLit);\n physLitRgb = litRgb;\n physLitA = totalLit;\n physShadeA = dark;\n }\n\n // Keep interior strictly transparent when shadow, hairline, border, and rim are all zero\n if (shadowA <= 0.0001 && hairA <= 0.0001 && borderA <= 0.0001 && rimA <= 0.0001 && physLitA <= 0.0001 && physShadeA <= 0.0001) {\n fragColor = vec4(0.0);\n return;\n }\n\n // Premultiplied alpha composite: uniform border over inner/physical rim over hairline and shadow\n float darkA = clamp(shadowA + hairA * (1.0 - shadowA), 0.0, 1.0);\n vec3 shadeColor = vec3(0.03921569, 0.07058824, 0.10980392);\n vec3 afterRimRgb = vec3(rimA) + physLitRgb + shadeColor * physShadeA;\n float totalRimA = clamp(rimA + physLitA + physShadeA * (1.0 - rimA), 0.0, 1.0);\n float afterRimA = totalRimA + darkA * (1.0 - totalRimA);\n vec3 outRgb = borderRgb + afterRimRgb * (1.0 - borderA);\n float outA = clamp(borderA + afterRimA * (1.0 - borderA), 0.0, 1.0);\n fragColor = vec4(outRgb, outA);\n}\n";
|
|
19
19
|
/**
|
|
20
20
|
* Traces an SVG path string emitted by `extractFieldContourPath` (`M`, `L`, `A`, `Z`)
|
|
21
21
|
* directly onto a 2D Canvas context without relying on `Path2D`.
|