Index of every page on this site: llms.txt
All skills
Run it yourself

Use when using the Three.js WebGPU renderer, node-based materials, TSL (Three Shading Language), or compute shaders. Prevents the common mistake of not checking browser support, missing async init, or using GLSL with WebGPU. Covers WebGPURenderer, node materials, TSL, compute shaders, WebGL fallback, migration guide. Keywords: WebGPU, WebGPURenderer, TSL, Three Shading Language, node material, compute shader, WGSL, MeshStandardNodeMaterial, next-gen rendering, modern GPU, WebGPU setup.

Use this Skill: https://skilld.dev/gh/impertio-studio/three.js-claude-skill-package/threejs-impl-webgpu

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesanti-patterns.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Anti-Patterns (Three.js WebGPU)

1. Rendering Before Async Init

// WRONG: render() called before init() resolves — throws runtime error
const renderer = new THREE.WebGPURenderer({ antialias: true });
renderer.render(scene, camera); // ERROR: renderer not initialized

// CORRECT: ALWAYS await init() before any render call
const renderer = new THREE.WebGPURenderer({ antialias: true });
await renderer.init();
renderer.render(scene, camera);

WHY: WebGPURenderer requires asynchronous GPU adapter and device initialization. Calling render() before init() completes causes a runtime error because the GPU device handle does not exist yet.


2. No Browser Support Check

// WRONG: Assumes WebGPU is available everywhere
const renderer = new THREE.WebGPURenderer({ antialias: true });
await renderer.init();

// CORRECT: ALWAYS check availability and provide fallback
import { WebGPU } from 'three/webgpu';

let renderer;
if (WebGPU.isAvailable()) {
  renderer = new THREE.WebGPURenderer({ antialias: true });
  await renderer.init();
} else {
  renderer = new THREE.WebGLRenderer({ antialias: true });
}

WHY: WebGPU is NOT available in Firefox (without a flag), older browsers, or many mobile browsers. Without a fallback, the application crashes for a large portion of users.


3. Writing Raw GLSL with WebGPU

// WRONG: GLSL strings are NOT supported by WebGPU backend
const material = new THREE.ShaderMaterial({
  vertexShader: `void main() { gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }`,
  fragmentShader: `void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }`,
});

// CORRECT: Use TSL with NodeMaterial
import { MeshBasicNodeMaterial } from 'three/webgpu';
import { vec4, float } from 'three/tsl';

const material = new MeshBasicNodeMaterial();
material.colorNode = vec4(float(1.0), float(0.0), float(0.0), float(1.0));

WHY: WebGPU uses WGSL, not GLSL. Three.js compiles TSL to WGSL automatically. ShaderMaterial with GLSL strings only works with WebGLRenderer. ALWAYS use TSL for cross-backend compatibility.


4. Using requestAnimationFrame

// WRONG: requestAnimationFrame does not integrate with WebGPU frame timing
function animate() {
  requestAnimationFrame(animate);
  renderer.render(scene, camera);
}
animate();

// CORRECT: ALWAYS use setAnimationLoop for WebGPU
renderer.setAnimationLoop((time) => {
  renderer.render(scene, camera);
});

WHY: renderer.setAnimationLoop() handles WebGPU frame scheduling, XR session loops, and renderer lifecycle correctly. Using requestAnimationFrame bypasses these mechanisms and can cause timing issues or missed frames with WebGPU.


5. Using EffectComposer with WebGPU

// WRONG: EffectComposer is WebGL-only
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass.js';

const composer = new EffectComposer(renderer); // FAILS with WebGPURenderer

// CORRECT: Use PostProcessing class with TSL nodes
import { PostProcessing } from 'three/webgpu';
import { pass, bloom, renderOutput } from 'three/tsl';

const postProcessing = new PostProcessing(renderer);
const scenePass = pass(scene, camera);
postProcessing.outputNode = renderOutput(bloom(scenePass));

