EN
全屏预览
Dither Tide 四色有序抖动流体着色器
一句话装进 Agent · 极速上手 Free Commercial · 无需绑卡 · 无试用倒计时
Claude Code Cursor Codex Antigravity OpenClaw
基于 Motion3D 原创 3D 网页蓝图「Dither Tide 四色有序抖动流体着色器」(https://motion3d.dev/works/dither-tide/):把自包含源码 ZIP 解压到 ./site,完整保留 60fps WebGL / GLSL + HTML5 动效骨架,替换为我的品牌文案、Logo 与主题色
免费商用永久有效 · 复制指令交给你的 Agent,免登录直接下载源码包解压即可开跑。
工艺拆解与配色
生产级英文提示词 · 5386 字符
# Build "Dither Tide" — Full-Bleed 4-Color Ordered Dither Fluid WebGL Shader Build a self-contained, full-viewport generative WebGL2 artwork titled **Dither Tide**: a continuously evolving, domain-warped fluid turbulence field quantized through a razor-sharp screen-locked **4×4 Bayer ordered dithering matrix** onto a strict **4-color thermal-risograph palette**, looping seamlessly every **10.0 seconds** at 60fps. ## Visual Direction & Mood - **Aesthetic**: Tactile digital printmaking meets infrared thermography and analog halftone cathode displays. Smooth, liquid, oil-on-water marbled swirls glide continuously beneath a rigid, stationary pixel-dot grid. - **No Smooth Gradients**: Every transition between colors must occur exclusively through crisp square Bayer halftone dot patterns—never soft alpha gradients, never per-channel RGB dithering (which introduces unwanted green/cyan artifacts), and never blurred antialiasing. - **Optical Color Mixing**: Adjacent palette stops dither against each other so the viewer perceives lush secondary hues—especially an electric **halftone violet/magenta** where Cobalt Blue and Blaze Orange interlock, midnight navy between Black and Blue, and warm apricot between Orange and Cream. ## Exact 4-Stop Quantized Palette (Ordered Low → High) Hardcode these exact sRGB stops in the fragment shader (no tone mapping, no gamma washout): 1. **Obsidian Void** (`#0C0C0D`, `vec3(0.047, 0.047, 0.051)`) — Scalar `0.00`, deep vortex troughs 2. **Electric Ultramarine** (`#3D2AFE`, `vec3(0.239, 0.165, 0.996)`) — Scalar `0.33`, dominant mid-low currents 3. **Blaze Vermilion** (`#FD5920`, `vec3(0.992, 0.349, 0.125)`) — Scalar `0.67`, fiery mid-high ridges 4. **Warm Bone** (`#F2EEE5`, `vec3(0.949, 0.933, 0.898)`) — Scalar `1.00`, incandescent core blooms ## Viewport Layout & Typography Contract - **100% Pure Canvas**: Render an edge-to-edge `<canvas>` locked to `100vw × 100dvh` (`position: fixed; inset: 0; overflow: hidden; background: #0C0C0D`). - **Zero Chrome**: Include NO navbar, NO buttons, NO overlays, NO scrollbars, and NO visible text—the artwork itself fills every pixel cleanly. - *(Optional extension note only if later adapted as a site hero: pair **Space Grotesk** 700 display type with **JetBrains Mono** metadata in `#F2EEE5` / `#0C0C0D` pills so type remains readable over high-frequency halftone dots.)* ## GLSL Fragment Shader & Motion Specification Render a single full-screen clip-space triangle with WebGL2 (`antialias: false`, `depth: false`, `alpha: false`): 1. **DPR-Normalized Cell Grid**: Compute `uCellSize = max(2.0, floor((uResolution.x / 640.0) + 0.5))` (targeting ~640 logical dither cells across a 16:9 desktop viewport, yielding ~2.4px cells at 1536×864). Quantize coordinates via `vec2 cell = floor(gl_FragCoord.xy / uCellSize)` and derive isotropic aspect-corrected UV `vec2 p = ((cell + 0.5) * uCellSize - 0.5 * uResolution) / min(uResolution.x, uResolution.y) * 2.1`. 2. **Seamless 10-Second Periodic Fluid Field**: Drive time with `float theta = 6.2831853 * fract(uTime / 10.0)` and map `(cos(theta), sin(theta)) * 0.65` into the `zw` coordinates of a **4D Simplex Noise** FBM function (4 octaves, lacunarity `2.05`, gain `0.5`). This ensures continuous forward organic advection with an invisible seam at `t = 10.0s` (never ping-pong `sin(t)` reversal). 3. **Two-Stage Domain Warping**: - Stage 1: `vec2 q = vec2(fbm4(p, tVec), fbm4(p + vec2(5.2, 1.3), tVec));` - Stage 2: `vec2 r = vec2(fbm4(p + 2.8 * q + vec2(1.7, 9.2), tVec), fbm4(p + 2.8 * q + vec2(8.3, 2.8), tVec));` - Density: `float f = fbm4(p + 3.2 * r, tVec);` - Remap & shape `f` into `v ∈ [0.0, 1.0]` with `smoothstep(-0.55, 0.72, f)` plus slight mid-range bias so typical frame coverage stays balanced (~10% Black, ~40% Blue, ~35% Orange, ~15% Cream) while dynamically breathing between deep-blue lulls and incandescent cream surges. 4. **Indexed 1D Ramp + 4×4 Bayer Ordered Dithering**: - Standard 4×4 matrix `[0,8,2,10, 12,4,14,6, 3,11,1,9, 15,7,13,5]` sampled at `ivec2(mod(cell, 4.0))`. - Center threshold: `float thresh = (bayerVal + 0.5) / 16.0;` (prevents stray single dots in flat extremes). - Map `float s = clamp(v, 0.0, 1.0) * 3.0; int i0 = int(floor(s)); int i1 = min(i0 + 1, 3);` - Output `vec3 col = (fract(s) > thresh) ? palette(i1) : palette(i0);` directly to `fragColor`. ## Tech Stack, Assets & Performance - **Stack**: Vite + TypeScript + Vanilla WebGL2 (zero external runtime libraries or image/texture assets—100% procedural GLSL). - **Performance & Accessibility**: Cap canvas DPR to `Math.min(window.devicePixelRatio, 2)`, resize cleanly via `ResizeObserver`, pause `requestAnimationFrame` on `document.hidden`, and slow time progression to `0.15×` (or freeze cleanly) when `prefers-reduced-motion: reduce` is active. Target <4ms GPU frame time for locked 60fps. ## Visual Acceptance Checklist - Inspecting any screenshot at 400% zoom reveals ONLY the 4 exact solid hex colors arranged in crisp, non-blurry square 4×4 Bayer dot patterns. - Zero green, cyan, or muddy gray pixels anywhere on screen. - Bayer grid stays locked in screen space while swirling marbled ribbons fold and advect smoothly underneath. - Looping from `00:09.9` to `00:00.0` shows zero pop, jump, or direction reversal. - Swirls remain circular/isotropic on both ultrawide desktop and vertical mobile viewports.
工艺拆解、动效栈与配色系统

原创设计理念

Dither Tide 是一套纯 GLSL 实时渲染的四色 Bayer 有序抖动流体背景引擎,支持光标流体扰动、色板实时切换与极低 GPU 占用,适合作为科技品牌动态背景。

色彩系统(点击复制 Hex)

版式与区块架构

该作品采用极致纯粹的 **全屏单画布无边框(Full-Bleed Edge-to-Edge Canvas)** 架构,全片 10 秒内没有任何导航栏、标题文案、悬浮按钮、参数面板、页脚或鼠标指针,整个视口(录屏分辨率 `1536×864`,16:9 宽屏)100% 由实时 WebGL 片元着色器接管。 - **视口容器层**:固定定位铺满 `100vw × 100dvh`,底色与色阶最低谷值 `#0C0C0D` 一致以防加载闪烁,禁用滚动条与选中交互(`overflow: hidden; user-select: none`)。 - **逻辑抖动网格层**:在 `1536×864` 画面中,着色器将屏幕划分为约 `640×360` 个离散正方形像素单元(单格约 `2.4px`),并叠加周期为 4 格的屏幕空间 `4×4` Bayer 矩阵。该网格严格锚定在视口坐标系上,形成类似“物理丝网/滤光栅格”的静态表层结构。 - **流体标量构图层**:底层域翘曲噪声场在纵横比归一化后的空间中铺满全屏,无固定居中焦点,而是通过大尺度斜向涡流、孤岛与热浪脊线在四角与中心之间持续流动、聚散,天然适配从超宽桌面屏到竖屏移动端的任意纵横比(只需以 `min(width, height)` 归一化 UV 防止漩涡被拉伸变形)。 - **生产复用定位**:既可直接作为独立数字艺术 / Shader 实验展品页面,也可零改动地作为 Hero Landing 页面的全屏背景层(底层 `z-index: 0`,上层叠加高对比度极简排版与导航)。

动效与前端工程栈

### 核心视觉与动效实现原理 在底层渲染架构上,画面并非真实流体仿真(Navier-Stokes),而是 **「两级域翘曲分形噪声(2-Stage Domain-Warped FBM)+ 周期循环时间 + 一维 4 色阶索引的 4×4 Bayer 有序抖动(Ordered Dithering)」** 在单 pass WebGL 片元着色器中的高效生成: 1. **屏幕空间量化网格(Cell Quantization)**: - 将片元坐标 `gl_FragCoord.xy` 按响应式步长 `uCellSize`(如 `max(2.0, round(uResolution.x / 640.0))`)向下取整得到离散格子索引 `cell = floor(gl_FragCoord.xy / uCellSize)`。 - 后续的噪声采样与 Bayer 查表均基于 `cell` 完成,保证每个抖动点为锐利等大的实心方块,且网格静止固定在屏幕空间,流体在其下方丝滑滑行,产生标志性的“像素点渐进明灭”呼吸感。 2. **无接缝 10 秒循环域翘曲流体(Seamless Periodic Domain Warping)**: - 经比对首帧(第 0 帧)与末帧(第 299 帧)像素差值极小,证实作品为 **10.0 秒无缝循环**。 - 实现方式:定义角相位 `theta = 2.0 * PI * fract(uTime / 10.0)`,构造圆周时间坐标 `tVec = vec2(cos(theta), sin(theta)) * loopRadius`,输入 **4D Simplex Noise** 构成的 4 层 FBM(`fbm4(vec4(p, tVec))`)。 - 采用 Inigo Quilez 经典二级域翘曲(Domain Warping): - 第一层翘曲向量 `q = vec2(fbm4(p), fbm4(p + vec2(5.2, 1.3)))` - 第二层嵌套翘曲 `r = vec2(fbm4(p + 2.8*q + vec2(1.7, 9.2)), fbm4(p + 2.8*q + vec2(8.3, 2.8)))` - 最终标量密度 `f = fbm4(p + 3.2*r)`,再经 `smoothstep` 拉伸归一化至 `v ∈ [0.0, 1.0]`,形成丝绸般折叠卷曲的大尺度云纹与涡流。 3. **4 色阶一维映射 + 4×4 Bayer 有序抖动**: - 标准 4×4 Bayer 矩阵 `[0,8,2,10, 12,4,14,6, 3,11,1,9, 15,7,13,5]` 按 `ivec2(mod(cell, 4.0))` 取值并居中归一化为 `threshold = (bayerVal + 0.5) / 16.0`。 - 将 `v` 映射到 3 个相邻色段:`scaled = clamp(v, 0.0, 1.0) * 3.0`,取下界索引 `i0 = int(floor(scaled))`、上界 `i1 = min(i0 + 1, 3)` 与局部小数 `frac = fract(scaled)`。 - 单次阈值比较 `chosen = (frac > threshold) ? i1 : i0`,直接查表输出 4 个精确 sRGB 颜色之一(`#0C0C0D`、`#3D2AFE`、`#FD5920`、`#F2EEE5`)。 ### 推荐技术栈 - **极简最优栈**:Vanilla **WebGL2** + **TypeScript** + **Vite**(仅绘制一个全屏大三角形 `gl.drawArrays(gl.TRIANGLES, 0, 3)`,零第三方依赖,打包体积极小,GPU 单帧耗时 < 2–4ms 稳跑 60fps)。 - **框架集成备选**:React / Next.js 封装轻量 WebGL2 `<canvas>` Hook,或使用 **OGL / Three.js** 的 `RawShaderMaterial`(注意关闭 ToneMapping 与多余后处理)。 - **性能与体验细节**:限制 `devicePixelRatio <= 2`,利用 `ResizeObserver` 更新 `uResolution` 与 `uCellSize`,监听 `visibilitychange` 后台暂停渲染,支持 `prefers-reduced-motion: reduce` 降速。

工程实现要点与避坑指南

  • 必须采用「一维调色板索引抖动(Indexed 1D Ramp Dithering)」而非 RGB 三通道独立抖动:如果先算出连续彩图再对 R/G/B 分别做 Bayer 量化,蓝(#3D2AFE)与橙(#FD5920)交界处会炸出大量青色、绿色与黄色杂点;正确做法是先算标量场 v∈[0,1],仅在相邻两个色阶(黑↔蓝、蓝↔橙、橙↔白)之间以 Bayer 阈值二选一输出,才能得到干净纯粹的光学紫与柔桃过渡带。
  • Bayer 阈值必须做半步居中偏移 `(bayer + 0.5) / 16.0`:若直接用 `bayer / 16.0`,标量场到达极值 0.0 或 1.0 附近时仍会在纯黑/纯白平坦区域偶发孤立噪点,居中偏移可保证极值区间彻底干净且过渡带占比对称。
  • 严格按 DPR 归一化逻辑网格并关闭抗锯齿(`antialias: false`):视频在 1536×864 下对应约 640×360 的离散单元(约 2.4px/格);若在 Retina 屏上直接按物理 1px 做 Bayer 矩阵,点阵会过细引发高频摩尔纹并丧失版画颗粒感;而若启用了双线性插值或非整数 CSS 缩放,方块点阵又会糊成灰紫色泥浆。务必在片元着色器内用 `floor(gl_FragCoord.xy / uCellSize)` 锁死整格采样。
  • 使用 4D 循环时间圆轨迹实现真正无缝的 10 秒循环:切忌用 `sin(t)` 驱动时间来回往复(会产生明显的“折返停顿感”)。应将归一化时间相位 θ=2π·fract(t/10.0) 映射到 4D Simplex Noise 的 zw 平面圆周 `(cos θ, sin θ) * R`,让涡流在视觉上持续单向漂移演进,同时在第 10 秒末完美首尾衔接回第 0 秒。
  • 禁止二次 Gamma / ToneMapping 色彩失真:若用 Three.js 等框架承载该片元着色器,务必关闭 ACESFilmicToneMapping 并注意 sRGB 输出空间转换,否则饱和电光蓝 `#3D2AFE` 和烈焰橙 `#FD5920` 会发灰发粉、失去强烈的荧光热成像与 Risograph 油墨张力。
  • 标量场分布需要做动态对比度整形(smoothstep 压缩 + 偏置):原始多层 FBM 噪声往往高度集中在 0.45~0.55 中位区间,若直接映射会导致整屏只剩蓝橙而几乎没有黑洞和炽白高光;通过拉伸对比度使黑/蓝/橙/白四个色阶分别保持约 5–20%、25–53%、20–47%、4–24% 的动态呼吸占比,才能复现本作品强戏剧张力。

更多原创作品

更多3D 与交互工艺 →