webgpu-three-js
Comprehensive guide for developing WebGPU-enabled Three.js applications using TSL (Three.js Shading Language). Covers WebGPU renderer setup, TSL syntax and node materials, compute shaders, post-processing effects, and WGSL integration. Use this skill when working with Three.js WebGPU, TSL shaders, node materials, or GPU compute in Three.js.
1How It Works & Mechanism
SKILL.md itself is only 93 lines / 3.2KB and functions as a routing table: its body uses 'Skill Contents' to itemize 7 docs, 5 examples, 2 templates, and 1 cheatsheet. The agent progressively discloses and loads the corresponding files based on the active task, rather than flooding the context window with 50KB+ of documentation all at once.
- `docs/compute-shaders.md` - GPU compute with instanced arrays
On the Cursor side, the same disclosure strategy is formulated as explicit prompts: the .mdc body keeps only a 3–5 line summary and uses @file references pointing to the original documentation under skills/ (the 5 .mdc files total just 5.9KB, yet include 10 @ references).
The source-of-truth documentation lives under `skills/webgpu-threejs-tsl/`. Reference these files directly when deeper guidance is needed:
The true anchor for 'writing correct code' is a recurring semantic pitfall in TSL emphasized throughout the docs: TSL can only intercept node property assignments, not JS variable reassignments. Writing value = value.add(1.0) inside If() fails silently (returning the old node without throwing errors).
**TSL can intercept property assignments on nodes, but NOT JavaScript variable reassignment.**
It provides not just the rule, but also the failure mechanism to prevent models from repeating the same mistake with different phrasing: the documentation explains that JS variable reassignment creates a new node that TSL cannot observe, and scalars lack .x/.y properties, preventing property assignment workarounds.
**Why it fails:** `value = value.add(1.0)` creates a new TSL node and reassigns the JavaScript variable to point to it.
Breaking version changes are codified as documentation entries rather than runtime detection: the skill does not inspect the user project's Three.js version, but instead compiles r17x–r18x breaking changes into comparative reference entries for the model to cross-check autonomously.
> **Note:** `PostProcessing` was renamed to `RenderPipeline` in r183. `PostProcessing` still works as a compatibility wrapper but is deprecated.
Templates provide directly deployable, full-file scaffolding rather than pseudo-code: segmented structures (CONFIG/GLOBALS/INITIALIZATION/SCENE/ANIMATION/EVENT), designated insertion points, and internal objects exported at the end for external debugging.
// Export for external access if needed
WGSL escape hatch: When TSL cannot express a concept or existing WGSL needs porting, wgslFn() embeds entire WGSL function bodies into the TSL node graph; the documentation also includes quick references for WGSL types, syntax, and built-in functions so the model can write correct WGSL independently of TSL.
TSL allows embedding raw WGSL (WebGPU Shading Language) code when you need direct GPU control.
Incorporates WebGPU-specific runtime failure surfaces (device loss, limits/features) into coding guidance, ensuring generated code is not only runnable, but also resilient against GPU crashes and buffer limits.
Three.js accepts `requiredLimits` as a renderer constructor option, which gets passed through to `requestDevice()`:
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| package | three(npm 包,生成项目需自装) |
| package | three/addons 子路径(OrbitControls、BloomNode 等 addons 模块) |
| network | 文档引用链接(仅 markdown 里的参考资料链接,仓库内无任何抓取/请求代码,不被 skill 调用) |
4Recommended Governance & Evidence
- SKILL.md: Pure prompt instructions and rule text without script execution or external impact.
5Second-Pass Verification
- [ok] pin commit 与工作副本一致 — git rev-parse HEAD 输出 af2319bd01bb7cc881267a9ef42cafdaf5e9029d,与 .git/shallow 首行相同,等于任务 pin commit;结论只对该 commit 有效。
- [ok] skill 目录定位 — skills/webgpu-threejs-tsl/SKILL.md 存在且 frontmatter name: webgpu-threejs-tsl 与 slug 对应;同目录含 REFERENCE.md、docs/×7、examples/×5、templates/×2,路径写入 skill.path。
- [discrepancy] license 声明与仓库实际文件 — README.md 有『## License』段声明 MIT License,.claude-plugin/plugin.json 也写 "license": "MIT";但 git ls-tree -r 全量清单里没有 LICENSE / LICENSE.md 文件,全仓 grep -il license 只命中 plugin.json、README.md 与 5 个 examples 的注释,与 GitHub API license=null 一致。即:许可为『源码内声明』而非仓内标准许可文件。
- [discrepancy] README 自述的 skill 结构图 vs 实际文件 — README『## Skill Structure』的 docs/ 分支只列 core-concepts / materials / compute-shaders / post-processing / wgsl-integration / device-loss 六篇(以 `└── device-loss.md` 收尾),而 docs/ 实有 7 篇——漏列 limits-and-features.md;SKILL.md 的 Skill Contents 则完整列出七篇。属 README 文档漂移。
- [discrepancy] Cursor 摘要与 docs 的 API 世代是否一致(后处理) — .cursor/rules/post-processing.mdc 仍教 `import { PostProcessing } from 'three/webgpu';` 并说 postProcessing.renderAsync(),而 docs/post-processing.md 开篇即注明 r183 已改名 RenderPipeline、旧名仅为兼容包装,examples/post-processing.js 实际用的是 `new THREE.RenderPipeline(renderer)`。README 自称 shim 会『edits flow through automatically』——该说法对手写摘要句不成立。
- [discrepancy] Cursor 摘要与 docs 的 API 世代是否一致(compute 派发) — .cursor/rules/compute-shaders.mdc 写『dispatched via `renderer.computeAsync()`』与『- `renderer.computeAsync(kernel)` to dispatch』,而 docs/compute-shaders.md『Execution Methods』明确『// Note: computeAsync() is deprecated since r181.』并给出『await renderer.init() at startup, then renderer.compute() synchronously』;templates/compute-shader.js 与 examples/particle-system.js 用的都是 renderer.compute(...)。同一漂移问题的第二例。
- [ok] 外部依赖反查:是否存在 CDN/网络调用 — 全仓 grep -riE 'unpkg|jsdelivr|cdn\.|importmap|import-map' 零命中;templates/examples 的 import 全部是裸包名(three、three/webgpu、three/tsl、three/addons/...),无 URL 形式的模块来源。故 external_deps 只列 npm 包,security.network_calls 为空。
- [ok] 脚本/凭证面反查 — git ls-tree 全清单只有 .md/.mdc/.json/.js;无 package.json(因此无 npm scripts、无依赖安装钩子)、无 scripts/、无 .sh/.py;危险 token 扫描对 child_process/eval/new Function/process.env/.env/token/secret/document.cookie/credentials 均无命中。scripts_executed 与 credential_reads 为空有据。
6Verdict & Scenarios
afb594cdc14fec2b…