WHY: The EffectComposer and its passes use WebGL-specific render targets and GLSL shaders. They are fundamentally incompatible with WebGPURenderer. The PostProcessing class uses TSL nodes that compile to WGSL.


6. Importing from Wrong Module Path

// WRONG: Standard three import does not include WebGPU classes
import * as THREE from 'three';
const renderer = new THREE.WebGPURenderer(); // undefined

// CORRECT: ALWAYS import from 'three/webgpu' for WebGPU classes
import * as THREE from 'three/webgpu';
const renderer = new THREE.WebGPURenderer({ antialias: true });

WHY: WebGPURenderer, node materials, and WebGPU utilities are only exported from 'three/webgpu'. The standard 'three' entry point does not include them.


7. Using Lowercase if in TSL

// WRONG: JavaScript if does not generate shader conditionals
if (someNode.greaterThan(float(0.5))) {
  material.colorNode = color(0xff0000);
}

// CORRECT: ALWAYS use TSL's capital If for shader-level conditionals
import { If, float, color } from 'three/tsl';

If(someNode.greaterThan(float(0.5)), () => {
  material.colorNode = color(0xff0000);
}).Else(() => {
  material.colorNode = color(0x0000ff);
});

WHY: JavaScript if evaluates at material creation time, not per-fragment. TSL If() generates actual GPU conditional instructions that execute per-fragment on the GPU. Using JavaScript if produces a static material instead of a dynamic one.


8. Synchronous Compute Dispatch

// WRONG: computeAsync returns a Promise — ignoring it causes race conditions
renderer.computeAsync(computeNode); // fire-and-forget
renderer.render(scene, camera);     // may render before compute finishes

// CORRECT: ALWAYS await compute before rendering dependent results
await renderer.computeAsync(computeNode);
renderer.render(scene, camera);

WHY: GPU compute operations are asynchronous. Rendering before the compute pass finishes can display stale or incomplete data. ALWAYS await computeAsync() when the render depends on compute results.


9. Forgetting to Make Entry Point Async

// WRONG: Cannot use await at top level in non-module scripts
const renderer = new THREE.WebGPURenderer();
renderer.init(); // Promise ignored, init never completes

// CORRECT: Use async entry point
async function init() {
  const renderer = new THREE.WebGPURenderer({ antialias: true });
  await renderer.init();
  // ... rest of setup
}
init();

WHY: WebGPURenderer.init() is a Promise. Without await, the renderer is used before GPU initialization completes. ALWAYS wrap WebGPU setup in an async function or use top-level await in ES modules.


10. Mixing Classic and Node Material APIs Incorrectly

// WRONG: Setting classic property after assigning node — node takes precedence
const material = new MeshStandardNodeMaterial();
material.colorNode = color(0xff0000);
material.color.set(0x00ff00); // has NO effect — colorNode overrides

// CORRECT: Use EITHER classic props OR node props, not both
// Option A: Classic props only (auto-converts for WebGPU)
const material = new MeshStandardNodeMaterial({ color: 0x00ff00 });

// Option B: Node props only (full TSL control)
const material = new MeshStandardNodeMaterial();
material.colorNode = color(0x00ff00);

WHY: When a node property (e.g., colorNode) is set, it completely overrides the corresponding classic property (e.g., color). Setting both creates confusion and the classic value is silently ignored. Choose one approach and use it consistently.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5mo3 checks · Risk SAFE
  • Gen Agent Trust Hub5mo

    This skill provides comprehensive documentation and best practices for using the Three.js WebGPU renderer and Three Shading Language (TSL). It is entirely educational and contains no malicious instructions or code.

  • Socket5mo

    No alerts

  • Snyk5mo

    Risk: LOW · No issues

Signed by skilld at 6c190f0. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 8 months ago
metadata
{
  "author": "OpenAEC-Foundation",
  "version": "1.0"
}
Other metadata
compatibility
Designed for Claude Code. Requires Three.js r160+. WebGPU: Chrome 113+, Safari 18+.

README badge

README badge for impertio-studio/three.js-claude-skill-package/threejs-impl-webgpu