fix(glass): preserve content clarity across transparency (#656) (#657)

Co-authored-by: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com>
This commit is contained in:
jxxghp
2026-08-10 12:49:05 +08:00
committed by GitHub
co-authored by InfinityPacer
parent bb53a181a9
commit 6a4af66683
6 changed files with 80 additions and 7 deletions
+29
View File
@@ -6,6 +6,7 @@ import {
getGlassCssFrostBlur,
getGlassCoverScale,
getGlassMaterialResponse,
getGlassOverlayClarityBlur,
getGlassOpticalCssTransmissionBrightness,
getGlassOpticalDecay,
getGlassOpticalBufferSize,
@@ -269,6 +270,34 @@ describe('glass optics geometry', () => {
).toBe(true)
})
it('derives a continuous overlay clarity floor from transparency anchors', () => {
const anchors = [
[0, 8.9],
[20, 7.8],
[50, 6.7],
[70, 5.8],
[85, 5.4],
[100, 5],
] as const
for (const [transparency, blur] of anchors) {
expect(getGlassOverlayClarityBlur(transparency)).toBe(blur)
}
expect(getGlassOverlayClarityBlur(-1)).toBe(8.9)
expect(getGlassOverlayClarityBlur(101)).toBe(5)
expect(getGlassOverlayClarityBlur(Number.NaN)).toBe(6.7)
const samples = Array.from({ length: 101 }, (_, value) => getGlassOverlayClarityBlur(value))
expect(samples.every((sample, index) => index === 0 || sample <= samples[index - 1])).toBe(true)
for (const anchor of [20, 50, 70, 85]) {
const blur = getGlassOverlayClarityBlur(anchor)
expect(Math.abs(getGlassOverlayClarityBlur(anchor - 1) - blur)).toBeLessThan(0.02)
expect(Math.abs(getGlassOverlayClarityBlur(anchor + 1) - blur)).toBeLessThan(0.03)
}
})
it('returns preset copies so previews cannot mutate the shared matrix', () => {
const first = getGlassOpticalPresetParameters('tinted', 'high', 'glide')
first.translation = 0
+6
View File
@@ -250,6 +250,7 @@ const GLASS_SURFACE_DENSITY: Record<GlassAppearance, readonly number[]> = {
const GLASS_TINT_DENSITY = [1, 0.9, 0.65, 0.48, 0.36, 0.28] as const
const GLASS_FROST_DENSITY = [1, 0.9, 0.7, 0.34, 0.12, 0.04] as const
const GLASS_FROSTED_DENSITY = [1, 0.82, 0.55, 0.28, 0.1, 0.025] as const
const GLASS_OVERLAY_CLARITY_BLUR = [8.9, 7.8, 6.7, 5.8, 5.4, 5] as const
/** 在相邻业务锚点之间使用零斜率边界插值,避免滑杆经过锚点时出现视觉折线。 */
function interpolateGlassResponse(value: unknown, anchors: readonly number[]) {
@@ -292,6 +293,11 @@ export function getGlassCssFrostBlur(value: unknown) {
}
}
/** 透明与色调浮层保留独立模糊下限,避免高通透度使临时内容直接暴露在复杂壁纸上。 */
export function getGlassOverlayClarityBlur(value: unknown) {
return interpolateGlassResponse(value, GLASS_OVERLAY_CLARITY_BLUR)
}
/** 计算与 CSS `ease` 相同的交叉淡化进度,使 DOM 壁纸与 shader 双纹理保持同一时钟。 */
export function getGlassWallpaperTransitionProgress(elapsed: number, duration: number) {
if (duration <= 0 || elapsed >= duration) return 1