ShaderToy
Use this skill for ShaderToy-native work and ShaderToy-to-runtime migration.
This skill is narrower than shader. If the problem is fundamentally about ShaderToy built-ins, mainImage, channels, buffers, or porting out of ShaderToy, use this one first.
Workflow
1. Confirm the ShaderToy shape
Resolve these first:
- - single
Image pass or multi-pass with INLINECODE3 - uses of
iTime, iResolution, INLINECODE6 - channel usage: INLINECODE7
- whether the code is pure procedural or samples textures / buffers
If the user posts ShaderToy code, keep the original structure visible until the effect works.
2. Debug in ShaderToy terms first
Before porting, reduce the effect inside ShaderToy conventions:
- - replace output with a constant color
- visualize INLINECODE8
- bypass texture reads and channels temporarily
- isolate one term at a time
Read references/builtins.md for the built-in variable map.
3. Port only after the effect is understood
When porting away from ShaderToy:
- - convert
mainImage(out vec4 fragColor, in vec2 fragCoord) to the host entry point - replace built-ins with explicit uniforms
- recreate full-screen quad or postprocess host setup
- account for channel textures and buffer passes explicitly
Read references/porting.md before rewriting host-side glue.
4. Keep answers concrete
Prefer:
- - a corrected ShaderToy fragment shader
- a mapping of built-ins to host uniforms
- a minimal migration plan
- the first likely failure point
Commands
Inspect built-ins and channels
CODEBLOCK0
Generate a porting checklist
CODEBLOCK1
Use this when converting ShaderToy code into another runtime.
Print a debug checklist
CODEBLOCK2
Generate an intake plan
CODEBLOCK3
Pick the right demo starting point
CODEBLOCK4
Generate a scaffold recommendation
CODEBLOCK5
Use this when the user wants the fastest route from a ShaderToy idea to a runnable host setup.
Assets
Bundled templates:
- - INLINECODE12
- INLINECODE13
References
- - Built-ins, channels, and pass semantics: INLINECODE14
- Migration rules to WebGL / Three.js / R3F: INLINECODE15
- Buffer and feedback triage: INLINECODE16
Guardrails
- - Keep ShaderToy naming intact until the effect is understood.
- Do not invent channels or buffer passes the user did not specify.
- If the shader relies on buffers or feedback, say so explicitly before pretending it is a single-pass effect.
- When porting, make every implicit ShaderToy input explicit in the host code.
ShaderToy
使用此技能处理ShaderToy原生工作以及从ShaderToy迁移到运行时环境。
此技能比shader更具体。如果问题本质上涉及ShaderToy内置函数、mainImage、通道、缓冲区或从ShaderToy移植,请优先使用此技能。
工作流程
1. 确认ShaderToy结构
首先解决以下问题:
- - 单次Image渲染还是使用Buffer A/B/C/D的多通道渲染
- 是否使用iTime、iResolution、iMouse
- 通道使用情况:iChannel0..3
- 代码是纯程序化生成还是采样纹理/缓冲区
如果用户发布了ShaderToy代码,在效果正常工作前保持原始结构可见。
2. 先在ShaderToy层面调试
在移植之前,先在ShaderToy约定范围内简化效果:
- - 用常量颜色替换输出
- 可视化fragCoord / iResolution.xy
- 临时绕过纹理读取和通道
- 一次隔离一个变量
阅读references/builtins.md了解内置变量映射。
3. 理解效果后再移植
当从ShaderToy移植时:
- - 将mainImage(out vec4 fragColor, in vec2 fragCoord)转换为主机入口点
- 用显式uniform替换内置变量
- 重建全屏四边形或后处理主机设置
- 明确处理通道纹理和缓冲区渲染
在重写主机端胶水代码前阅读references/porting.md。
4. 保持答案具体
优先提供:
- - 修正后的ShaderToy片段着色器
- 内置变量到主机uniform的映射
- 最小化迁移方案
- 最可能的失败点
命令
检查内置变量和通道
bash
node {baseDir}/scripts/shadertoy.js builtins
node {baseDir}/scripts/shadertoy.js channels --json
生成移植检查清单
bash
node {baseDir}/scripts/shadertoy.js port three
node {baseDir}/scripts/shadertoy.js port webgl --json
在将ShaderToy代码转换到其他运行时环境时使用此命令。
打印调试检查清单
bash
node {baseDir}/scripts/shadertoy.js debug black-screen
node {baseDir}/scripts/shadertoy.js debug channels
生成导入方案
bash
node {baseDir}/scripts/shadertoy.js intake port a shadertoy ocean to r3f
node {baseDir}/scripts/shadertoy.js intake fix my iChannel feedback effect --json
选择正确的演示起点
bash
node {baseDir}/scripts/shadertoy.js demo single-pass
node {baseDir}/scripts/shadertoy.js demo feedback --json
生成脚手架推荐
bash
node {baseDir}/scripts/shadertoy.js scaffold three single-pass
node {baseDir}/scripts/shadertoy.js scaffold webgl feedback --json
当用户希望从ShaderToy创意到可运行主机设置的最快路径时使用此命令。
资源
捆绑模板:
- - assets/shadertoy-single-pass-demo/index.html
- assets/shadertoy-feedback-notes.txt
参考资料
- - 内置变量、通道和渲染语义:references/builtins.md
- 迁移到WebGL / Three.js / R3F的规则:references/porting.md
- 缓冲区和反馈分类:references/buffers-feedback.md
防护措施
- - 在理解效果前保持ShaderToy命名不变。
- 不要发明用户未指定的通道或缓冲区渲染。
- 如果着色器依赖缓冲区或反馈,在将其视为单次渲染效果前明确说明。
- 移植时,在主机代码中将每个隐式的ShaderToy输入显式化。