一个真正有物理质感的光环,不应该只是罩在页面上的半透明圆。

它经过时,背后的内容会轻微变形;红蓝通道会有不同幅度的位移;页面边缘像玻璃斜边一样把内容折向内侧;连分隔线和卡片边框也会短暂捕捉到颜色。

原推文把 iOS 27.3 的屏幕边缘光感,与 Dia 打开主页时的光环冲击结合起来。它不是单纯复刻某一套视觉,而是让一次触发在页面里经过六个层。

先定义一次空间事件

光环不是永远播放的背景动画,而是一次由明确动作触发、从明确原点扩散、作用在明确区域内的事件。

触发前需要确定:

  • 点击输入框、聚焦、发送消息,还是 AI 开始回答;
  • 正在播放时再次触发,是重播、接续,还是忽略;
  • 从输入框、按钮、底部边缘、点击位置或面板中心扩散;
  • 只作用于一个面板、页面内容区,还是整个窗口;
  • 工具栏是否始终排除在外。

只要其中一项含糊,光环就会从“空间反馈”退化成随机发光。组件位置改变后,光环可能穿过工具栏、溢出圆角,甚至在用户没有操作时自行出现。

六个层,组成一次冲击

效果由六层叠加而成:

  1. 页面快照:把当前页面渲染成图像,作为后续采样的基础;
  2. 透镜扭曲:光环作为一整块透镜,把经过的页面推开;
  3. 通道分离:红色与蓝色分别以不同比例偏移,形成极轻的色散;
  4. 色环:四道宽色带平滑过渡,并随扩散淡出;
  5. 边缘折射:内容到达页面边缘时,像透过玻璃斜边一样被拉伸;
  6. 边线反光:分隔线、描边和卡片轮廓经过光环时短暂提亮。

前四层决定光环看起来像什么,后两层决定它是否真的与页面发生关系。

四道色环,先建立光的结构

光环宽度约为 110px,内部依次排列四道色带。距离光环前沿为 x 的位置,每种颜色的权重按高斯分布混合,所以相邻色环之间没有硬边。

1
2
weight = gaussian((x - center) / 0.8)
alpha = strength × exp(-1.1 × (x / 2)²)

四道环共享同一个淡出函数。光环越往外扩散,强度越低,最后全部融回页面。

浅色模式用染色:把页面颜色向色环混合,再轻微加亮。深色模式用加光:通过 screen 混合把颜色叠亮,而不是继续提高不透明度。

原效果提供四组配色:

配色 色彩方向
Aurora 蓝、紫、粉、桃
Halo 橙、琥珀、金
Frost 薄荷、青绿、浅青
Spark 紫、粉紫、金

每一组都有独立的深色与浅色版本。深色下更亮、更饱和;浅色下更柔和,避免高饱和颜色把白色页面拖脏。

透镜只弯一次,不跟着色环一起抖

最容易做错的地方,是让每个色环各自扭曲页面。那样看起来像水面涟漪,而不是有一块透明材料从空间里穿过。

正确的做法是把整个光环当成一块透镜。设距离光环前沿的归一化位置为 x,则:

1
2
z = x × 0.75
push = 7px × 2.33 × z × exp(-z²)

页面从自身位置反向 push 的距离取样。光环外侧被拉伸,内侧被挤压,变化宽度大约与色环相同,不能扩散到整页。

颜色分离也服务于透镜,而不是彩虹效果:红色通道的位移乘 1.08,蓝色乘 0.92,绿色保持基准。偏移只出现在真正发生位移的位置,文字必须保持清晰;如果边缘出现明显彩边,就说明分离过强。

页面边缘需要保持笔直。扭曲在最后 56px 内逐渐降到零,让窗框像固定镜片的外壳,而不是也跟着融化。

到边缘时,内容像透过玻璃斜边

当光环到达页面侧边或底部,最后 60px 的区域会从更靠内的内容取样。偏移从边缘向内最多约 22px,并按二次曲线衰减:

1
refraction = 22px × (1 - d / 60)² × strength

这会让靠近边缘的文字与素材轻微向边框拉伸,窗框本身不动。光环真正碰到边缘时,再叠一条极细的高光,颜色向白色混合约 45%。

如果光环下方有工具栏,边缘折光必须避开工具栏的直线边界。效果可以覆盖内容,但不能画到浏览器或应用自己的工具条上。

