Shader
Use this skill to turn shader requests into runnable code and fast debugging steps.
Default target: browser-friendly GLSL. If the runtime is unclear, narrow it before writing code:
- - ShaderToy fragment-only
- raw WebGL / GLSL ES
- Three.js INLINECODE0
- React Three Fiber
- postprocess-style full-screen pass
Workflow
1. Lock the runtime and effect shape
Resolve these first:
- - runtime
- fragment-only vs vertex + fragment
- screen effect vs material effect vs postprocess pass
- required inputs:
uTime, uResolution, UVs, normals, textures, mouse
If the request is vague, start with the smallest visible version of the effect.
2. Build from a visible baseline
- - Start with a constant color or UV gradient.
- Add one moving term at a time.
- Reintroduce uniforms, varyings, noise, lighting, and distortion step by step.
For blank output, compile failures, or “nothing shows”, read references/black-screen-checklist.md.
3. Match the host, not the idea source
Do not hand over ShaderToy code unchanged if the user asked for Three.js or R3F.
Common translations:
- -
iTime -> INLINECODE5 - INLINECODE6 -> INLINECODE7
- INLINECODE8 -> INLINECODE9
- ShaderToy fullscreen logic -> quad / plane / postprocess host setup
For live previews inside OpenClaw, pair this skill with canvas.
4. Keep answers practical
Prefer responses that include:
- - runnable shader code
- required uniforms and defaults
- host-side glue code
- the first debugging step if it fails
Common Uses
- - Full-screen effects: flowing gradients, ripples, ShaderToy-style animated backgrounds
- Material effects: fresnel, dissolve, edge glow, scanlines, vertex wobble
- Porting: ShaderToy -> WebGL / Three.js / R3F
- Debugging: black screen, all-white / all-black output, broken UVs, wrong varyings, missing uniforms
Commands
Intake
CODEBLOCK0
Use this to structure an underspecified request.
Debug
CODEBLOCK1
Effects
CODEBLOCK2
Maps user phrases to likely starter techniques like gradient, noise, fresnel, dissolve, ripple, scanline, and pixelate.
Boilerplate
CODEBLOCK3
Returns stage split, likely uniforms, varyings, build order, and common failure points.
Snippet
CODEBLOCK4
Points to the nearest bundled GLSL starter.
Demo
CODEBLOCK5
Chooses the best bundled runtime template for a target + effect combination.
Scaffold
CODEBLOCK6
Combines the nearest demo, boilerplate, snippet, and first integration steps.
Assets
Bundled templates:
- - INLINECODE18
- INLINECODE19
- INLINECODE20
- INLINECODE21
- INLINECODE22
- INLINECODE23
- INLINECODE24
- INLINECODE25
Bundled snippets:
- - INLINECODE26
- INLINECODE27
- INLINECODE28
- INLINECODE29
- INLINECODE30
- INLINECODE31
Use the postprocess template for screen-space effects. Use the Three.js or R3F templates for mesh/material effects.
References
- - INLINECODE32
- INLINECODE33
- INLINECODE34
- INLINECODE35
- INLINECODE36
Guardrails
- - Default to the smallest working shader that proves the effect.
- Use host-friendly uniform names like
uTime, uResolution, uMouse, uTexture. - Do not assume WebGL2 unless the host clearly uses it.
- Do not invent runtime-specific macros or built-ins.
- Call out likely precision, color-space, or postprocess-order bugs explicitly.
- For performance advice, stay directional unless the actual runtime and GPU are known.
着色器
使用此技能将着色器请求转化为可运行代码和快速调试步骤。
默认目标:浏览器友好的GLSL。如果运行时环境不明确,在编写代码前先进行限定:
- - ShaderToy纯片段着色器
- 原始WebGL / GLSL ES
- Three.js ShaderMaterial
- React Three Fiber
- 后处理风格的全屏通道
工作流程
1. 锁定运行时环境和效果形态
首先解决以下问题:
- - 运行时环境
- 纯片段着色器 vs 顶点+片段着色器
- 屏幕效果 vs 材质效果 vs 后处理通道
- 所需输入:uTime、uResolution、UV坐标、法线、纹理、鼠标
如果请求模糊不清,从效果的最小可见版本开始。
2. 从可见基线开始构建
- - 从纯色或UV渐变开始。
- 每次添加一个动态项。
- 逐步引入uniform变量、varying变量、噪声、光照和变形。
对于空白输出、编译失败或什么都不显示的情况,请阅读references/black-screen-checklist.md。
3. 匹配宿主环境,而非灵感来源
如果用户要求Three.js或R3F,不要直接照搬ShaderToy代码。
常见转换:
- - iTime -> uTime
- iResolution -> uResolution
- fragCoord -> gl_FragCoord.xy
- ShaderToy全屏逻辑 -> 四边形/平面/后处理宿主设置
如需在OpenClaw内进行实时预览,请将此技能与canvas配合使用。
4. 保持回答实用性
优先提供包含以下内容的回答:
- - 可运行的着色器代码
- 所需的uniform变量及其默认值
- 宿主端胶水代码
- 失败时的第一步调试步骤
常见用途
- - 全屏效果:流动渐变、波纹、ShaderToy风格的动态背景
- 材质效果:菲涅尔、溶解、边缘发光、扫描线、顶点抖动
- 移植:ShaderToy -> WebGL / Three.js / R3F
- 调试:黑屏、全白/全黑输出、UV坐标错误、varying变量错误、uniform变量缺失
命令
接收
bash
node {baseDir}/scripts/shader.js intake three.js中的全屏海洋背景
node {baseDir}/scripts/shader.js intake 将此shadertoy移植到r3f --json
用于结构化处理未明确指定的请求。
调试
bash
node {baseDir}/scripts/shader.js debug black-screen
node {baseDir}/scripts/shader.js debug uniform
node {baseDir}/scripts/shader.js debug varyings
效果
bash
node {baseDir}/scripts/shader.js effects
将用户描述映射到可能的起始技术,如gradient、noise、fresnel、dissolve、ripple、scanline和pixelate。
样板代码
bash
node {baseDir}/scripts/shader.js boilerplate fresnel
node {baseDir}/scripts/shader.js boilerplate dissolve --json
返回阶段拆分、可能的uniform变量、varying变量、构建顺序和常见失败点。
代码片段
bash
node {baseDir}/scripts/shader.js snippet fresnel
node {baseDir}/scripts/shader.js snippet ripple --json
指向最近的捆绑GLSL起始代码。
演示
bash
node {baseDir}/scripts/shader.js demo webgl ripple
node {baseDir}/scripts/shader.js demo r3f fresnel --json
为目标+效果组合选择最佳的捆绑运行时模板。
脚手架
bash
node {baseDir}/scripts/shader.js scaffold r3f dissolve
node {baseDir}/scripts/shader.js scaffold postprocess scanline --json
结合最近的演示、样板代码、代码片段和第一步集成步骤。
资源
捆绑模板:
- - assets/webgl-fullscreen-demo/index.html
- assets/threejs-material-demo/index.html
- assets/postprocess-demo/index.html
- assets/r3f-demo/App.jsx
- assets/r3f-demo/main.jsx
- assets/r3f-demo/index.html
- assets/r3f-demo/package.json
- assets/r3f-demo/vite.config.js
捆绑代码片段:
- - assets/snippets/fresnel.md
- assets/snippets/dissolve.md
- assets/snippets/ripple.md
- assets/snippets/scanline.md
- assets/snippets/pixelate.md
- assets/snippets/vertex-wobble.md
屏幕空间效果使用后处理模板。网格/材质效果使用Three.js或R3F模板。
参考资料
- - references/glsl-quick-reference.md
- references/black-screen-checklist.md
- references/effect-starters-zh.md
- references/snippets.md
- references/runtime-translation.md
安全护栏
- - 默认使用能证明效果的最小可工作着色器。
- 使用宿主友好的uniform变量名称,如uTime、uResolution、uMouse、uTexture。
- 除非宿主明确使用WebGL2,否则不要假设使用WebGL2。
- 不要发明运行时特定的宏或内置函数。
- 明确指出可能的精度、色彩空间或后处理顺序错误。
- 对于性能建议,除非已知实际运行时环境和GPU,否则保持方向性指导。