webgpu-threejs-tsl
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.
install
source · Clone the upstream repo
git clone https://github.com/dgreenheck/webgpu-claude-skill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/dgreenheck/webgpu-claude-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/webgpu-threejs-tsl" ~/.claude/skills/dgreenheck-webgpu-claude-skill-webgpu-threejs-tsl && rm -rf "$T"
manifest:
skills/webgpu-threejs-tsl/SKILL.mdsource content
WebGPU Three.js with TSL
TSL (Three.js Shading Language) is a node-based shader abstraction that lets you write GPU shaders in JavaScript instead of GLSL/WGSL strings.
Quick Start
import * as THREE from 'three/webgpu'; import { color, time, oscSine } from 'three/tsl'; const renderer = new THREE.WebGPURenderer(); await renderer.init(); const material = new THREE.MeshStandardNodeMaterial(); material.colorNode = color(0xff0000).mul(oscSine(time));
Skill Contents
Documentation
- Types, operators, uniforms, control flowdocs/core-concepts.md
- Node materials and all propertiesdocs/materials.md
- GPU compute with instanced arraysdocs/compute-shaders.md
- Built-in and custom effectsdocs/post-processing.md
- Custom WGSL functionsdocs/wgsl-integration.md
- Handling GPU device loss and recoverydocs/device-loss.md
- WebGPU device limits and optional featuresdocs/limits-and-features.md
Examples
- Minimal WebGPU projectexamples/basic-setup.js
- Custom shader materialexamples/custom-material.js
- GPU compute particlesexamples/particle-system.js
- Effect pipelineexamples/post-processing.js
- Complete Earth with atmosphereexamples/earth-shader.js
Templates
- Starter project templatetemplates/webgpu-project.js
- Compute shader templatetemplates/compute-shader.js
Reference
- Quick reference cheatsheetREFERENCE.md
Key Concepts
Import Pattern
// Always use the WebGPU entry point import * as THREE from 'three/webgpu'; import { /* TSL functions */ } from 'three/tsl';
Node Materials
Replace standard material properties with TSL nodes:
material.colorNode = texture(map); // instead of material.map material.roughnessNode = float(0.5); // instead of material.roughness material.positionNode = displaced; // vertex displacement
Method Chaining
TSL uses method chaining for operations:
// Instead of: sin(time * 2.0 + offset) * 0.5 + 0.5 time.mul(2.0).add(offset).sin().mul(0.5).add(0.5)
Custom Functions
Use
Fn() for reusable shader logic:
const fresnel = Fn(([power = 2.0]) => { const nDotV = normalWorld.dot(viewDir).saturate(); return float(1.0).sub(nDotV).pow(power); });
When to Use This Skill
- Setting up Three.js with WebGPU renderer
- Creating custom shader materials with TSL
- Writing GPU compute shaders
- Building post-processing pipelines
- Migrating from GLSL to TSL
- Implementing visual effects (particles, water, terrain, etc.)
Resources
- Three.js TSL Wiki
- WebGPU Examples (files prefixed with
)webgpu_