让页面结构也捕捉到光

如果只有内容扭曲,而所有分隔线和描边保持原样,光环仍然像一层贴在页面上的滤镜。

可以在光环经过时,让页面里的细线一起提亮。最准确的方式是额外捕获一张只含线条的图:所有分隔线、边框和轮廓用白线画在黑底上,不包含文字、图标、图片、填充和阴影。主画面根据这张 mask 提亮,因此 1px 边框仍然只会亮 1px。

如果是 DOM retrofit,做不到整页捕获,也可以给每个带边框的元素和分隔线一个 CSS 变量,根据它们与光环前沿的距离,把 0–1 的光强写入变量,再混合边框颜色。

提亮幅度需要很克制:浅色模式约 0.3,深色模式约 0.14。文字和图标不参与这层反光;它们一旦发光,就会变成可读性问题。

节奏先快后慢,最后完全消失

默认触发是点击或聚焦 AI 输入框。光环圆心位于输入框下方约 650px,视觉上是一条从页面底部升起的宽弧。

扩散半径不是线性增长,而是前段很快、后段减速:

1
2
3
radius =
650
+ 800 × (1 - 2^(-9t)) / (1 - 2^(-9))

整段约 1000ms。强度在前 3% 快速建立,之后随 1 - t^2.2 淡出,确保到达远端时已经没有明显边缘。

如果输入框本身也参与触发,则先下压到 97% 约 90ms,再以约 580ms 的弹簧展开。光环在展开开始 40ms 后出现,金属边缘高光可以在约 900ms 内旋转一周。

这些动作共享同一个起点,但各自拥有不同职责:输入框说明“操作被接收”,光环说明“界面能量向外扩散”。

平台决定扭曲怎么实现

色环和线条反光只需要一层覆盖画面,几乎所有平台都能做。真正的难点是让页面从偏移后的位置取样。

Web

最完整的方式是用 WebGL2 或 WebGL1 覆盖画布,从页面快照里采样并一次完成色环、扭曲、分色和反光。

页面快照可以按支持情况选择:

  • HTML-in-Canvas:浏览器直接渲染页面,实时、保真,但只有部分 Chromium 版本支持;
  • foreignObject 截图库:克隆 DOM 后交给浏览器渲染,需要内联字体和图片;
  • html2canvas:重新实现 CSS,对 backdrop-filter、复杂渐变和新颜色空间容易失真;
  • 无快照回退:只画光环覆盖层,不做扭曲;Chromium 可尝试 backdrop-filter 加 SVG 位移滤镜,但成本更高。

像素比建议上限为 2,画布在静止时移除或隐藏,且必须 pointer-events: none。

原生与游戏引擎

平台 推荐路径 回退
iOS 17+ SwiftUI .layerEffect + Metal stitchable shader 静态渐变覆盖层
Android 33+ AGSL RuntimeShader + RenderEffect 只画光环
Flutter Impeller FragmentProgram + ImageFilter.shader 只画光环
Rust / wgpu 离屏纹理 + 全屏后处理 shader 只画光环
bevy 自定义 post-process node 只画光环
Electron / Tauri Web 方案,Electron 可直接捕获页面 只画光环

不同平台的实现细节并不重要,选择标准只有两个:能否实时采样页面,以及一次快照或一次后处理的成本能否接受。

动效要能被中断,也要能被关闭

光环播放期间重新触发时,必须从当前视觉状态开始,而不是等旧动画结束再重播。主题切换时,色环随页面交叉淡化,不能先闪一下再换颜色。

在 prefers-reduced-motion: reduce 下,取消扭曲、分色和结构反光,只保留在固定位置淡入淡出的光环,亮度减半,时长约 600ms。

性能上也只应在光环可见时绘制。静止状态不应该有常驻 Canvas、持续 shader 或逐帧布局计算。

检查清单

  • 触发动作、原点、作用区域和重复触发策略是否明确;
  • 光环是否被裁剪在内容区,且从不覆盖工具栏;
  • 四道色环是否连续过渡,浅色染色与深色加光是否分开;
  • 透镜是否作为整体弯曲,而不是每个色环各弯一次;
  • 红蓝分离是否足够轻,文字是否仍然清晰;
  • 页面边缘是否保持笔直,内容是否只在边缘附近折光;
  • 线条反光是否不包含文字和图标;
  • 动效是否前快后慢,并在结束时完全消失;
  • 当前平台是否真的支持页面采样,有没有明确降级;
  • 减少动态效果和静止零开销是否都落实。

