日更栏目《999 个小技巧,让你 Vibe 的产品更有质感》 ✨ 013 有物理质感的冲击波(含扭曲与通道分离) iOS 27.3 加入了屏幕边缘的跑马灯光效,也让我想起用 Dia 时,每次打开主页都会出现的光环冲击效果,于是尝试把两者结合。 完整 Prompt 见下方评论,可直接复制使用 ⬇️ 该效果由 6 层组成: 1. 页面快照:将当前页面转为图像,作为后续各层的计算基础(可以借助 Chrome 新增的 HTML-in-Canvas) 2. 透镜扭曲:光环整体作为一个透镜,外侧拉伸、内侧压缩,表现空间被推开。 3. 通道分离:红、蓝通道的位移分别比绿色多、少 8%,在位移处形成轻微色散,同时保持文字清晰。 4. 色环:四道色环平滑过渡,随扩散逐渐淡出,决定光环的颜色与亮度。浅色模式为染色,深色模式为加光(screen 混合)。 5. 边缘折射:光环只在内容区内扩散。到达边缘时,内容如透过玻璃斜边向边缘轻微拉伸,窗框保持不变。 6. 边线反光:光环经过时,分割线与描边短暂提亮,深色模式下更弱,使页面结构也参与其中。 共 4 组配色:Aurora 蓝紫粉桃,Halo 橙黄,Frost 薄荷绿,Spark 紫金。
枯白啃设计

图标设计师 / 设计工程师

Prompt(4/4) 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.
登录并发表评论

评论 · 0