chore(cam): Liquid Glass UI kiti 2.0.0 → 2.0.4 (→ 2.13.1)
All checks were successful
Deploy / deploy (push) Successful in 8m24s

src/components/liquid-glass altındaki dört dosya kitin son hâlinden
(bilalgursen/liquid-glass@d80330a) yeniden kopyalandı: boşta kare
çizilmiyor, GPU'ya giden iş azaldı (Engine 2.0.2, Card 2.0.3).
Kitin gizli şerit düzeltmesi rozetin CSS şeridine taşındı.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
bilalgursen
2026-11-26 01:02:14 +03:00
parent e0406557ea
commit 8da03fcd6c
9 changed files with 382 additions and 109 deletions

View File

@@ -2111,7 +2111,7 @@ liquid glass olsun". Kaynak Bilal'in açık kaynak kiti **Liquid Glass UI**
- **Kitin 2.0 sürümüne geçildi** (Bilal, 25 Kas 2026: "burdaki liquid glassları güncel liquid - **Kitin 2.0 sürümüne geçildi** (Bilal, 25 Kas 2026: "burdaki liquid glassları güncel liquid
glass ile güncelle"; site 2.13.0). Motor ve bakış artık kitin kendisidir: glass ile güncelle"; site 2.13.0). Motor ve bakış artık kitin kendisidir:
`src/components/liquid-glass/` altında `engine.ts`, `dom-snapshot.ts`, `glass-layer.tsx`, `src/components/liquid-glass/` altında `engine.ts`, `dom-snapshot.ts`, `glass-layer.tsx`,
`glass-lens.tsx` (bilalgursen/liquid-glass@9c65d01) **olduğu gibi** durur, elle değiştirilmez; `glass-lens.tsx` (bilalgursen/liquid-glass@d80330a, kit 2.0.4; 26 Kas 2026'da 2.0.0'dan güncellendi: boşta kare çizilmez, GPU yükü azaldı) **olduğu gibi** durur, elle değiştirilmez;
kit güncellenince dosyalar yeniden kopyalanır (lint ve `pnpm tasarim:denetim` bu klasörü kit güncellenince dosyalar yeniden kopyalanır (lint ve `pnpm tasarim:denetim` bu klasörü
kitin biçiminde bırakır). `sivi-cam.tsx` yalnız sarmalayıcıdır: `SiviCam` kitin `GlassLayer`'ının kitin biçiminde bırakır). `sivi-cam.tsx` yalnız sarmalayıcıdır: `SiviCam` kitin `GlassLayer`'ının
uyarlaması (ok damlası kendiliğinden bulunur, üstüne gelince ya da `otoDamla`'da ayrılır, uyarlaması (ok damlası kendiliğinden bulunur, üstüne gelince ya da `otoDamla`'da ayrılır,

View File

@@ -1,6 +1,6 @@
{ {
"name": "kolaytercih", "name": "kolaytercih",
"version": "2.13.0", "version": "2.13.1",
"private": true, "private": true,
"engines": { "engines": {
"node": ">=22" "node": ">=22"

View File

@@ -1418,6 +1418,11 @@ html.lenis body {
.kt-yeni-serit { .kt-yeni-serit {
animation: kt-yeni-serit 5s linear infinite; animation: kt-yeni-serit 5s linear infinite;
} }
/* Cam rozeti çizince gizlenen CSS şeridi de durur (kit 2.0.2): görünmeden akan şerit,
sayfadaki her karede katmanların yeniden hesaplanmasına yol açıyordu. */
[data-glass-ready] .kt-yeni-serit {
animation: none;
}
.kt-yeni-sabit { .kt-yeni-sabit {
display: none; display: none;
} }

View File

@@ -33,6 +33,14 @@ type Surum = {
}; };
const SURUMLER: Surum[] = [ const SURUMLER: Surum[] = [
{
surum: "2.13.1",
tarih: "26 Kasım 2026",
maddeler: [],
arayuz: [
"Sıvı cam görünümü hafifledi: cam hareket etmiyorken artık hiç çizilmiyor, hareket ederken de cihazını daha az yoruyor. Sayfayı kaydırırken ve telefonda daha akıcı.",
],
},
{ {
surum: "2.13.0", surum: "2.13.0",
tarih: "25 Kasım 2026", tarih: "25 Kasım 2026",

View File

@@ -1,5 +1,5 @@
// KolayTercih (DESIGN.md §4.50): Liquid Glass UI 2.0.0'dan (bilalgursen/liquid-glass@9c65d01, // KolayTercih (DESIGN.md §4.50): Liquid Glass UI 2.0.4'ten (bilalgursen/liquid-glass@d80330a,
// 24 Kas 2026) olduğu gibi alındı. Elle değiştirilmez; kit güncellenince dosya yeniden kopyalanır. // 25 Kas 2026) olduğu gibi alındı. Elle değiştirilmez; kit güncellenince dosya yeniden kopyalanır.
// dom-snapshot — paints a DOM subtree into a Canvas2D context at its on-screen position. // dom-snapshot — paints a DOM subtree into a Canvas2D context at its on-screen position.
// //
@@ -475,14 +475,15 @@ function drawText(
originY: number, originY: number,
lang: string | undefined, lang: string | undefined,
isVisible: (rect: DOMRect) => boolean, isVisible: (rect: DOMRect) => boolean,
range: Range,
) { ) {
const raw = node.textContent ?? '' const raw = node.textContent ?? ''
let text = raw.replace(/\s+/g, ' ').trim() let text = raw.replace(/\s+/g, ' ').trim()
if (!text) return if (!text) return
const range = document.createRange()
range.selectNodeContents(node) range.selectNodeContents(node)
const lines = [...range.getClientRects()].filter((rect) => rect.width > 0.5) const lines = [...range.getClientRects()].filter((rect) => rect.width > 0.5)
if (!lines.length) return // No line of it shows: its font is not set up and nothing is measured.
if (!lines.some(isVisible)) return
// The page shows the transformed text. Upper and lower case follow the page's // The page shows the transformed text. Upper and lower case follow the page's
// language (Turkish i → İ); browsers capitalise without it. // language (Turkish i → İ); browsers capitalise without it.
const transform = style.textTransform const transform = style.textTransform
@@ -533,10 +534,12 @@ let scratch: HTMLCanvasElement | undefined
function blurBackdrop(ctx: CanvasRenderingContext2D, box: Box, radius: number, blurPx: number) { function blurBackdrop(ctx: CanvasRenderingContext2D, box: Box, radius: number, blurPx: number) {
const matrix = ctx.getTransform() const matrix = ctx.getTransform()
const scale = matrix.a const scale = matrix.a
// (A context may be scaled a hair differently each way: the engine fits a small picture to its canvas.)
const scaleY = matrix.d
const left = Math.max(0, Math.floor(box.x * scale + matrix.e)) const left = Math.max(0, Math.floor(box.x * scale + matrix.e))
const top = Math.max(0, Math.floor(box.y * scale + matrix.f)) const top = Math.max(0, Math.floor(box.y * scaleY + matrix.f))
const w = Math.min(ctx.canvas.width, Math.ceil((box.x + box.w) * scale + matrix.e)) - left const w = Math.min(ctx.canvas.width, Math.ceil((box.x + box.w) * scale + matrix.e)) - left
const h = Math.min(ctx.canvas.height, Math.ceil((box.y + box.h) * scale + matrix.f)) - top const h = Math.min(ctx.canvas.height, Math.ceil((box.y + box.h) * scaleY + matrix.f)) - top
if (w < 1 || h < 1) return if (w < 1 || h < 1) return
const pad = Math.ceil(blurPx * scale * 3) const pad = Math.ceil(blurPx * scale * 3)
scratch ??= document.createElement('canvas') scratch ??= document.createElement('canvas')
@@ -634,6 +637,23 @@ function clipShape(value: string, box: Box): Path2D | null {
return shape return shape
} }
/** Screen-reader-only text (a 1 px square) and empty boxes: never painted. */
const isEmpty = (rect: DOMRect) => rect.width <= 0 || rect.height <= 0 || (rect.width <= 1 && rect.height <= 1)
let locale: { of: string; is: string | undefined } | undefined
/** The page's language as a locale, worked out once for each value of `lang`. */
function localeOf(lang: string) {
if (locale?.of === lang) return locale.is
let is: string | undefined
try {
is = Intl.getCanonicalLocales(lang)[0]
} catch {
// Not a language tag: the default locale's rules apply.
}
locale = { of: lang, is }
return is
}
export function drawDom(ctx: CanvasRenderingContext2D, root: Element, options: DomSnapshotOptions) { export function drawDom(ctx: CanvasRenderingContext2D, root: Element, options: DomSnapshotOptions) {
const { origin, region, skip, onStale, cacheKey = document.documentElement.className, found } = options const { origin, region, skip, onStale, cacheKey = document.documentElement.className, found } = options
const originX = origin.left const originX = origin.left
@@ -641,14 +661,10 @@ export function drawDom(ctx: CanvasRenderingContext2D, root: Element, options: D
const deferred: { element: Element; opacity: number }[] = [] const deferred: { element: Element; opacity: number }[] = []
const intersects = (rect: DOMRect) => const intersects = (rect: DOMRect) =>
!region || (rect.right > region.left && rect.left < region.right && rect.bottom > region.top && rect.top < region.bottom) !region || (rect.right > region.left && rect.left < region.right && rect.bottom > region.top && rect.top < region.bottom)
let lang: string | undefined const lang = localeOf(document.documentElement.lang)
try { const range = document.createRange()
lang = Intl.getCanonicalLocales(document.documentElement.lang)[0]
} catch {
// Not a language tag: the default locale's rules apply.
}
const walk = (element: Element, parentOpacity: number, isDeferred = false, style = getComputedStyle(element)) => { const walk = (element: Element, parentOpacity: number, isDeferred = false, style = getComputedStyle(element), measured?: DOMRect) => {
if (skip?.(element)) return if (skip?.(element)) return
if (style.display === 'none' || style.visibility === 'hidden') return if (style.display === 'none' || style.visibility === 'hidden') return
const opacity = parentOpacity * Number(style.opacity) const opacity = parentOpacity * Number(style.opacity)
@@ -660,18 +676,33 @@ export function drawDom(ctx: CanvasRenderingContext2D, root: Element, options: D
} }
const drawChildren = () => { const drawChildren = () => {
const inFlexOrGrid = /flex|grid/.test(style.display) const inFlexOrGrid = /flex|grid/.test(style.display)
const children = [...element.childNodes].map((node) => { const children: { node: ChildNode; childStyle: CSSStyleDeclaration | null; layer: number; z: number; rect?: DOMRect }[] = []
const childStyle = node instanceof Element ? getComputedStyle(node) : null for (const node of element.childNodes) {
const [layer, z] = childStyle ? layerOf(childStyle, inFlexOrGrid) : [1, 0] if (!(node instanceof Element)) {
return { node, childStyle, layer, z } children.push({ node, childStyle: null, layer: 1, z: 0 })
}) continue
}
const childStyle = getComputedStyle(node)
// Most siblings on the way down to the region lie outside it, and nothing of such a box is
// painted (see `walk`): it is left out here, before its place among its siblings is worked
// out, which takes most of what is read of an element. Kept whatever its box: an element
// pinned to the viewport (it is met again at the end, and reported in `found`) and one
// without a box of its own (`display: contents`).
let rect: DOMRect | undefined
if (childStyle.position !== 'fixed' && childStyle.position !== 'sticky' && childStyle.display !== 'contents') {
rect = node.getBoundingClientRect()
if (isEmpty(rect) || !intersects(rect)) continue
}
const [layer, z] = layerOf(childStyle, inFlexOrGrid)
children.push({ node, childStyle, layer, z, rect })
}
// The sort is stable: within a layer, document order. // The sort is stable: within a layer, document order.
children.sort((a, b) => a.layer - b.layer || a.z - b.z) children.sort((a, b) => a.layer - b.layer || a.z - b.z)
for (const { node, childStyle } of children) { for (const { node, childStyle, rect } of children) {
if (childStyle) walk(node as Element, opacity, false, childStyle) if (childStyle) walk(node as Element, opacity, false, childStyle, rect)
else if (node.nodeType === Node.TEXT_NODE) { else if (node.nodeType === Node.TEXT_NODE) {
ctx.globalAlpha = opacity ctx.globalAlpha = opacity
drawText(ctx, node as Text, style, originX, originY, lang, intersects) drawText(ctx, node as Text, style, originX, originY, lang, intersects, range)
} }
} }
} }
@@ -679,10 +710,11 @@ export function drawDom(ctx: CanvasRenderingContext2D, root: Element, options: D
drawChildren() drawChildren()
return return
} }
const rect = element.getBoundingClientRect() // (Nothing on the page moves during a walk: a box measured among its siblings is still right.)
const rect = measured ?? element.getBoundingClientRect()
// Screen-reader-only text (a 1 px square) and empty boxes are not painted, a hairline is; // Screen-reader-only text (a 1 px square) and empty boxes are not painted, a hairline is;
// nothing outside the region is visited. // nothing outside the region is visited.
if (rect.width <= 0 || rect.height <= 0 || (rect.width <= 1 && rect.height <= 1) || !intersects(rect)) return if (isEmpty(rect) || !intersects(rect)) return
if (found) { if (found) {
if (isDeferred) found.touched = true if (isDeferred) found.touched = true
else if (!found.loose) { else if (!found.loose) {

View File

@@ -1,5 +1,5 @@
// KolayTercih (DESIGN.md §4.50): Liquid Glass UI 2.0.0'dan (bilalgursen/liquid-glass@9c65d01, // KolayTercih (DESIGN.md §4.50): Liquid Glass UI 2.0.4'ten (bilalgursen/liquid-glass@d80330a,
// 24 Kas 2026) olduğu gibi alındı. Elle değiştirilmez; kit güncellenince dosya yeniden kopyalanır. // 25 Kas 2026) olduğu gibi alındı. Elle değiştirilmez; kit güncellenince dosya yeniden kopyalanır.
// Liquid Glass engine — one shared WebGL2 context that draws every glass surface on the // Liquid Glass engine — one shared WebGL2 context that draws every glass surface on the
// page and copies each result into the surface's own 2D <canvas>, so a page full of // page and copies each result into the surface's own 2D <canvas>, so a page full of
@@ -11,7 +11,8 @@
// //
// Cost model: the loop runs only while a spring moves, a surface is dirty or the // Cost model: the loop runs only while a spring moves, a surface is dirty or the
// cursor light changes; at rest it stops completely. Off-screen surfaces are not // cursor light changes; at rest it stops completely. Off-screen surfaces are not
// drawn, and neither is a frame that would come out exactly as the one on the canvas. // drawn, and neither is a frame that would come out exactly as the one on the canvas:
// nothing is asked of the GPU for it, and a frame that is drawn sends only what changed.
// `prefers-reduced-motion` freezes every spring at its target. // `prefers-reduced-motion` freezes every spring at its target.
// If WebGL2 is missing or the context is lost, every surface falls back to plain CSS. // If WebGL2 is missing or the context is lost, every surface falls back to plain CSS.
// //
@@ -755,6 +756,15 @@ uniform float uGlowBlob;
uniform vec4 uLight; uniform vec4 uLight;
uniform vec4 uBlobMat; uniform vec4 uBlobMat;
uniform vec3 uBlobLine; uniform vec3 uBlobLine;
// The frost of large glass, worked out beforehand at a fraction of the size (FROST_PASS in the
// engine). uFrostPass.x: 0 = no such picture, the frost is worked out here as ever; 1 = this draw
// is that picture; 2 = this draw reads it. Then how many pixels one of its texels covers each
// way, and 1 / (that x the picture's size), to find a pixel in it.
uniform sampler2D uFrostPic;
uniform vec4 uFrostPass;
// How many halvings smaller the picture of the page was painted (BACK_SKIP in the engine): its
// mip levels are read that many lower.
uniform float uBackSkip;
uniform float uCssPx; uniform float uCssPx;
uniform sampler2D uAround; uniform sampler2D uAround;
uniform vec4 uAroundBox; uniform vec4 uAroundBox;
@@ -785,7 +795,7 @@ vec2 toUv(vec2 d) {
return clamp(vec2(q.x / uSize.x, 1.0 - q.y / uSize.y), vec2(0.0005), vec2(0.9995)); return clamp(vec2(q.x / uSize.x, 1.0 - q.y / uSize.y), vec2(0.0005), vec2(0.9995));
} }
vec3 backdrop(vec2 st, float lod) { vec3 backdrop(vec2 st, float lod) {
vec4 c = textureLod(uBack, st, lod); vec4 c = textureLod(uBack, st, max(lod - uBackSkip, 0.0));
return c.rgb + (1.0 - c.a) * uSurface; return c.rgb + (1.0 - c.a) * uSurface;
} }
// What surrounds the glass (GlassLens.reflection), at a point of the canvas in design units and // What surrounds the glass (GlassLens.reflection), at a point of the canvas in design units and
@@ -922,9 +932,25 @@ vec3 frostedRadial(vec2 q, float dq, float sigma) {
} }
return total > 1e-4 ? sum / total : backdrop(toUv(uCenter + q + radialBend(q, dq)), lod); return total > 1e-4 ? sum / total : backdrop(toUv(uCenter + q + radialBend(q, dq)), lod);
} }
// How much of the frost this deep in the glass is read from the picture (0 = worked out here).
// Within four of the picture's texels of the rim it is worked out in full: it changes too fast
// there for a smaller picture. The picture fades in over the inner half of that band.
float frostDeep(float d) {
if (uFrostPass.x < 1.5) return 0.0;
float band = 4.0 * uFrostPass.y * uDevicePx;
return 1.0 - smoothstep(-band, -0.5 * band, d);
}
vec3 frostPicture() {
return texture(uFrostPic, gl_FragCoord.xy * uFrostPass.zw).rgb;
}
void main() { void main() {
vec2 px = vec2(gl_FragCoord.x, uSize.y - gl_FragCoord.y); // The frost's own pass draws one texel for every uFrostPass.y pixels each way, and a little
// past the rim, so that a pixel on the rim finds its neighbours in the picture.
bool pre = uFrostPass.x > 0.5 && uFrostPass.x < 1.5;
vec2 fc = pre ? gl_FragCoord.xy * uFrostPass.y : gl_FragCoord.xy;
float frostReach = pre ? 1.0 + 2.0 * uFrostPass.y * uDevicePx : 1.0;
vec2 px = vec2(fc.x, uSize.y - fc.y);
vec2 local = px / uUnit - uCenter; vec2 local = px / uUnit - uCenter;
float dist = shape(local); float dist = shape(local);
@@ -1080,12 +1106,12 @@ void main() {
if (uNearPair[i].x > 0.5) cover *= step(s, fade + 2.0 * uDevicePx); if (uNearPair[i].x > 0.5) cover *= step(s, fade + 2.0 * uDevicePx);
else cover *= smoothstep(fade, -fade, s); else cover *= smoothstep(fade, -fade, s);
} }
if (cover <= 0.0) { if (cover <= 0.0 && !pre) {
outColor = outsideCol * (1.0 - mask); outColor = outsideCol * (1.0 - mask);
return; return;
} }
} }
if (mask <= 0.0) { if (mask <= 0.0 && !pre) {
outColor = outsideCol; outColor = outsideCol;
return; return;
} }
@@ -1115,8 +1141,14 @@ void main() {
// Radial bend, then frost: the old SVG card's rim. // Radial bend, then frost: the old SVG card's rim.
float ratio = radialRatio(dist); float ratio = radialRatio(dist);
float sharpLod = max(uBlurShift, 0.0); float sharpLod = max(uBlurShift, 0.0);
if (uFrostBlur > 0.0 && dist < 1.0) { if (uFrostBlur > 0.0 && dist < frostReach) {
vec3 frost = frostedRadial(local, dist, uFrostBlur * mix(1.0, uFrostEdge, pow(ratio, 1.3))); float deep = frostDeep(dist);
vec3 frost = deep > 0.0 ? frostPicture() : vec3(0.0);
if (deep < 1.0) frost = mix(frostedRadial(local, dist, uFrostBlur * mix(1.0, uFrostEdge, pow(ratio, 1.3))), frost, deep);
if (pre) {
outColor = vec4(frost, 1.0);
return;
}
glass = uFrostMix < 1.0 ? mix(bent(uCenter + local, radialBend(local, dist), uDisp * 0.35, sharpLod), frost, uFrostMix) : frost; glass = uFrostMix < 1.0 ? mix(bent(uCenter + local, radialBend(local, dist), uDisp * 0.35, sharpLod), frost, uFrostMix) : frost;
} else { } else {
glass = bent(uCenter + local, radialBend(local, dist), uDisp * 0.35, sharpLod); glass = bent(uCenter + local, radialBend(local, dist), uDisp * 0.35, sharpLod);
@@ -1139,10 +1171,16 @@ void main() {
float split = uDisp * 0.35 * (1.0 - own); float split = uDisp * 0.35 * (1.0 - own);
float lod = max(mix(uBlurCenter, uBlurEdge, pow(bendEdge, 1.3)) + blurShift, 0.0); float lod = max(mix(uBlurCenter, uBlurEdge, pow(bendEdge, 1.3)) + blurShift, 0.0);
vec2 at = uCenter + magnified; vec2 at = uCenter + magnified;
if (frostBlur > 0.0 && dist < 1.0) { if (frostBlur > 0.0 && dist < frostReach) {
// Frosted (inside the glass only: outside, nothing of it shows). The frost hides the // Frosted (inside the glass only: outside, nothing of it shows). The frost hides the
// colour split, so one bent point is enough; uFrostMix lets the sharp bend show through. // colour split, so one bent point is enough; uFrostMix lets the sharp bend show through.
vec3 frost = frosted(at + bend, frostBlur * mix(1.0, uFrostEdge, pow(bendEdge, 1.3))); float deep = frostDeep(dist);
vec3 frost = deep > 0.0 ? frostPicture() : vec3(0.0);
if (deep < 1.0) frost = mix(frosted(at + bend, frostBlur * mix(1.0, uFrostEdge, pow(bendEdge, 1.3))), frost, deep);
if (pre) {
outColor = vec4(frost, 1.0);
return;
}
glass = uFrostMix < 1.0 ? mix(bent(at, bend, split, lod), frost, uFrostMix) : frost; glass = uFrostMix < 1.0 ? mix(bent(at, bend, split, lod), frost, uFrostMix) : frost;
} else { } else {
glass = bent(at, bend, split, lod); glass = bent(at, bend, split, lod);
@@ -1154,6 +1192,12 @@ void main() {
glass = mix(uSurface, uColor, 1.0 - edge * uEdgeClear); glass = mix(uSurface, uColor, 1.0 - edge * uEdgeClear);
} }
// (The frost's own pass ends here: where there is no frost, its picture is empty.)
if (pre) {
outColor = vec4(0.0);
return;
}
// Top reflection. // Top reflection.
float top = ((1.0 - smoothstep(-0.05, 0.75, ny)) * (1.0 - nx * 0.12) * uTopRefl * 0.6 + uTopBase) * lit; float top = ((1.0 - smoothstep(-0.05, 0.75, ny)) * (1.0 - nx * 0.12) * uTopRefl * 0.6 + uTopBase) * lit;
vec3 topDim = dim(1.0 - vec3(1.0, 1.0, 0.72) * top); vec3 topDim = dim(1.0 - vec3(1.0, 1.0, 0.72) * top);
@@ -1296,9 +1340,7 @@ function createEngine(): GlassEngine | null {
if (!s) return null if (!s) return null
gl.shaderSource(s, src) gl.shaderSource(s, src)
gl.compileShader(s) gl.compileShader(s)
if (gl.getShaderParameter(s, gl.COMPILE_STATUS)) return s return s
console.warn('[liquid-glass] shader failed to compile', gl.getShaderInfoLog(s))
return null
} }
const vs = compile(gl.VERTEX_SHADER, VERTEX) const vs = compile(gl.VERTEX_SHADER, VERTEX)
const fs = compile(gl.FRAGMENT_SHADER, FRAGMENT) const fs = compile(gl.FRAGMENT_SHADER, FRAGMENT)
@@ -1307,7 +1349,12 @@ function createEngine(): GlassEngine | null {
gl.attachShader(program, vs) gl.attachShader(program, vs)
gl.attachShader(program, fs) gl.attachShader(program, fs)
gl.linkProgram(program) gl.linkProgram(program)
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) return null // A shader's own status is asked for only when linking fails: every such question waits for
// the GPU, and a program that linked has answered it.
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
for (const s of [vs, fs]) if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) console.warn('[liquid-glass] shader failed to compile', gl.getShaderInfoLog(s))
return null
}
gl.useProgram(program) gl.useProgram(program)
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer()) gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW)
@@ -1315,34 +1362,109 @@ function createEngine(): GlassEngine | null {
gl.enableVertexAttribArray(attr) gl.enableVertexAttribArray(attr)
gl.vertexAttribPointer(attr, 2, gl.FLOAT, false, 0, 0) gl.vertexAttribPointer(attr, 2, gl.FLOAT, false, 0, 0)
// Two shared canvases for textured lenses: what lies beneath, and what rides on top. // Shared canvases for textured lenses: what lies beneath, and what rides on top.
// Each view keeps its own pair of textures, so a frame that only moves the light re-uses them. // Each view keeps its own pair of textures, so a frame that only moves the light re-uses them.
const layer = () => { const layer = () => {
const canvas = document.createElement('canvas') const canvas = document.createElement('canvas')
return { canvas, ctx: canvas.getContext('2d') } return { canvas, ctx: canvas.getContext('2d') }
} }
const texture = (mipmapped: boolean) => { const filters = (mipmapped: boolean) => {
const tex = gl.createTexture()
gl.bindTexture(gl.TEXTURE_2D, tex)
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4))
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, mipmapped ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR) gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, mipmapped ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR)
}
const texture = (mipmapped: boolean) => {
const tex = gl.createTexture()
gl.bindTexture(gl.TEXTURE_2D, tex)
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4))
filters(mipmapped)
if (mipmapped) gl.generateMipmap(gl.TEXTURE_2D) if (mipmapped) gl.generateMipmap(gl.TEXTURE_2D)
return tex return tex
} }
/** A picture on the GPU, and the size its storage was made for (0 = none yet). */
type Picture = { tex: WebGLTexture | null; w: number; h: number }
/**
* Puts a canvas into a picture, on the texture unit that is active. Its storage is made once
* for a size (with every mip level, where the picture is seen blurred) and a canvas of that size
* is then written into it in place: asking for a new image on every upload makes the GPU give
* the texture new storage each time.
*/
const upload = (to: Picture, from: HTMLCanvasElement, mipmapped: boolean) => {
const w = from.width
const h = from.height
if (!to.tex || to.w !== w || to.h !== h) {
if (to.tex) gl.deleteTexture(to.tex)
to.tex = gl.createTexture()
gl.bindTexture(gl.TEXTURE_2D, to.tex)
filters(mipmapped)
gl.texStorage2D(gl.TEXTURE_2D, mipmapped ? Math.floor(Math.log2(Math.max(w, h))) + 1 : 1, gl.RGBA8, w, h)
to.w = w
to.h = h
} else gl.bindTexture(gl.TEXTURE_2D, to.tex)
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, from)
if (mipmapped) gl.generateMipmap(gl.TEXTURE_2D)
}
const back = layer() const back = layer()
const front = layer() const front = layer()
if (!back.ctx || !front.ctx) return null if (!back.ctx || !front.ctx) return null
type Painted = { back: WebGLTexture | null; front: WebGLTexture | null; w: number; h: number; at: number } // The pair is kept per size, for the sizes last drawn: one pair sized to every view in turn was
// given a new backing store for each of them, on every frame. The front canvas is made when a
// painter first asks for one.
type Layer = ReturnType<typeof layer>
type Layers = { back: Layer; front: Layer | null; used: number }
const LAYER_SIZES = 12
const layersOf = new Map<string, Layers>()
let layerUse = 0
const sized = (w: number, h: number) => {
const l = layer()
l.canvas.width = w
l.canvas.height = h
return l
}
const layersFor = (w: number, h: number, fw: number, fh: number) => {
const key = `${w}x${h}|${fw}x${fh}`
let l = layersOf.get(key)
if (!l) {
if (layersOf.size >= LAYER_SIZES) {
// The size drawn longest ago gives its canvases back.
let oldest = ''
let least = Infinity
for (const [k, o] of layersOf) if (o.used < least) [oldest, least] = [k, o.used]
const gone = layersOf.get(oldest)
for (const o of gone ? [gone.back, gone.front] : []) if (o) o.canvas.width = o.canvas.height = 0
layersOf.delete(oldest)
}
layersOf.set(key, (l = { back: sized(w, h), front: null, used: 0 }))
}
if (fw && !l.front) l.front = sized(fw, fh)
l.used = ++layerUse
return l
}
/**
* Glass frosted all over shows nothing of the page sharper than its frost: every reading of the
* page is at mip level log2(0.8 × the frost's softness in device px) − 0.5 or above (frosted in
* FRAGMENT). The levels beneath that are never read. So the page is painted that many halvings
* smaller to begin with, `most` at most, and the shader reads it that many levels lower
* (uBackSkip): a quarter or a sixteenth of the pixels to paint, upload and build mipmaps from,
* on every frame of live glass. Glass that shows the page sharp anywhere (no frost, a frost
* mixed with the sharp bend, a blob with a glass of its own) keeps the full picture.
*/
const BACK_SKIP = { most: 2 }
const backSkipOf = (m: GlassLens, dpr: number) => {
const r = m.refraction
if (!r || m.blob?.material || clamp(r.blurMix ?? 1) < 1) return 0
const soft = Math.max(0, r.blur ?? 0) * Math.min(1, Math.max(0.05, m.tune?.frostEdge ?? 1)) * dpr
return soft > 0 ? clamp(Math.floor(Math.log2(soft * 0.8) - 0.5), 0, BACK_SKIP.most) : 0
}
type Painted = { back: Picture; front: Picture; w: number; h: number; skip: number; at: number }
const painted = new Map<GlassView, Painted>() const painted = new Map<GlassView, Painted>()
// A third, small one for what surrounds a lens (its reflection), and each view's own texture of it: // A third, small one for what surrounds a lens (its reflection), and each view's own texture of it:
// where the picture was taken (the canvas's box then, CSS px) and how far past it it reaches. // where the picture was taken (the canvas's box then, CSS px) and how far past it it reaches.
const around = layer() const around = layer()
if (!around.ctx) return null if (!around.ctx) return null
/** `busy`: a picture is due (or was taken) while something on the page moved or was lit: it is taken once all is still. */ /** `busy`: a picture is due (or was taken) while something on the page moved or was lit: it is taken once all is still. */
type Mirrored = { tex: WebGLTexture | null; w: number; h: number; at: number; left: number; top: number; reach: number; due: boolean; timer: number; busy: boolean } type Mirrored = { pic: Picture; w: number; h: number; at: number; left: number; top: number; reach: number; due: boolean; timer: number; busy: boolean }
/** The pictures of the surroundings taken on this frame. */ /** The pictures of the surroundings taken on this frame. */
const pictured: Mirrored[] = [] const pictured: Mirrored[] = []
const mirrored = new Map<GlassView, Mirrored>() const mirrored = new Map<GlassView, Mirrored>()
@@ -1361,6 +1483,10 @@ function createEngine(): GlassEngine | null {
let ranLast = false let ranLast = false
// What a lens without layers samples (and ignores): a texture unit is never left empty. // What a lens without layers samples (and ignores): a texture unit is never left empty.
const blank = { back: texture(true), front: texture(false) } const blank = { back: texture(true), front: texture(false) }
// (The frost's picture has a texture unit of its own, never left empty either.)
gl.activeTexture(gl.TEXTURE3)
gl.bindTexture(gl.TEXTURE_2D, blank.front)
gl.activeTexture(gl.TEXTURE0)
/** The page behind a still lens is read again this often while only the light moves (ms). */ /** The page behind a still lens is read again this often while only the light moves (ms). */
const REPAINT_EVERY = 120 const REPAINT_EVERY = 120
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true) gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true)
@@ -1368,22 +1494,81 @@ function createEngine(): GlassEngine | null {
gl.uniform1i(gl.getUniformLocation(program, 'uBack'), 0) gl.uniform1i(gl.getUniformLocation(program, 'uBack'), 0)
gl.uniform1i(gl.getUniformLocation(program, 'uFront'), 1) gl.uniform1i(gl.getUniformLocation(program, 'uFront'), 1)
gl.uniform1i(gl.getUniformLocation(program, 'uAround'), 2) gl.uniform1i(gl.getUniformLocation(program, 'uAround'), 2)
/**
* The frost's own pass. Frost is 32 readings of the page for every pixel of the glass, most of
* what the GPU does for a frosted card. From `area` device px of glass up, and where the frost
* is at least `sigma` device px soft, it is first worked out into a picture a fraction of the
* size: one texel for every (its softness ÷ `texel`) px each way, `most` at most, since a frost
* that soft has nothing finer to show. The glass then reads that picture, except along its rim
* (frostDeep in FRAGMENT). Smaller glass gains nothing from a second pass and keeps the one.
* Measured on the same cards drawn both ways, the two pictures differ by 5 levels in 255 at
* most, and by more than 1 on fewer than one pixel in a thousand. A blob with a glass of its own (a surface that opens)
* frosts by a different amount at every point, and keeps the one pass too.
*/
const FROST_PASS = { area: 150_000, sigma: 5, texel: 2.5, most: 3 }
gl.uniform1i(gl.getUniformLocation(program, 'uFrostPic'), 3)
const frostPassAt = gl.getUniformLocation(program, 'uFrostPass')
/** What uFrostPass.x holds now. */
let frostPassHeld = 0
const frostPic = { tex: null as WebGLTexture | null, fbo: null as WebGLFramebuffer | null, w: 0, h: 0, broken: false }
/** Makes room in the frost's picture for w × h texels (it only grows). False where this GPU cannot draw into it. */
const frostRoom = (w: number, h: number) => {
if (frostPic.broken) return false
if (frostPic.tex && frostPic.w >= w && frostPic.h >= h) return true
const tw = Math.max(frostPic.w, w)
const th = Math.max(frostPic.h, h)
if (frostPic.tex) gl.deleteTexture(frostPic.tex)
frostPic.tex = gl.createTexture()
gl.activeTexture(gl.TEXTURE3)
gl.bindTexture(gl.TEXTURE_2D, frostPic.tex)
filters(false)
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA8, tw, th)
frostPic.fbo ??= gl.createFramebuffer()
gl.bindFramebuffer(gl.FRAMEBUFFER, frostPic.fbo)
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, frostPic.tex, 0)
// Asked once for each size the picture grows to: the answer waits for the GPU.
frostPic.broken = gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
frostPic.w = tw
frostPic.h = th
return !frostPic.broken
}
const locations = new Map<string, WebGLUniformLocation | null>() const locations = new Map<string, WebGLUniformLocation | null>()
const u = (name: string) => { const u = (name: string) => {
if (!locations.has(name)) locations.set(name, gl.getUniformLocation(program, name)) if (!locations.has(name)) locations.set(name, gl.getUniformLocation(program, name))
return locations.get(name) ?? null return locations.get(name) ?? null
} }
// Every uniform of a frame goes through `set`, which keeps the values: a view whose frame // Every uniform of a frame goes through `set`, which keeps the values: a view whose frame
// would come out exactly as the one already on its canvas is not drawn again. // would come out exactly as the one already on its canvas is not drawn again, and nothing is
// asked of the GPU for it. A frame that is drawn sends them with `send`: only those that differ
// from what the program (one for every view) already holds.
const sent: number[] = [] const sent: number[] = []
const names: string[] = []
const sizes: number[] = []
const set = (name: string, a: number, b?: number, c?: number, d?: number) => { const set = (name: string, a: number, b?: number, c?: number, d?: number) => {
const at = u(name) names.push(name)
if (b === undefined) gl.uniform1f(at, a) sizes.push(b === undefined ? 1 : c === undefined ? 2 : d === undefined ? 3 : 4)
else if (c === undefined) gl.uniform2f(at, a, b)
else if (d === undefined) gl.uniform3f(at, a, b, c)
else gl.uniform4f(at, a, b, c, d)
sent.push(a, b ?? 0, c ?? 0, d ?? 0) sent.push(a, b ?? 0, c ?? 0, d ?? 0)
} }
const held = new Map<string, [number, number, number, number]>()
const send = () => {
for (let i = 0; i < names.length; i++) {
const at = i * 4
const a = sent[at]
const b = sent[at + 1]
const c = sent[at + 2]
const d = sent[at + 3]
let h = held.get(names[i])
if (h && h[0] === a && h[1] === b && h[2] === c && h[3] === d) continue
if (!h) held.set(names[i], (h = [a, b, c, d]))
else [h[0], h[1], h[2], h[3]] = [a, b, c, d]
const to = u(names[i])
if (sizes[i] === 1) gl.uniform1f(to, a)
else if (sizes[i] === 2) gl.uniform2f(to, a, b)
else if (sizes[i] === 3) gl.uniform3f(to, a, b, c)
else gl.uniform4f(to, a, b, c, d)
}
}
/** What a view's canvas shows now: its uniforms (empty = nothing usable) and its CSS box. */ /** What a view's canvas shows now: its uniforms (empty = nothing usable) and its CSS box. */
const shown = new WeakMap<GlassView, { sent: number[]; box: string }>() const shown = new WeakMap<GlassView, { sent: number[]; box: string }>()
@@ -1864,59 +2049,52 @@ function createEngine(): GlassEngine | null {
v.canvas.height = devH v.canvas.height = devH
on.sent.length = 0 on.sent.length = 0
} }
// The shared GL canvas only grows; each view is drawn into its bottom-left corner.
if (glCanvas.width < devW || glCanvas.height < devH) {
glCanvas.width = Math.max(glCanvas.width, devW)
glCanvas.height = Math.max(glCanvas.height, devH)
}
gl.viewport(0, 0, devW, devH)
// Nothing is asked of the GPU until this frame is known to differ from the one on the canvas:
// the layers are painted here, on plain 2D canvases, and put into their textures at the end.
const unit = m.unit const unit = m.unit
const r = m.refraction const r = m.refraction
/** The layers are the ones this view was last drawn with. */ /** The layers are the ones this view was last drawn with. */
let fresh = true let fresh = true
if (r) { let p: Painted | undefined
let p = painted.get(v) /** The layers painted on this frame, to upload. */
if (!p) painted.set(v, (p = { back: texture(true), front: texture(false), w: 0, h: 0, at: 0 })) let layers: Layers | undefined
const now = performance.now()
const sized = p.w === devW && p.h === devH
// A painter that takes only `back` has no front layer: none is cleared or uploaded. // A painter that takes only `back` has no front layer: none is cleared or uploaded.
const fronted = r.paint.length > 1 const fronted = !!r && r.paint.length > 1
const skip = backSkipOf(m, dpr)
if (r) {
p = painted.get(v)
if (!p) painted.set(v, (p = { back: { tex: null, w: 0, h: 0 }, front: { tex: null, w: 0, h: 0 }, w: 0, h: 0, skip: 0, at: 0 }))
const now = performance.now()
const sized = p.w === devW && p.h === devH && p.skip === skip
fresh = !repaint && sized && now - p.at < REPAINT_EVERY fresh = !repaint && sized && now - p.at < REPAINT_EVERY
gl.activeTexture(gl.TEXTURE0)
gl.bindTexture(gl.TEXTURE_2D, p.back)
if (!fresh) { if (!fresh) {
for (const l of fronted ? [back, front] : [back]) { // The page's picture, smaller where the frost never reads it at full size (BACK_SKIP),
if (l.canvas.width !== devW || l.canvas.height !== devH) { // and fitted to its canvas, so that it covers the glass's canvas exactly as before.
l.canvas.width = devW const bw = skip ? Math.max(2, Math.ceil(devW / 2 ** skip)) : devW
l.canvas.height = devH const bh = skip ? Math.max(2, Math.ceil(devH / 2 ** skip)) : devH
} const l = layersFor(bw, bh, fronted ? devW : 0, fronted ? devH : 0)
l.ctx!.setTransform(1, 0, 0, 1, 0, 0) l.back.ctx!.setTransform(1, 0, 0, 1, 0, 0)
l.ctx!.clearRect(0, 0, devW, devH) l.back.ctx!.clearRect(0, 0, bw, bh)
l.ctx!.setTransform(dpr, 0, 0, dpr, 0, 0) if (skip) l.back.ctx!.setTransform(bw / m.width, 0, 0, bh / m.height, 0, 0)
else l.back.ctx!.setTransform(dpr, 0, 0, dpr, 0, 0)
if (fronted && l.front) {
l.front.ctx!.setTransform(1, 0, 0, 1, 0, 0)
l.front.ctx!.clearRect(0, 0, devW, devH)
l.front.ctx!.setTransform(dpr, 0, 0, dpr, 0, 0)
} }
// A painter that says nothing changed keeps the textures it already has. // A painter that says nothing changed keeps the textures it already has.
fresh = r.paint(back.ctx!, front.ctx!) === false && sized fresh = r.paint(l.back.ctx!, (l.front ?? front).ctx!) === false && sized
}
if (!fresh) { if (!fresh) {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, back.canvas) layers = l
gl.generateMipmap(gl.TEXTURE_2D)
}
gl.activeTexture(gl.TEXTURE1)
gl.bindTexture(gl.TEXTURE_2D, fronted ? p.front : blank.front)
if (!fresh) {
if (fronted) gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, front.canvas)
p.w = devW p.w = devW
p.h = devH p.h = devH
p.skip = skip
p.at = now p.at = now
} }
} else {
gl.activeTexture(gl.TEXTURE0)
gl.bindTexture(gl.TEXTURE_2D, blank.back)
gl.activeTexture(gl.TEXTURE1)
gl.bindTexture(gl.TEXTURE_2D, blank.front)
} }
sent.length = 0 }
sent.length = names.length = sizes.length = 0
// The surroundings, for the reflection. The picture is taken when it is first needed, and // The surroundings, for the reflection. The picture is taken when it is first needed, and
// again when sizes and colours are re-read or the canvas changes size, AROUND_EVERY apart at // again when sizes and colours are re-read or the canvas changes size, AROUND_EVERY apart at
// most (a change that comes sooner waits its turn). A scroll takes none: what surrounds the // most (a change that comes sooner waits its turn). A scroll takes none: what surrounds the
@@ -1933,16 +2111,16 @@ function createEngine(): GlassEngine | null {
const idle = mirrored.get(v) const idle = mirrored.get(v)
if (idle) idle.due = true if (idle) idle.due = true
} }
gl.activeTexture(gl.TEXTURE2) /** A picture of the surroundings taken on this frame, to upload. */
let picture: Mirrored | undefined
if (f) { if (f) {
let a = mirrored.get(v) let a = mirrored.get(v)
if (!a) mirrored.set(v, (a = { tex: texture(true), w: 0, h: 0, at: 0, left: 0, top: 0, reach: 0, due: true, timer: 0, busy: false })) if (!a) mirrored.set(v, (a = { pic: { tex: null, w: 0, h: 0 }, w: 0, h: 0, at: 0, left: 0, top: 0, reach: 0, due: true, timer: 0, busy: false }))
const taken = a const taken = a
const reach = clamp(f.height * MIRROR.reach, MIRROR.reachMin, Math.max(MIRROR.reachMin, MIRROR.reachMax)) const reach = clamp(f.height * MIRROR.reach, MIRROR.reachMin, Math.max(MIRROR.reachMin, MIRROR.reachMax))
const aw = Math.max(2, Math.ceil((m.width + 2 * reach) * AROUND_SCALE)) const aw = Math.max(2, Math.ceil((m.width + 2 * reach) * AROUND_SCALE))
const ah = Math.max(2, Math.ceil((m.height + 2 * reach) * AROUND_SCALE)) const ah = Math.max(2, Math.ceil((m.height + 2 * reach) * AROUND_SCALE))
const now = performance.now() const now = performance.now()
gl.bindTexture(gl.TEXTURE_2D, a.tex)
if (refresh || (f.live && repaint) || a.w !== aw || a.h !== ah || a.reach !== reach) a.due = true if (refresh || (f.live && repaint) || a.w !== aw || a.h !== ah || a.reach !== reach) a.due = true
if (a.due && a.w && busy && !f.live && now - a.at < AROUND_WAIT) { if (a.due && a.w && busy && !f.live && now - a.at < AROUND_WAIT) {
// It waits for all to be still (see AROUND_WAIT): the picture it has is kept meanwhile. // It waits for all to be still (see AROUND_WAIT): the picture it has is kept meanwhile.
@@ -1969,8 +2147,7 @@ function createEngine(): GlassEngine | null {
c.clearRect(0, 0, aw, ah) c.clearRect(0, 0, aw, ah)
c.setTransform(AROUND_SCALE, 0, 0, AROUND_SCALE, reach * AROUND_SCALE, reach * AROUND_SCALE) c.setTransform(AROUND_SCALE, 0, 0, AROUND_SCALE, reach * AROUND_SCALE, reach * AROUND_SCALE)
f.paint(c, reach) f.paint(c, reach)
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, around.canvas) picture = a
gl.generateMipmap(gl.TEXTURE_2D)
a.w = aw a.w = aw
a.h = ah a.h = ah
a.at = now a.at = now
@@ -1984,7 +2161,6 @@ function createEngine(): GlassEngine | null {
set('uAroundScale', AROUND_SCALE * unit) set('uAroundScale', AROUND_SCALE * unit)
set('uReach', reach / unit) set('uReach', reach / unit)
} else { } else {
gl.bindTexture(gl.TEXTURE_2D, blank.back)
set('uAroundBox', 0, 0, 1, 1) set('uAroundBox', 0, 0, 1, 1)
set('uAroundScale', 1) set('uAroundScale', 1)
set('uReach', 0) set('uReach', 0)
@@ -1998,6 +2174,7 @@ function createEngine(): GlassEngine | null {
// Blur level follows screen density (reference: 2.27 device px per design unit). // Blur level follows screen density (reference: 2.27 device px per design unit).
set('uBlurShift', Math.log2(Math.max((unit * dpr) / 2.27, 1e-3))) set('uBlurShift', Math.log2(Math.max((unit * dpr) / 2.27, 1e-3)))
set('uFrost', r?.frost ?? 0) set('uFrost', r?.frost ?? 0)
set('uBackSkip', skip)
set('uFrostBlur', Math.max(0, r?.blur ?? 0) / unit) set('uFrostBlur', Math.max(0, r?.blur ?? 0) / unit)
set('uFrostMix', clamp(r?.blurMix ?? 1)) set('uFrostMix', clamp(r?.blurMix ?? 1))
// Radial bend: a share of the viewport per axis, as the SVG card's map was. // Radial bend: a share of the viewport per axis, as the SVG card's map was.
@@ -2114,6 +2291,51 @@ function createEngine(): GlassEngine | null {
// The same layers and the same uniforms as the frame on the canvas: nothing to draw. // The same layers and the same uniforms as the frame on the canvas: nothing to draw.
if (fresh && on.sent.length === sent.length && sent.every((value, i) => value === on.sent[i])) return if (fresh && on.sent.length === sent.length && sent.every((value, i) => value === on.sent[i])) return
on.sent = sent.slice() on.sent = sent.slice()
// The shared GL canvas only grows; each view is drawn into its bottom-left corner.
if (glCanvas.width < devW || glCanvas.height < devH) {
glCanvas.width = Math.max(glCanvas.width, devW)
glCanvas.height = Math.max(glCanvas.height, devH)
}
gl.viewport(0, 0, devW, devH)
// What lies beneath, what rides on top and what surrounds the glass: the pictures taken on
// this frame are uploaded, the others are the ones this view already has.
gl.activeTexture(gl.TEXTURE0)
if (p && layers) upload(p.back, layers.back.canvas, true)
else gl.bindTexture(gl.TEXTURE_2D, p?.back.tex ?? blank.back)
gl.activeTexture(gl.TEXTURE1)
if (p && layers?.front && fronted) upload(p.front, layers.front.canvas, false)
else gl.bindTexture(gl.TEXTURE_2D, (fronted && p?.front.tex) || blank.front)
gl.activeTexture(gl.TEXTURE2)
if (picture) upload(picture.pic, around.canvas, true)
else gl.bindTexture(gl.TEXTURE_2D, (f && mirrored.get(v)?.pic.tex) || blank.back)
send()
// The frost's own pass (FROST_PASS): on large, softly frosted glass the frost is drawn first,
// into a smaller picture that the glass then reads.
const sigma = r && !blob?.material ? Math.max(0, r.blur ?? 0) * Math.min(1, Math.max(0.05, k.frostEdge ?? 1)) * dpr : 0
const texel = sigma >= FROST_PASS.sigma && 4 * m.hx * m.hy * dpr * dpr >= FROST_PASS.area ? Math.min(FROST_PASS.most, Math.floor(sigma / FROST_PASS.texel)) : 0
const fw = texel >= 2 ? Math.ceil(devW / texel) + 1 : 0
const fh = texel >= 2 ? Math.ceil(devH / texel) + 1 : 0
if (texel >= 2 && frostRoom(fw, fh)) {
const sx = 1 / (texel * frostPic.w)
const sy = 1 / (texel * frostPic.h)
// The picture is not bound while it is drawn into.
gl.activeTexture(gl.TEXTURE3)
gl.bindTexture(gl.TEXTURE_2D, blank.front)
gl.bindFramebuffer(gl.FRAMEBUFFER, frostPic.fbo)
// Nothing of what it held is kept: a GPU that draws in tiles need not load it back.
gl.invalidateFramebuffer(gl.FRAMEBUFFER, [gl.COLOR_ATTACHMENT0])
gl.viewport(0, 0, fw, fh)
gl.uniform4f(frostPassAt, 1, texel, sx, sy)
gl.drawArrays(gl.TRIANGLES, 0, 3)
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
gl.viewport(0, 0, devW, devH)
gl.bindTexture(gl.TEXTURE_2D, frostPic.tex)
gl.uniform4f(frostPassAt, 2, texel, sx, sy)
frostPassHeld = 2
} else if (frostPassHeld) {
gl.uniform4f(frostPassAt, 0, 1, 0, 0)
frostPassHeld = 0
}
gl.drawArrays(gl.TRIANGLES, 0, 3) gl.drawArrays(gl.TRIANGLES, 0, 3)
v.ctx.clearRect(0, 0, devW, devH) v.ctx.clearRect(0, 0, devW, devH)
v.ctx.drawImage(glCanvas, 0, glCanvas.height - devH, devW, devH, 0, 0, devW, devH) v.ctx.drawImage(glCanvas, 0, glCanvas.height - devH, devW, devH, 0, 0, devW, devH)
@@ -2484,13 +2706,13 @@ function createEngine(): GlassEngine | null {
if (a) { if (a) {
mirrored.delete(v) mirrored.delete(v)
clearTimeout(a.timer) clearTimeout(a.timer)
gl.deleteTexture(a.tex) gl.deleteTexture(a.pic.tex)
} }
const p = painted.get(v) const p = painted.get(v)
if (!p) return if (!p) return
painted.delete(v) painted.delete(v)
gl.deleteTexture(p.back) gl.deleteTexture(p.back.tex)
gl.deleteTexture(p.front) gl.deleteTexture(p.front.tex)
}, },
wake, wake,
resolveColor, resolveColor,

View File

@@ -1,7 +1,7 @@
'use client' 'use client'
// KolayTercih (DESIGN.md §4.50): Liquid Glass UI 2.0.0'dan (bilalgursen/liquid-glass@9c65d01, // KolayTercih (DESIGN.md §4.50): Liquid Glass UI 2.0.4'ten (bilalgursen/liquid-glass@d80330a,
// 24 Kas 2026) olduğu gibi alındı. Elle değiştirilmez; kit güncellenince dosya yeniden kopyalanır. // 25 Kas 2026) olduğu gibi alındı. Elle değiştirilmez; kit güncellenince dosya yeniden kopyalanır.
// GlassLayer — turns any positioned element (a button, a link, a pill) into liquid glass. // GlassLayer — turns any positioned element (a button, a link, a pill) into liquid glass.
// Put it as the FIRST child of the host and mark the host with `data-glass-host`: // Put it as the FIRST child of the host and mark the host with `data-glass-host`:
@@ -199,6 +199,8 @@ export const GLASS_CSS = `
@keyframes glass-spin{to{transform:rotate(1turn)}} @keyframes glass-spin{to{transform:rotate(1turn)}}
[data-glass-spin]{animation:glass-spin .8s linear infinite} [data-glass-spin]{animation:glass-spin .8s linear infinite}
[data-glass-ready] [data-glass-fallback]{visibility:hidden} [data-glass-ready] [data-glass-fallback]{visibility:hidden}
/* A hidden fallback stops moving too. Its marquee ran on unseen, on the main thread, and made the browser work out the page's layers again on every frame of anything else on the page. */
[data-glass-ready] [data-glass-fallback] [data-glass-marquee]{animation:none}
@media (prefers-reduced-motion:reduce){[data-glass-marquee],[data-glass-in],[data-glass-draw],[data-glass-spin]{animation:none}} @media (prefers-reduced-motion:reduce){[data-glass-marquee],[data-glass-in],[data-glass-draw],[data-glass-spin]{animation:none}}
` `
@@ -492,7 +494,10 @@ export function GlassLayer({
const melt = swell ? Math.ceil(cohesionSoftness(h) / 4) + 3 : 0 const melt = swell ? Math.ceil(cohesionSoftness(h) / 4) + 3 : 0
const padX = Math.max(8, Math.ceil(reach * (1 + most) - w / 2 + 2), melt) const padX = Math.max(8, Math.ceil(reach * (1 + most) - w / 2 + 2), melt)
const padTop = Math.max(10, Math.ceil(hy * (1 + most) - h / 2 + 2), melt) const padTop = Math.max(10, Math.ceil(hy * (1 + most) - h / 2 + 2), melt)
const padBottom = Math.round(h * 0.8 + 4) // Below the glass the canvas keeps room for its drop shadow. Glass that casts none (a card:
// its shadow is CSS) needs no more there than above it, and a canvas that much smaller is
// that much less to paint, upload, shade and copy on every frame.
const padBottom = (tuneRef.current.optics?.shadow ?? 1) <= 0 ? padTop : Math.round(h * 0.8 + 4)
const origin = `${padX + w / 2}px ${padTop + h / 2}px` const origin = `${padX + w / 2}px ${padTop + h / 2}px`
const undo = px === 1 && py === 1 ? '' : `${(1 / px).toFixed(6)} ${(1 / py).toFixed(6)}` const undo = px === 1 && py === 1 ? '' : `${(1 / px).toFixed(6)} ${(1 / py).toFixed(6)}`
if (undo !== unstretched || (undo && origin !== unstretchedAt)) { if (undo !== unstretched || (undo && origin !== unstretchedAt)) {

View File

@@ -1,7 +1,7 @@
'use client' 'use client'
// KolayTercih (DESIGN.md §4.50): Liquid Glass UI 2.0.0'dan (bilalgursen/liquid-glass@9c65d01, // KolayTercih (DESIGN.md §4.50): Liquid Glass UI 2.0.4'ten (bilalgursen/liquid-glass@d80330a,
// 24 Kas 2026) olduğu gibi alındı. Elle değiştirilmez; kit güncellenince dosya yeniden kopyalanır. // 25 Kas 2026) olduğu gibi alındı. Elle değiştirilmez; kit güncellenince dosya yeniden kopyalanır.
// GlassLens — the sliding glass lens of a segmented control / tab bar. Bring your own // GlassLens — the sliding glass lens of a segmented control / tab bar. Bring your own
// options (Radix Tabs, a radiogroup, anything) and put the lens first in the container: // options (Radix Tabs, a radiogroup, anything) and put the lens first in the container:

View File

@@ -2,8 +2,9 @@
// Sıvı cam (DESIGN.md §4.1, §4.22, §4.49, §4.50): cam butonların zemini, tek seçimli // Sıvı cam (DESIGN.md §4.1, §4.22, §4.49, §4.50): cam butonların zemini, tek seçimli
// sekmelerde kayan mercek ve "Yeni" rozeti. Kaynak: Bilal'in açık kaynak kiti // sekmelerde kayan mercek ve "Yeni" rozeti. Kaynak: Bilal'in açık kaynak kiti
// "Liquid Glass UI" 2.0.0 (github.com/bilalgursen/liquid-glass@9c65d01, 24 Kas 2026, MIT). // "Liquid Glass UI" 2.0.4 (github.com/bilalgursen/liquid-glass@d80330a, 25 Kas 2026, MIT).
// Bilal, 25 Kas 2026: "burdaki liquid glassları güncel liquid glass ile güncelle". // Bilal, 25 Kas 2026: "burdaki liquid glassları güncel liquid glass ile güncelle"; 26 Kas 2026:
// "liquid glass'ın son hâline çevir" (2.0.0 → 2.0.4: boşta hiç kare çizilmez, GPU yükü azaldı).
// //
// Motor ve bakış kitin kendisidir, `src/components/liquid-glass/` altında olduğu gibi // Motor ve bakış kitin kendisidir, `src/components/liquid-glass/` altında olduğu gibi
// durur (`engine.ts`, `dom-snapshot.ts`, `glass-layer.tsx`, `glass-lens.tsx`): tek ortak // durur (`engine.ts`, `dom-snapshot.ts`, `glass-layer.tsx`, `glass-lens.tsx`): tek ortak