冲击波光环示例 Prompt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Prompt

Add a shockwave halo to my product: when something triggers it (by default, clicking or focusing the AI input), a faint halo of light sweeps across the page from one place and fades out, bending the page a few pixels as it passes, with a slight color split, in my dark and light modes. Build it inside my code and design system; do not change what the page does or how it looks at rest. Every value below is a default to start from, not a requirement.

First look at my app (section 0). Then ask me these one at a time, offering the default each time, and wait for each answer:
1. Trigger: what starts the halo (clicking or focusing the AI input, a keyboard shortcut, sending a message, the AI starting to answer, something else), and what happens if it is triggered again while one is running (restart, or ignore).
2. Origin: where it spreads from (the AI input, a button, the bottom edge of the page, the point that was clicked, the middle of a panel), and over which area (the page's content area, one panel, the whole window). Toolbars always stay clear.
3. Layers: the color rings (section 3) are always on; ask yes or no for each of the others: the bend (section 4), the color split, the refraction at the edges, the glints on lines and borders. The bend, the split and the refraction need the page as an image (section 6), so say what each costs on my platform.
4. Colors: one of the four palettes in section 3, or my brand colors (then derive four rings, and a dark and a light version, from them), and which modes my app has.
5. The input: leave my AI input as it is (the default), or turn it into the pill that springs open with a metal edge (section 1).
Then propose how you will build it on my platform (section 6 is a starting point, not a prescription), with the cost and any fallback, and wait for my go-ahead.

0. Start from what exists
- Find the AI input, what opens or focuses it, the page container it sits in, its corner radius, any toolbars over it, and whether the app has a dark mode.
- List what the page draws with (DOM, a canvas, a native view tree, a GPU renderer) and the platform version range: this decides how the bend can be done (section 6).

1. The input (only if I chose the pill)
- At rest: a pill 300 x 44 px, radius 22, white (dark: rgb(30 30 33)), a 1px hairline, a sparkle icon, the placeholder "Ask AI about this project" in 14px and a shortcut hint on the right. It sits centered on the page's content, 48px above the page's bottom.
- On click: the pill dips to 97% for 90ms, then springs open into a card 460 x 100, radius 16, growing from its center and keeping its bottom edge where it was. Spring: progress = 1 - exp(-8t) * cos(6t) over 580ms (barely past the end, settles by the end). The card's content is laid out at its final size from the start and is revealed as it grows; it fades in from 30% of the way. Height and radius follow the same progress.
- The open card: one line of text at 15px on a 22px line, 16px from the left, the caret first and the placeholder right after it; a hairline; then a toolbar 52px tall: a round add button, a short divider, two pickers (model, mode), and on the right a voice button and the send button, all 32px.
- Shadow: wide, soft and far, not heavy: 0 0 0 1px rgb(15 23 42 / 0.09), 0 2px 4px rgb(15 23 42 / 0.04), 0 28px 64px -16px rgb(15 23 42 / 0.22). No focus ring; focus shows only as the caret.
- The metal edge: a 1px border painted with a light silver gradient, linear-gradient(120deg, rgb(238 240 243), rgb(196 202 210) 28%, rgb(241 243 245) 50%, rgb(188 195 204) 74%, rgb(233 236 239)) (dark: rgb(74 79 87) to rgb(51 55 61)), with a highlight on top: conic-gradient(from <angle>, transparent 0 280deg, rgb(255 255 255 / 0.8) 325deg, transparent 360deg). Turn the angle from -60deg to 300deg over 900ms (ease-out) as the card opens, and fade the whole edge in and out over that time (opacity sin(pi * t), at most 0.75). Mask the gradient to the border only (mask with content-box exclude).
- Closing: back to the pill in 320ms, ease-in-out.

2. The halo's shape and timing
- The halo is a circle that grows from the origin I chose. The defaults assume the origin is the AI input at the bottom of the page: the circle's center sits below the page, horizontally at the input's center and 650px below the page's bottom edge, so what shows is a wide arc rising from the bottom.
- It starts with its middle at the page's bottom (radius 650) and grows by 800px over 1000ms, so it ends just past the page's top: radius = 650 + 800 * (1 - 2^(-9t)) / (1 - 2^(-9)). That is very fast at first and slow near the far edge.
- For another origin, keep the same timing and set the start and the growth so the halo starts at the origin and ends just past the farthest edge of the area: from a point inside the area, center the circle on the point and start at a radius of 0 to 40px; from an edge, put the center beyond that edge, about two thirds of the area's width away.
- Strength over the same time: min(1, t / 0.03) * (1 - t^2.2), so it is gone by the end and fades over its slow last stretch.
- It starts on the trigger (40ms after the input starts opening, if it opens).
- It stays in the area I chose: clip it to that area, with a straight edge under any toolbar and the area's own corner radius elsewhere (12px in the demo). It must never draw over a browser or app toolbar.

3. The rings and the palettes
- Across the halo's width sit four broad rings, one color each, inside to outside. With w = 110px and x = (distance from the center - radius) / w, ring i is centered at x = i - 1.5 with weight exp(-((x - c) / 0.8)^2); the color is the weighted average of the four, so neighbors blend softly. One fade covers all four: alpha = strength * exp(-1.1 * (x / 2)^2).
- Light mode tints the page: color = mix(page, ring, alpha * 0.24) + ring * alpha * 0.24 * 0.2.
- Dark mode adds light (screen): color = 1 - (1 - page) * (1 - ring * alpha * 0.3 * 1.5).
- Palettes, rings inside to outside. Each is tuned twice: brighter and more saturated on dark, softer on light.
Aurora (blue through violet and pink to peach)
dark: rgb(80 140 255), rgb(160 110 255), rgb(255 110 180), rgb(255 190 140)
light: rgb(110 150 255), rgb(180 130 255), rgb(255 130 190), rgb(255 180 120)
Halo (orange through amber to gold, like low sun through a lens)
dark: rgb(255 150 60), rgb(255 190 70), rgb(255 225 120), rgb(255 245 210)
light: rgb(255 140 50), rgb(255 175 60), rgb(245 200 80), rgb(255 225 150)
Frost (mint and aqua with a touch of lime)
dark: rgb(80 220 175), rgb(70 195 225), rgb(180 240 150), rgb(235 255 245)
light: rgb(40 190 150), rgb(50 170 210), rgb(140 210 90), rgb(180 235 215)
Spark (violet into gold)
dark: rgb(140 100 255), rgb(200 130 255), rgb(255 200 110), rgb(255 235 170)
light: rgb(130 95 240), rgb(185 125 245), rgb(245 185 80), rgb(250 215 120)

4. The bend
- The whole halo bends the page as one lens, never ring by ring (ring by ring reads as water ripples). With z = x * 0.75: push = 7px * 2.33 * z * exp(-z^2), along the direction away from the circle's center; read the page at position - push. Outside the halo's middle the page stretches, inside it squeezes, over about the width of the rings and no wider.
- Color split: at most a trace. Read red at 1.08 times the offset and blue at 0.92 times; text must stay clean.
- The frame holds the page: fade the lens to nothing over the last 56px before the page's edge, so the edge stays straight.
- The page's lines catch the light: where the halo passes, its rules, borders and the outlines of chips, cards and nodes brighten toward the ring color (mixed 20% toward white), at the halo's strength times exp(-1.4 * (x / 2)^2) times 0.3 on light and 0.14 on dark (a faint glint, not a redrawn border), read at their bent position so the glint follows them. Text and icons never light up. To find the lines, use a second capture of the page with every rule and border drawn white at its own width on black, and nothing else (no text, icons, pictures, fills or shadows); light the page where that capture is white, so a 1px border glints as 1px. Without a capture (a retrofit in the DOM), give each bordered element and divider a CSS variable from 0 to 1 by its distance to the halo's front each frame, and mix its border color toward the ring color by it.
- The edge as a glass bevel: at the sides and the bottom (not under a toolbar), where the halo reaches the edge, read the last 60px of the page from up to 22px further in (22 * (1 - d/60)^2 * the halo's strength there), so content beside the edge stretches toward it. Where the halo meets the edge, add a thin line of light (exp(-d / 7)) in the ring color mixed 45% toward white.

5. Rhythm
- On the trigger: if the input opens, it dips to 97% for 90ms, springs open (580ms) and its edge highlight turns (900ms); the halo leaves 40ms after the opening starts and runs 1000ms. Without the input, the halo runs on the trigger.
- Switching between dark and light cross-fades the halo's colors with the page; never cut.
- Reduced motion: no bend, no split and no glints; the halo fades in and out in place at half strength over 600ms.
- Draw only while the halo runs; nothing at rest.

6. How to build it, by platform
These are suggestions from what worked in the demo and what each platform offers; check them against my stack and its versions, and choose what fits. The halo itself (the rings, and the glints on lines and edges) is only an overlay and works anywhere. The bend needs the page as an image to sample from.
- Web, as in the demo: a WebGL2 canvas over the page draws everything in one fragment pass from a snapshot of the page. Cap the pixel ratio at 2; the canvas ignores pointer events and is removed or hidden at rest.
- Web, getting the snapshot:
- HTML-in-Canvas (WICG): a canvas with the page as its child, drawn with drawElementImage() or uploaded as a WebGL texture, live and with real browser rendering. Behind the canvas-draw-element flag in recent Chromium and reported on by default from Chrome 157; no Firefox or Safari yet. Use it where present.
- SVG foreignObject libraries (html-to-image, modern-screenshot): the browser renders the clone, so it is faithful, but images and fonts must be inlined or same-origin, the root needs a background color, and backdrop-filter is unreliable. Take it once on click (tens to a few hundred ms), then animate.
- html2canvas (or html2canvas-pro): it re-implements CSS on a canvas, so modern effects (backdrop-filter, some gradients, oklch) may come out wrong. A last resort.
- Fallback without a snapshot: draw only the halo in a transparent canvas over the page (light mode: normal alpha; dark mode: mix-blend-mode: screen or plus-lighter), and skip the bend. In Chromium only, a bend is possible with backdrop-filter pointing at an SVG filter with feDisplacementMap, at a cost.
- iOS (SwiftUI, iOS 17+): put the halo in a Metal [[stitchable]] function and apply .layerEffect(shader, maxSampleOffset: CGSize(width: 30, height: 30)) to the page view: it can sample the view at bent positions and add the color, live. Drive radius and strength from a TimelineView or an animatable value. Below iOS 17: an overlay with an AngularGradient and blur, without the bend.
- Android (API 33+): write the shader in AGSL as a RuntimeShader with a uniform shader named for the content, and set view.setRenderEffect(RenderEffect.createRuntimeShaderEffect(shader, "content")) on the page's root (in Compose: Modifier.graphicsLayer { renderEffect = ...asComposeRenderEffect() }). Update its uniforms every frame. Below 33: an overlay only.
- Flutter (Impeller): a FragmentProgram with ImageFilter.shader inside a BackdropFilter clipped to the page; the engine passes the content as sampler 0 and its size as the first vec2. Use FlutterFragCoord(), flip y on GLES, and check ImageFilter.isShaderFilterSupported, with an overlay-only fallback.
- Rust: render the UI into an offscreen texture, then draw one fullscreen pass with the same shader ported to WGSL that samples it.
- wgpu by hand: render target texture with TEXTURE_BINDING usage, a fullscreen triangle, uniforms in one buffer.
- Bevy: a custom post-processing node; call post_process_write() on the ViewTarget to get the source and destination textures, as in Bevy's custom post-processing example.
- egui or iced on wgpu: render the frame into a texture through the renderer's wgpu callback and composite with the shader; their widgets cannot sample what is under them by themselves.
- Electron and Tauri: the web route; Electron can also take a snapshot with webContents.capturePage().

7. Check
- Dark and light, in the colors I chose: the text under the halo stays readable and unsplit; the halo never shows on a toolbar; the area's corners stay clean; the bend is no wider than the rings.
- The trigger and the origin are the ones I chose, and the page works exactly as before.
- It runs only while the halo is visible and costs nothing at rest.

质感来自可解释的细节

冲击波光环的质感,不来自颜色更亮或扩散更大,而来自它真的经过了页面。

四道色环给出光的光谱,整体透镜说明空间的弯曲,通道分离只负责一点点透视,边缘折光与线条反光让页面结构参与进来。任何一层过量,都会从“光经过界面”变成“界面上播了一段特效”。

克制地使用物理关系,才会让一次短暂的冲击留下真实的空间记忆。

站内搜索

没有找到内容!