shader-glsl
This skill should be used when the user asks to "write a fragment shader", "make a GLSL gradient/noise/plasma background", "create an image transition (dissolve, displacement, glitch)", "add distortion or chromatic aberration", "build an SDF shape shader", "wire up a Three.js ShaderMaterial with uniforms", or "do GPU post-processing". Covers GLSL fragment shaders, noise/fbm, SDFs, domain warping, transitions, and Three.js integration.
1How It Works & Mechanism
The foundation is the GPU parallel model of "evaluating a color per pixel": establish this premise first, then write all effects as fragment shaders (pure functions of uniforms).
Write GPU fragment shaders for generative motion, gradients, transitions, and post-processing. Fragment shaders run once per pixel in parallel — the most performant way to do full-screen generative motion.
Fix the skeleton as "normalized coordinates → aspect ratio correction → color", and provide the IQ cosine palette as the shortest path (a + b*cos(2π(c*t+d))).
The cosine-palette line above (Inigo Quilez palettes) is the fastest route to a good-looking animated gradient: `a + b*cos(2π*(c*t + d))` with tunable `a,b,c,d` vec3s.
Four basic building blocks make up the entire recipe: smoothstep+mix (paired with fwidth for 1-pixel-wide antialiased edges), textureless hash/value noise and fbm, SDF shapes, and domain warping (feeding noise into noise).
**smoothstep + mix** are the workhorses. `smoothstep(e0, e1, x)` gives a smooth 0→1 ramp; `mix(a, b, t)` linearly blends. Antialias an edge by the width of one pixel:
Unify image transitions into a "two textures + one u_progress" model: noise threshold dissolve, UV pushing via displacement map, and glitch (scanline hash displacement + RGB channel split).
Sample two textures and blend per pixel by a progress uniform `u_progress` (0→1).
Provide a runnable, complete Three.js wiring skeleton (uniforms + ShaderMaterial + 2×2 plane covering clip space + projectionless camera), distinguishing between "fullscreen pass directly outputting position" and "actual geometry requiring vUv".
For a full-screen pass with a plain camera, write the vertex shader to output `position` directly and skip projection (as above). For shaders applied to real geometry, pass `vUv` from the vertex shader via `varying vec2 vUv;
Mobile and performance rules are hard constraints of GLSL ES rather than stylistic recommendations: loops must have constant upper bounds, octaves ≤5–6, avoid branching in hot paths, minimize texture2D and dependent texture reads, choose highp/mediump as needed, and outline ES 3.00 migration points.
Loops must have **constant bounds** in GLSL ES — no dynamic loop counts. Keep fbm octaves ≤ 5–6.
Determinism stems from "shaders are pure functions of uniforms": all animations are driven solely via u_time (plus u_progress for transitions), and shader randomness inherently originates from deterministic hash(uv) without needing per-frame seeding.
The shader is a pure function of uniforms — drive everything from `u_time` (and `u_progress` for transitions). All animation flows through one uniform you can pin.
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | npx playwright screenshot(验证回路:截 file:// 页面在 ?t=2.0 的冻结帧) |
| cli | 仓库根共享脚本 scripts/seek-shot.sh、scripts/contact-sheet.sh(截图与接触表拼图;不在 skill 目录内) |
| cli | ffmpeg / ffprobe(contact-sheet.sh 与 probe-mp4.sh) |
| network | 交付 HTML 经 importmap 从 CDN 取 three(产物期,浏览器端拉取) |
4Recommended Governance & Evidence
- scripts/: Local script or command execution: (SKILL.md instruction) npx playwright screenshot --wait-for-timeout=600 "file://$PWD/
- 网络端点: External network access declaration: The skill directory contains no network-calling code; runtime network surface only stems from fetching tools via `npx playwright` (npm registry + Chromium binary download)
- 本地工作目录: File I/O and artifact output: Core deliverable: single shader.html (created by agent per output contract)
5Second-Pass Verification
- [ok] 「skill 目录内无脚本」是否成立(蓝档的关键前提) — 文件清单实证:skills/shader-glsl/ 下只有 SKILL.md、README.md(0 B)、references/glsl-cookbook.md。SKILL.md 引用的 `scripts/seek-shot.sh` 属仓库根资产,已在 reason/risks 记录为「单装 skill 目录会悬空」。
- [ok] 凭证/环境变量读取是否存在 — 本仓(webgl-animation-skills)全仓 `process.env|API_KEY|TOKEN|SECRET|Authorization` 零命中;本 skill 的 credential_reads 为空成立。
- [ok] 是否有更高的触发条件被漏掉(红档特征) — `sandbox|automationcontrolled|no-verify|stealth|bypass|ignoreHTTPSErrors|dangerously` 全仓零命中;无任意代码执行面(交付物是浏览器沙箱内的 GLSL/JS)。
- [ok] 「shader 是 uniform 的纯函数 → ?t=N 可复现」是否与 harness 代码相符 — harness 段在 `?t=N` 分支直接 `frame(parseFloat(t))`(同时把 u_progress 钉到 N),非冻结分支才用 clock + setAnimationLoop;与「只有一个时钟来源」的声明一致,无夸大。
- [ok] GLSL ES 限制类声明是否确实写在文档内(非推测) — 原文 'Loops must have **constant bounds** in GLSL ES — no dynamic loop counts. Keep fbm octaves ≤ 5–6.';移动端精度段(mediump/highp、pixelRatio 上限、低分辨率 RT 上采样)亦可逐条定位。
- [ok] reference 内容与 SKILL.md 描述是否一致 — glsl-cookbook.md 开篇 'Complete, copy-pasteable GLSL for noise, SDFs, palettes, domain warping, transitions, and Three.js wiring.',随后逐节给出 IQ 调色板、hash21/hash22/valueNoise、SDF 与 domain warping 实现,与 SKILL.md 末尾能力清单对得上。
6Verdict & Scenarios
b6013fd669696c7f…